Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pacific: test/{librbd, rgw}: increase delay between and number of bind attempts #48024

Merged
merged 2 commits into from Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/test/librbd/migration/test_mock_HttpClient.cc
Expand Up @@ -8,6 +8,7 @@
#include "librbd/migration/HttpClient.h"
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include <unistd.h>
#include <boost/asio/ip/tcp.hpp>
#include <boost/beast/core.hpp>
#include <boost/beast/http.hpp>
Expand Down Expand Up @@ -83,10 +84,29 @@ class TestMockMigrationHttpClient : public TestMockFixture {
TestMockFixture::TearDown();
}

// if we have a racing where another thread manages to bind and listen the
// port picked by this acceptor, try again.
static constexpr int MAX_BIND_RETRIES = 60;

void create_acceptor(bool reuse) {
m_acceptor.emplace(*m_image_ctx->asio_engine,
for (int retries = 0;; retries++) {
try {
m_acceptor.emplace(*m_image_ctx->asio_engine,
boost::asio::ip::tcp::endpoint(
boost::asio::ip::tcp::v4(), m_server_port), reuse);
// yay!
break;
} catch (const boost::system::system_error& e) {
if (retries == MAX_BIND_RETRIES) {
throw;
}
if (e.code() != boost::system::errc::address_in_use) {
throw;
}
}
// backoff a little bit
sleep(1);
}
m_server_port = m_acceptor->local_endpoint().port();
}

Expand Down
38 changes: 34 additions & 4 deletions src/test/rgw/test_http_manager.cc
Expand Up @@ -15,20 +15,50 @@
#include "rgw/rgw_http_client.h"
#include "global/global_init.h"
#include "common/ceph_argparse.h"
#include <unistd.h>
#include <curl/curl.h>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/write.hpp>
#include <thread>
#include <gtest/gtest.h>

namespace {
using tcp = boost::asio::ip::tcp;

// if we have a racing where another thread manages to bind and listen the
// port picked by this acceptor, try again.
static constexpr int MAX_BIND_RETRIES = 60;

tcp::acceptor try_bind(boost::asio::io_context& ioctx) {
using tcp = boost::asio::ip::tcp;
tcp::endpoint endpoint(tcp::v4(), 0);
tcp::acceptor acceptor(ioctx);
acceptor.open(endpoint.protocol());
for (int retries = 0;; retries++) {
try {
acceptor.bind(endpoint);
// yay!
break;
} catch (const boost::system::system_error& e) {
if (retries == MAX_BIND_RETRIES) {
throw;
}
if (e.code() != boost::system::errc::address_in_use) {
throw;
}
}
// backoff a little bit
sleep(1);
}
return acceptor;
}
}

TEST(HTTPManager, ReadTruncated)
{
using tcp = boost::asio::ip::tcp;
tcp::endpoint endpoint(tcp::v4(), 0);
boost::asio::io_context ioctx;
tcp::acceptor acceptor(ioctx);
acceptor.open(endpoint.protocol());
acceptor.bind(endpoint);
auto acceptor = try_bind(ioctx);
acceptor.listen();

std::thread server{[&] {
Expand Down