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

test: Add testing of connect()-ion abort ability #2301

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions tests/unit/socket_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,37 @@ SEASTAR_TEST_CASE(socket_on_close_local_shutdown_test) {
when_all(std::move(client), std::move(server)).discard_result().get();
});
}

// The test makes sure it's possible to abort connect()-ing a socket before
// it succeeds or fails. The way to abort the in-flight connection is to call
// shutdown() on the socket. The connect()'s future<> must resolve shortly
// after that with exception.
//
// The test currently fails on io_uring backend -- calling shutdown() doesn't
// make connect() future<> to resolve, instead it resolves after kernel times
// out the socket, which's not what test expects (see scylladb/seastar#2303)
SEASTAR_TEST_CASE(socket_connect_abort_test) {
xemul marked this conversation as resolved.
Show resolved Hide resolved
return seastar::async([&] {
bool too_late = false;
auto sk = make_socket();
auto cf = sk.connect(ipv4_addr("192.0.2.1", 12345)).then([] (auto cs) {
fmt::print("Connected\n");
BOOST_REQUIRE(false);
}).handle_exception([&too_late] (auto ex) {
fmt::print("Cannot connect {}\n", ex);
BOOST_REQUIRE(!too_late);
});

auto abort = sleep(std::chrono::milliseconds(500)).then([&sk] {
fmt::print("Abort connect\n");
sk.shutdown();
});

auto check = sleep(std::chrono::seconds(2)).then([&too_late] {
fmt::print("Connection must have been aborted already\n");
too_late = true;
});

when_all(std::move(cf), std::move(check), std::move(abort)).get();
});
}