diff options
author | Tor Brede Vekterli <vekterli@yahooinc.com> | 2022-10-24 08:36:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-24 08:36:17 +0200 |
commit | 2dc4c6b58004d51af887c49760a98804803ab73f (patch) | |
tree | 77d2a5b7edb36f86739e9af10a4791de451942b0 | |
parent | 1579514b4a757e9038728dbbeecd27a8b812ce66 (diff) | |
parent | e031e618cce7d4ee3e71a39c1d9c2e9b2227fb62 (diff) |
Merge pull request #24537 from vespa-engine/toregge/create-local-spec-on-demand
Replace the global variable vespalib::test::local_spec with the function
5 files changed, 11 insertions, 9 deletions
diff --git a/vespalib/src/tests/net/crypto_socket/crypto_socket_test.cpp b/vespalib/src/tests/net/crypto_socket/crypto_socket_test.cpp index 439afb49041..37b773426a1 100644 --- a/vespalib/src/tests/net/crypto_socket/crypto_socket_test.cpp +++ b/vespalib/src/tests/net/crypto_socket/crypto_socket_test.cpp @@ -209,7 +209,7 @@ void verify_crypto_socket(SocketPair &sockets, CryptoEngine &engine, bool is_ser SmartBuffer read_buffer(4_Ki); CryptoSocket::UP my_socket = is_server ? engine.create_server_crypto_socket(std::move(my_handle)) - : engine.create_client_crypto_socket(std::move(my_handle), local_spec); + : engine.create_client_crypto_socket(std::move(my_handle), make_local_spec()); TEST_DO(verify_handshake(*my_socket)); drain(*my_socket, read_buffer); TEST_DO(verify_socket_io(*my_socket, read_buffer, is_server)); diff --git a/vespalib/src/tests/net/sync_crypto_socket/sync_crypto_socket_test.cpp b/vespalib/src/tests/net/sync_crypto_socket/sync_crypto_socket_test.cpp index 6f62df8d78f..d689ef2b348 100644 --- a/vespalib/src/tests/net/sync_crypto_socket/sync_crypto_socket_test.cpp +++ b/vespalib/src/tests/net/sync_crypto_socket/sync_crypto_socket_test.cpp @@ -101,7 +101,7 @@ void verify_crypto_socket(SocketPair &sockets, CryptoEngine &engine, bool is_ser my_handle.set_blocking(false); SyncCryptoSocket::UP my_socket = is_server ? SyncCryptoSocket::create_server(engine, std::move(my_handle)) - : SyncCryptoSocket::create_client(engine, std::move(my_handle), local_spec); + : SyncCryptoSocket::create_client(engine, std::move(my_handle), make_local_spec()); ASSERT_TRUE(my_socket); TEST_DO(verify_socket_io(*my_socket, is_server)); TEST_DO(verify_graceful_shutdown(*my_socket, is_server)); diff --git a/vespalib/src/tests/portal/portal_test.cpp b/vespalib/src/tests/portal/portal_test.cpp index 979b1284700..fb9b58fc248 100644 --- a/vespalib/src/tests/portal/portal_test.cpp +++ b/vespalib/src/tests/portal/portal_test.cpp @@ -22,7 +22,7 @@ using namespace vespalib::test; vespalib::string do_http(int port, CryptoEngine::SP crypto, const vespalib::string &method, const vespalib::string &uri, bool send_host = true) { auto socket = SocketSpec::from_port(port).client_address().connect(); ASSERT_TRUE(socket.valid()); - auto conn = SyncCryptoSocket::create_client(*crypto, std::move(socket), local_spec); + auto conn = SyncCryptoSocket::create_client(*crypto, std::move(socket), make_local_spec()); vespalib::string http_req = vespalib::make_string("%s %s HTTP/1.1\r\n" "My-Header: my value\r\n" "%s" @@ -262,18 +262,18 @@ TEST("require that connection errors do not block shutdown by leaking resources" auto bound = portal->bind("/test", handler); { // close before sending anything auto socket = SocketSpec::from_port(portal->listen_port()).client_address().connect(); - auto conn = SyncCryptoSocket::create_client(*crypto.engine, std::move(socket), local_spec); + auto conn = SyncCryptoSocket::create_client(*crypto.engine, std::move(socket), make_local_spec()); } { // send partial request then close connection auto socket = SocketSpec::from_port(portal->listen_port()).client_address().connect(); - auto conn = SyncCryptoSocket::create_client(*crypto.engine, std::move(socket), local_spec); + auto conn = SyncCryptoSocket::create_client(*crypto.engine, std::move(socket), make_local_spec()); vespalib::string req = "GET /test HTTP/1.1\r\n" "Host: local"; ASSERT_EQUAL(conn->write(req.data(), req.size()), ssize_t(req.size())); } { // send request then close without reading response auto socket = SocketSpec::from_port(portal->listen_port()).client_address().connect(); - auto conn = SyncCryptoSocket::create_client(*crypto.engine, std::move(socket), local_spec); + auto conn = SyncCryptoSocket::create_client(*crypto.engine, std::move(socket), make_local_spec()); vespalib::string req = "GET /test HTTP/1.1\r\n" "Host: localhost\r\n" "\r\n"; diff --git a/vespalib/src/vespa/vespalib/test/make_tls_options_for_testing.cpp b/vespalib/src/vespa/vespalib/test/make_tls_options_for_testing.cpp index 1210b1d7c87..b7046a74c6d 100644 --- a/vespalib/src/vespa/vespalib/test/make_tls_options_for_testing.cpp +++ b/vespalib/src/vespa/vespalib/test/make_tls_options_for_testing.cpp @@ -79,7 +79,9 @@ const TransientCryptoCredentials& TransientCryptoCredentials::instance() { namespace vespalib::test { -SocketSpec local_spec("tcp/localhost:123"); +SocketSpec make_local_spec() { + return SocketSpec("tcp/localhost:123"); +} vespalib::net::tls::TransportSecurityOptions make_tls_options_for_testing() { return TransientCryptoCredentials::instance().cached_transport_options; diff --git a/vespalib/src/vespa/vespalib/test/make_tls_options_for_testing.h b/vespalib/src/vespa/vespalib/test/make_tls_options_for_testing.h index 5a07f796991..0bc39deaeaf 100644 --- a/vespalib/src/vespa/vespalib/test/make_tls_options_for_testing.h +++ b/vespalib/src/vespa/vespalib/test/make_tls_options_for_testing.h @@ -8,11 +8,11 @@ namespace vespalib::test { /** - * A socket spec representing "tcp/localhost:123". Used by unit tests + * Make a socket spec representing "tcp/localhost:123". Used by unit tests * performing hostname verification against the tls options created * below. **/ -extern SocketSpec local_spec; +SocketSpec make_local_spec(); /** * Make security options allowing you to talk to yourself using |