From af339d03b67f0515bee3f861e2c09feeb2c0caf9 Mon Sep 17 00:00:00 2001 From: Ruben Perez Date: Sun, 16 Oct 2022 22:42:57 +0200 Subject: [PATCH] Reduced integ test overparametrize --- test/integration/close_connection.cpp | 10 ++- test/integration/close_statement.cpp | 4 +- test/integration/connect.cpp | 8 +- test/integration/execute_statement.cpp | 16 ++-- test/integration/handshake.cpp | 73 ++++++++++++------- test/integration/prepare_statement.cpp | 10 ++- test/integration/query.cpp | 18 +++-- test/integration/quit_connection.cpp | 8 +- test/integration/reconnect.cpp | 11 ++- test/integration/resultset.cpp | 43 ++++------- test/integration/statement_lifecycle.cpp | 12 +-- .../utils/include/er_network_variant.hpp | 6 +- .../utils/include/integration_test_common.hpp | 62 ++-------------- .../utils/include/network_test.hpp | 39 ++++------ .../utils/src/er_network_variant.cpp | 38 ++++------ 15 files changed, 170 insertions(+), 188 deletions(-) diff --git a/test/integration/close_connection.cpp b/test/integration/close_connection.cpp index 87765f1f..da03a540 100644 --- a/test/integration/close_connection.cpp +++ b/test/integration/close_connection.cpp @@ -13,9 +13,13 @@ using namespace boost::mysql::test; using boost::mysql::error_code; +namespace { + +auto net_samples = create_network_samples({"tcp_sync_errc", "tcp_async_callback"}); + BOOST_AUTO_TEST_SUITE(test_close_connection) -BOOST_MYSQL_NETWORK_TEST(active_connection, network_fixture) +BOOST_MYSQL_NETWORK_TEST(active_connection, network_fixture, net_samples) { setup_and_connect(sample.net); @@ -35,7 +39,7 @@ BOOST_MYSQL_NETWORK_TEST(active_connection, network_fixture) BOOST_TEST(!conn->is_open()); } -BOOST_MYSQL_NETWORK_TEST(not_open_connection, network_fixture) +BOOST_MYSQL_NETWORK_TEST(not_open_connection, network_fixture, net_samples) { setup(sample.net); conn->close().validate_no_error(); @@ -43,3 +47,5 @@ BOOST_MYSQL_NETWORK_TEST(not_open_connection, network_fixture) } BOOST_AUTO_TEST_SUITE_END() // test_close_connection + +} // namespace diff --git a/test/integration/close_statement.cpp b/test/integration/close_statement.cpp index 6ad5651c..d444d588 100644 --- a/test/integration/close_statement.cpp +++ b/test/integration/close_statement.cpp @@ -11,9 +11,11 @@ using namespace boost::mysql::test; namespace { +auto net_samples = create_network_samples({"tcp_sync_errc", "tcp_async_callback"}); + BOOST_AUTO_TEST_SUITE(test_close_statement) -BOOST_MYSQL_NETWORK_TEST(success, network_fixture) +BOOST_MYSQL_NETWORK_TEST(success, network_fixture, net_samples) { setup_and_connect(sample.net); diff --git a/test/integration/connect.cpp b/test/integration/connect.cpp index 3ae67a08..ec9f83a0 100644 --- a/test/integration/connect.cpp +++ b/test/integration/connect.cpp @@ -13,12 +13,16 @@ using boost::mysql::error_code; namespace { +auto net_samples = create_network_samples( + {"tcp_sync_errc", "tcp_sync_exc", "tcp_async_callback", "tcp_async_callback_noerrinfo"} +); + BOOST_AUTO_TEST_SUITE(test_connect) // The OK case is already being tested by all other integ tests // that require the connection to be connected -BOOST_MYSQL_NETWORK_TEST(physical_error, network_fixture) +BOOST_MYSQL_NETWORK_TEST(physical_error, network_fixture, net_samples) { setup(sample.net); @@ -28,7 +32,7 @@ BOOST_MYSQL_NETWORK_TEST(physical_error, network_fixture) BOOST_TEST(!conn->is_open()); } -BOOST_MYSQL_NETWORK_TEST(physical_ok_handshake_error, network_fixture) +BOOST_MYSQL_NETWORK_TEST(physical_ok_handshake_error, network_fixture, net_samples) { setup(sample.net); set_credentials("integ_user", "bad_password"); diff --git a/test/integration/execute_statement.cpp b/test/integration/execute_statement.cpp index 4ddfbe59..a92a0d77 100644 --- a/test/integration/execute_statement.cpp +++ b/test/integration/execute_statement.cpp @@ -25,10 +25,14 @@ using boost::mysql::make_execute_params; namespace { +auto net_samples = create_network_samples( + {"tcp_sync_errc", "tcp_sync_exc", "tcp_async_callback", "tcp_async_callback_noerrinfo"} +); + BOOST_AUTO_TEST_SUITE(test_execute_statement) BOOST_AUTO_TEST_SUITE(iterator) -BOOST_MYSQL_NETWORK_TEST(ok_no_params, network_fixture) +BOOST_MYSQL_NETWORK_TEST(ok_no_params, network_fixture, net_samples) { setup_and_connect(sample.net); @@ -41,7 +45,7 @@ BOOST_MYSQL_NETWORK_TEST(ok_no_params, network_fixture) BOOST_TEST(result->base().valid()); } -BOOST_MYSQL_NETWORK_TEST(ok_with_params, network_fixture) +BOOST_MYSQL_NETWORK_TEST(ok_with_params, network_fixture, net_samples) { setup_and_connect(sample.net); @@ -55,7 +59,7 @@ BOOST_MYSQL_NETWORK_TEST(ok_with_params, network_fixture) BOOST_TEST(result->base().valid()); } -BOOST_MYSQL_NETWORK_TEST(mismatched_num_params, network_fixture) +BOOST_MYSQL_NETWORK_TEST(mismatched_num_params, network_fixture, net_samples) { setup_and_connect(sample.net); @@ -69,7 +73,7 @@ BOOST_MYSQL_NETWORK_TEST(mismatched_num_params, network_fixture) .validate_error(errc::wrong_num_params, {"param", "2", "1", "statement", "execute"}); } -BOOST_MYSQL_NETWORK_TEST(server_error, network_fixture) +BOOST_MYSQL_NETWORK_TEST(server_error, network_fixture, net_samples) { setup_and_connect(sample.net); start_transaction(); @@ -94,7 +98,7 @@ BOOST_AUTO_TEST_SUITE_END() // collection is a wrapper around execute_params, so only // a subset of tests are run here BOOST_AUTO_TEST_SUITE(collection) -BOOST_MYSQL_NETWORK_TEST(ok, network_fixture) +BOOST_MYSQL_NETWORK_TEST(ok, network_fixture, net_samples) { setup_and_connect(sample.net); @@ -107,7 +111,7 @@ BOOST_MYSQL_NETWORK_TEST(ok, network_fixture) BOOST_TEST(result->base().valid()); } -BOOST_MYSQL_NETWORK_TEST(error, network_fixture) +BOOST_MYSQL_NETWORK_TEST(error, network_fixture, net_samples) { setup_and_connect(sample.net); start_transaction(); diff --git a/test/integration/handshake.cpp b/test/integration/handshake.cpp index 333422ba..0a2443fb 100644 --- a/test/integration/handshake.cpp +++ b/test/integration/handshake.cpp @@ -34,6 +34,27 @@ using boost::mysql::tcp_ssl_resultset; namespace { +auto net_samples_ssl = create_network_samples( + {"tcp_ssl_sync_errc", + "tcp_ssl_sync_exc", + "tcp_ssl_async_callback", + "tcp_ssl_async_callback_noerrinfo"} +); + +auto net_samples_nossl = create_network_samples( + {"tcp_sync_errc", "tcp_sync_exc", "tcp_async_callback", "tcp_async_callback_noerrinfo"} +); + +// Subset of plaintext variants, to reduce test runtime +auto net_samples_all = create_network_samples( + {"tcp_ssl_sync_errc", + "tcp_ssl_sync_exc", + "tcp_ssl_async_callback", + "tcp_ssl_async_callback_noerrinfo", + "tcp_sync_errc", + "tcp_async_callback"} +); + BOOST_AUTO_TEST_SUITE(test_handshake) struct handshake_fixture : network_fixture @@ -68,21 +89,21 @@ struct handshake_fixture : network_fixture // mysql_native_password BOOST_AUTO_TEST_SUITE(mysql_native_password) -BOOST_MYSQL_NETWORK_TEST(regular_user, handshake_fixture) +BOOST_MYSQL_NETWORK_TEST(regular_user, handshake_fixture, net_samples_all) { setup_and_physical_connect(sample.net); set_credentials("mysqlnp_user", "mysqlnp_password"); do_handshake_ok(); } -BOOST_MYSQL_NETWORK_TEST(empty_password, handshake_fixture) +BOOST_MYSQL_NETWORK_TEST(empty_password, handshake_fixture, net_samples_all) { setup_and_physical_connect(sample.net); set_credentials("mysqlnp_empty_password_user", ""); do_handshake_ok(); } -BOOST_MYSQL_NETWORK_TEST(bad_password, handshake_fixture) +BOOST_MYSQL_NETWORK_TEST(bad_password, handshake_fixture, net_samples_all) { setup_and_physical_connect(sample.net); set_credentials("mysqlnp_user", "bad_password"); @@ -120,7 +141,7 @@ struct caching_sha2_fixture : handshake_fixture } }; -BOOST_MYSQL_NETWORK_TEST_SSL(ssl_on_cache_hit, caching_sha2_fixture) +BOOST_MYSQL_NETWORK_TEST(ssl_on_cache_hit, caching_sha2_fixture, net_samples_ssl) { setup_and_physical_connect(sample.net); set_credentials("csha2p_user", "csha2p_password"); @@ -128,7 +149,7 @@ BOOST_MYSQL_NETWORK_TEST_SSL(ssl_on_cache_hit, caching_sha2_fixture) do_handshake_ok_ssl(); } -BOOST_MYSQL_NETWORK_TEST(ssl_off_cache_hit, caching_sha2_fixture) +BOOST_MYSQL_NETWORK_TEST(ssl_off_cache_hit, caching_sha2_fixture, net_samples_all) { // As we are sending password hashed, it is OK to not have SSL for this setup_and_physical_connect(sample.net); @@ -137,7 +158,7 @@ BOOST_MYSQL_NETWORK_TEST(ssl_off_cache_hit, caching_sha2_fixture) do_handshake_ok_nossl(); } -BOOST_MYSQL_NETWORK_TEST_SSL(ssl_on_cache_miss, caching_sha2_fixture) +BOOST_MYSQL_NETWORK_TEST(ssl_on_cache_miss, caching_sha2_fixture, net_samples_ssl) { setup_and_physical_connect(sample.net); set_credentials("csha2p_user", "csha2p_password"); @@ -145,7 +166,7 @@ BOOST_MYSQL_NETWORK_TEST_SSL(ssl_on_cache_miss, caching_sha2_fixture) do_handshake_ok_ssl(); } -BOOST_MYSQL_NETWORK_TEST(ssl_off_cache_miss, caching_sha2_fixture) +BOOST_MYSQL_NETWORK_TEST(ssl_off_cache_miss, caching_sha2_fixture, net_samples_all) { // A cache miss would force us send a plaintext password over // a non-TLS connection, so we fail @@ -156,7 +177,7 @@ BOOST_MYSQL_NETWORK_TEST(ssl_off_cache_miss, caching_sha2_fixture) conn->handshake(params).validate_error(errc::auth_plugin_requires_ssl, {}); } -BOOST_MYSQL_NETWORK_TEST_SSL(empty_password_ssl_on_cache_hit, caching_sha2_fixture) +BOOST_MYSQL_NETWORK_TEST(empty_password_ssl_on_cache_hit, caching_sha2_fixture, net_samples_ssl) { setup_and_physical_connect(sample.net); set_credentials("csha2p_empty_password_user", ""); @@ -164,7 +185,7 @@ BOOST_MYSQL_NETWORK_TEST_SSL(empty_password_ssl_on_cache_hit, caching_sha2_fixtu do_handshake_ok_ssl(); } -BOOST_MYSQL_NETWORK_TEST(empty_password_ssl_off_cache_hit, caching_sha2_fixture) +BOOST_MYSQL_NETWORK_TEST(empty_password_ssl_off_cache_hit, caching_sha2_fixture, net_samples_all) { // Empty passwords are allowed over non-TLS connections setup_and_physical_connect(sample.net); @@ -173,7 +194,7 @@ BOOST_MYSQL_NETWORK_TEST(empty_password_ssl_off_cache_hit, caching_sha2_fixture) do_handshake_ok_nossl(); } -BOOST_MYSQL_NETWORK_TEST_SSL(empty_password_ssl_on_cache_miss, caching_sha2_fixture) +BOOST_MYSQL_NETWORK_TEST(empty_password_ssl_on_cache_miss, caching_sha2_fixture, net_samples_ssl) { setup_and_physical_connect(sample.net); set_credentials("csha2p_empty_password_user", ""); @@ -181,7 +202,7 @@ BOOST_MYSQL_NETWORK_TEST_SSL(empty_password_ssl_on_cache_miss, caching_sha2_fixt do_handshake_ok_ssl(); } -BOOST_MYSQL_NETWORK_TEST(empty_password_ssl_off_cache_miss, caching_sha2_fixture) +BOOST_MYSQL_NETWORK_TEST(empty_password_ssl_off_cache_miss, caching_sha2_fixture, net_samples_all) { // Empty passwords are allowed over non-TLS connections setup_and_physical_connect(sample.net); @@ -190,7 +211,7 @@ BOOST_MYSQL_NETWORK_TEST(empty_password_ssl_off_cache_miss, caching_sha2_fixture do_handshake_ok_nossl(); } -BOOST_MYSQL_NETWORK_TEST_SSL(bad_password_ssl_on_cache_hit, caching_sha2_fixture) +BOOST_MYSQL_NETWORK_TEST(bad_password_ssl_on_cache_hit, caching_sha2_fixture, net_samples_ssl) { // Note: test over non-TLS would return "ssl required" setup_and_physical_connect(sample.net); @@ -202,7 +223,7 @@ BOOST_MYSQL_NETWORK_TEST_SSL(bad_password_ssl_on_cache_hit, caching_sha2_fixture ); } -BOOST_MYSQL_NETWORK_TEST_SSL(bad_password_ssl_on_cache_miss, caching_sha2_fixture) +BOOST_MYSQL_NETWORK_TEST(bad_password_ssl_on_cache_miss, caching_sha2_fixture, net_samples_ssl) { // Note: test over non-TLS would return "ssl required" setup_and_physical_connect(sample.net); @@ -243,7 +264,7 @@ OzBrmpfHEhF6NDU= -----END CERTIFICATE----- )%"; -BOOST_MYSQL_NETWORK_TEST_SSL(certificate_valid, handshake_fixture) +BOOST_MYSQL_NETWORK_TEST(certificate_valid, handshake_fixture, net_samples_ssl) { // Context changes need to be before setup ssl_ctx.set_verify_mode(boost::asio::ssl::verify_peer); @@ -252,7 +273,7 @@ BOOST_MYSQL_NETWORK_TEST_SSL(certificate_valid, handshake_fixture) do_handshake_ok_ssl(); } -BOOST_MYSQL_NETWORK_TEST_SSL(certificate_invalid, handshake_fixture) +BOOST_MYSQL_NETWORK_TEST(certificate_invalid, handshake_fixture, net_samples_ssl) { ssl_ctx.set_verify_mode(boost::asio::ssl::verify_peer); setup_and_physical_connect(sample.net); @@ -260,7 +281,7 @@ BOOST_MYSQL_NETWORK_TEST_SSL(certificate_invalid, handshake_fixture) BOOST_TEST(result.err.message().find("certificate verify failed") != std::string::npos); } -BOOST_MYSQL_NETWORK_TEST_SSL(custom_certificate_verification_failed, handshake_fixture) +BOOST_MYSQL_NETWORK_TEST(custom_certificate_verification_failed, handshake_fixture, net_samples_ssl) { ssl_ctx.set_verify_mode(boost::asio::ssl::verify_peer); ssl_ctx.add_certificate_authority(boost::asio::buffer(CA_PEM)); @@ -270,7 +291,7 @@ BOOST_MYSQL_NETWORK_TEST_SSL(custom_certificate_verification_failed, handshake_f BOOST_TEST(result.err.message().find("certificate verify failed") != std::string::npos); } -BOOST_MYSQL_NETWORK_TEST_SSL(custom_certificate_verification_ok, handshake_fixture) +BOOST_MYSQL_NETWORK_TEST(custom_certificate_verification_ok, handshake_fixture, net_samples_ssl) { ssl_ctx.set_verify_mode(boost::asio::ssl::verify_peer); ssl_ctx.add_certificate_authority(boost::asio::buffer(CA_PEM)); @@ -282,14 +303,14 @@ BOOST_MYSQL_NETWORK_TEST_SSL(custom_certificate_verification_ok, handshake_fixtu BOOST_AUTO_TEST_SUITE_END() // ssl_certificate_validation // Other handshake tests -BOOST_MYSQL_NETWORK_TEST(no_database, handshake_fixture) +BOOST_MYSQL_NETWORK_TEST(no_database, handshake_fixture, net_samples_all) { setup_and_physical_connect(sample.net); params.set_database(""); do_handshake_ok(); } -BOOST_MYSQL_NETWORK_TEST(bad_database, handshake_fixture) +BOOST_MYSQL_NETWORK_TEST(bad_database, handshake_fixture, net_samples_all) { setup_and_physical_connect(sample.net); params.set_database("bad_database"); @@ -300,7 +321,7 @@ BOOST_MYSQL_NETWORK_TEST(bad_database, handshake_fixture) } BOOST_TEST_DECORATOR(*boost::unit_test::label("sha256")) -BOOST_MYSQL_NETWORK_TEST_SSL(unknown_auth_plugin, handshake_fixture) +BOOST_MYSQL_NETWORK_TEST(unknown_auth_plugin, handshake_fixture, net_samples_ssl) { // Note: sha256_password is not supported, so it's an unknown plugin to us setup_and_physical_connect(sample.net); @@ -308,7 +329,7 @@ BOOST_MYSQL_NETWORK_TEST_SSL(unknown_auth_plugin, handshake_fixture) conn->handshake(params).validate_error(errc::unknown_auth_plugin, {}); } -BOOST_MYSQL_NETWORK_TEST_SSL(bad_user, handshake_fixture) +BOOST_MYSQL_NETWORK_TEST(bad_user, handshake_fixture, net_samples_nossl) { // unreliable without SSL. If the default plugin requires SSL // (like SHA256), this would fail with 'ssl required' @@ -317,7 +338,7 @@ BOOST_MYSQL_NETWORK_TEST_SSL(bad_user, handshake_fixture) conn->handshake(params).validate_any_error(); // may be access denied or unknown auth plugin } -BOOST_MYSQL_NETWORK_TEST(ssl_disable, handshake_fixture) +BOOST_MYSQL_NETWORK_TEST(ssl_disable, handshake_fixture, net_samples_all) { // Both SSL and non-SSL streams will act as non-SSL streams setup_and_physical_connect(sample.net); @@ -326,7 +347,7 @@ BOOST_MYSQL_NETWORK_TEST(ssl_disable, handshake_fixture) BOOST_TEST(!conn->uses_ssl()); } -BOOST_MYSQL_NETWORK_TEST_NOSSL(ssl_enable_nonssl_streams, handshake_fixture) +BOOST_MYSQL_NETWORK_TEST(ssl_enable_nonssl_streams, handshake_fixture, net_samples_nossl) { // Ignored by non-ssl streams setup_and_physical_connect(sample.net); @@ -335,7 +356,7 @@ BOOST_MYSQL_NETWORK_TEST_NOSSL(ssl_enable_nonssl_streams, handshake_fixture) BOOST_TEST(!conn->uses_ssl()); } -BOOST_MYSQL_NETWORK_TEST_SSL(ssl_enable_ssl_streams, handshake_fixture) +BOOST_MYSQL_NETWORK_TEST(ssl_enable_ssl_streams, handshake_fixture, net_samples_ssl) { // In all our CI systems, our servers support SSL, so // ssl_mode::enable will do the same as ssl_mode::require. @@ -346,7 +367,7 @@ BOOST_MYSQL_NETWORK_TEST_SSL(ssl_enable_ssl_streams, handshake_fixture) BOOST_TEST(conn->uses_ssl()); } -BOOST_MYSQL_NETWORK_TEST_NOSSL(ssl_require_nonssl_streams, handshake_fixture) +BOOST_MYSQL_NETWORK_TEST(ssl_require_nonssl_streams, handshake_fixture, net_samples_nossl) { // Ignored by non-ssl streams setup_and_physical_connect(sample.net); @@ -355,7 +376,7 @@ BOOST_MYSQL_NETWORK_TEST_NOSSL(ssl_require_nonssl_streams, handshake_fixture) BOOST_TEST(!conn->uses_ssl()); } -BOOST_MYSQL_NETWORK_TEST_SSL(ssl_require_ssl_streams, handshake_fixture) +BOOST_MYSQL_NETWORK_TEST(ssl_require_ssl_streams, handshake_fixture, net_samples_ssl) { setup_and_physical_connect(sample.net); params.set_ssl(ssl_mode::require); diff --git a/test/integration/prepare_statement.cpp b/test/integration/prepare_statement.cpp index 11eec8d8..cdda53c9 100644 --- a/test/integration/prepare_statement.cpp +++ b/test/integration/prepare_statement.cpp @@ -23,9 +23,13 @@ using boost::mysql::tcp_statement; namespace { +auto net_samples = create_network_samples( + {"tcp_sync_errc", "tcp_sync_exc", "tcp_async_callback", "tcp_async_callback_noerrinfo"} +); + BOOST_AUTO_TEST_SUITE(test_prepare_statement) -BOOST_MYSQL_NETWORK_TEST(ok_no_params, network_fixture) +BOOST_MYSQL_NETWORK_TEST(ok_no_params, network_fixture, net_samples) { setup_and_connect(sample.net); conn->prepare_statement("SELECT * FROM empty_table", *stmt).validate_no_error(); @@ -34,7 +38,7 @@ BOOST_MYSQL_NETWORK_TEST(ok_no_params, network_fixture) BOOST_TEST(stmt->base().num_params() == 0u); } -BOOST_MYSQL_NETWORK_TEST(ok_with_params, network_fixture) +BOOST_MYSQL_NETWORK_TEST(ok_with_params, network_fixture, net_samples) { setup_and_connect(sample.net); conn->prepare_statement("SELECT * FROM empty_table WHERE id IN (?, ?)", *stmt) @@ -44,7 +48,7 @@ BOOST_MYSQL_NETWORK_TEST(ok_with_params, network_fixture) BOOST_TEST(stmt->base().num_params() == 2u); } -BOOST_MYSQL_NETWORK_TEST(invalid_statement, network_fixture) +BOOST_MYSQL_NETWORK_TEST(invalid_statement, network_fixture, net_samples) { setup_and_connect(sample.net); conn->prepare_statement("SELECT * FROM bad_table WHERE id IN (?, ?)", *stmt) diff --git a/test/integration/query.cpp b/test/integration/query.cpp index a3b3401c..0f7d09f7 100644 --- a/test/integration/query.cpp +++ b/test/integration/query.cpp @@ -14,9 +14,15 @@ using namespace boost::mysql::test; using boost::mysql::errc; +namespace { + +auto net_samples = create_network_samples( + {"tcp_sync_errc", "tcp_sync_exc", "tcp_async_callback", "tcp_async_callback_noerrinfo"} +); + BOOST_AUTO_TEST_SUITE(test_query) -BOOST_MYSQL_NETWORK_TEST(insert_ok, network_fixture) +BOOST_MYSQL_NETWORK_TEST(insert_ok, network_fixture, net_samples) { setup_and_connect(sample.net); start_transaction(); @@ -41,7 +47,7 @@ BOOST_MYSQL_NETWORK_TEST(insert_ok, network_fixture) BOOST_TEST(this->get_table_size("inserts_table") == 1u); } -BOOST_MYSQL_NETWORK_TEST(insert_error, network_fixture) +BOOST_MYSQL_NETWORK_TEST(insert_error, network_fixture, net_samples) { setup_and_connect(sample.net); start_transaction(); @@ -52,7 +58,7 @@ BOOST_MYSQL_NETWORK_TEST(insert_error, network_fixture) netresult.validate_error(errc::no_such_table, {"table", "doesn't exist", "bad_table"}); } -BOOST_MYSQL_NETWORK_TEST(update_ok, network_fixture) +BOOST_MYSQL_NETWORK_TEST(update_ok, network_fixture, net_samples) { setup_and_connect(sample.net); start_transaction(); @@ -75,7 +81,7 @@ BOOST_MYSQL_NETWORK_TEST(update_ok, network_fixture) BOOST_TEST(updated_value == 52); // initial value was 42 } -BOOST_MYSQL_NETWORK_TEST(select_ok, network_fixture) +BOOST_MYSQL_NETWORK_TEST(select_ok, network_fixture, net_samples) { setup_and_connect(sample.net); @@ -86,7 +92,7 @@ BOOST_MYSQL_NETWORK_TEST(select_ok, network_fixture) this->validate_2fields_meta(result->base(), "empty_table"); } -BOOST_MYSQL_NETWORK_TEST(select_error, network_fixture) +BOOST_MYSQL_NETWORK_TEST(select_error, network_fixture, net_samples) { setup_and_connect(sample.net); auto netresult = conn->query("SELECT field_varchar, field_bad FROM one_row_table", *result); @@ -94,3 +100,5 @@ BOOST_MYSQL_NETWORK_TEST(select_error, network_fixture) } BOOST_AUTO_TEST_SUITE_END() // test_query + +} // namespace diff --git a/test/integration/quit_connection.cpp b/test/integration/quit_connection.cpp index 60f49c7e..4fdc5a5d 100644 --- a/test/integration/quit_connection.cpp +++ b/test/integration/quit_connection.cpp @@ -10,9 +10,13 @@ using namespace boost::mysql::test; using boost::mysql::error_code; +namespace { + +auto net_samples = create_network_samples({"tcp_sync_errc", "tcp_async_callback"}); + BOOST_AUTO_TEST_SUITE(test_quit_connection) -BOOST_MYSQL_NETWORK_TEST(active_connection, network_fixture) +BOOST_MYSQL_NETWORK_TEST(active_connection, network_fixture, net_samples) { setup_and_connect(sample.net); @@ -24,3 +28,5 @@ BOOST_MYSQL_NETWORK_TEST(active_connection, network_fixture) } BOOST_AUTO_TEST_SUITE_END() // test_quit_connection + +} // namespace diff --git a/test/integration/reconnect.cpp b/test/integration/reconnect.cpp index e88ef24a..75874bd2 100644 --- a/test/integration/reconnect.cpp +++ b/test/integration/reconnect.cpp @@ -19,6 +19,11 @@ using namespace boost::mysql::test; namespace { +auto net_samples_nossl = create_network_samples({"tcp_sync_errc", "tcp_async_callback"}); +auto net_samples_all = create_network_samples( + {"tcp_sync_errc", "tcp_async_callback", "tcp_ssl_sync_errc", "tcp_ssl_async_callback"} +); + BOOST_AUTO_TEST_SUITE(test_reconnect) struct reconnect_fixture : network_fixture @@ -31,7 +36,7 @@ struct reconnect_fixture : network_fixture } }; -BOOST_MYSQL_NETWORK_TEST_NOSSL(reconnect_after_close, reconnect_fixture) +BOOST_MYSQL_NETWORK_TEST(reconnect_after_close, reconnect_fixture, net_samples_nossl) { setup(sample.net); @@ -47,7 +52,7 @@ BOOST_MYSQL_NETWORK_TEST_NOSSL(reconnect_after_close, reconnect_fixture) do_query_ok(); } -BOOST_MYSQL_NETWORK_TEST_NOSSL(reconnect_after_handshake_error, reconnect_fixture) +BOOST_MYSQL_NETWORK_TEST(reconnect_after_handshake_error, reconnect_fixture, net_samples_nossl) { setup(sample.net); @@ -62,7 +67,7 @@ BOOST_MYSQL_NETWORK_TEST_NOSSL(reconnect_after_handshake_error, reconnect_fixtur do_query_ok(); } -BOOST_MYSQL_NETWORK_TEST(reconnect_after_physical_connect_error, reconnect_fixture) +BOOST_MYSQL_NETWORK_TEST(reconnect_after_physical_connect_error, reconnect_fixture, net_samples_all) { setup(sample.net); diff --git a/test/integration/resultset.cpp b/test/integration/resultset.cpp index 9f065170..a2f04b51 100644 --- a/test/integration/resultset.cpp +++ b/test/integration/resultset.cpp @@ -92,24 +92,11 @@ std::ostream& operator<<(std::ostream& os, const resultset_sample& input) return os << static_cast(input) << '_' << input.gen->name(); } -struct sample_gen -{ - std::vector make_all() const - { - std::vector res; - for (auto* net : all_variants()) - { - res.emplace_back(net, &text_obj); - res.emplace_back(net, &binary_obj); - } - return res; - } - - const std::vector& operator()() const - { - static const auto res = make_all(); - return res; - } +resultset_sample net_samples[] = { + resultset_sample(get_variant("tcp_sync_errc"), &text_obj), + resultset_sample(get_variant("tcp_async_callback"), &text_obj), + resultset_sample(get_variant("tcp_sync_exc"), &binary_obj), + resultset_sample(get_variant("tcp_async_callback_noerrinfo"), &binary_obj), }; struct resultset_fixture : network_fixture @@ -131,7 +118,7 @@ struct resultset_fixture : network_fixture BOOST_AUTO_TEST_SUITE(read_one) -BOOST_MYSQL_NETWORK_TEST_EX(no_results, resultset_fixture, sample_gen()) +BOOST_MYSQL_NETWORK_TEST(no_results, resultset_fixture, net_samples) { setup_and_connect(sample); generate("SELECT * FROM empty_table"); @@ -150,7 +137,7 @@ BOOST_MYSQL_NETWORK_TEST_EX(no_results, resultset_fixture, sample_gen()) validate_eof(*result); } -BOOST_MYSQL_NETWORK_TEST_EX(one_row, resultset_fixture, sample_gen()) +BOOST_MYSQL_NETWORK_TEST(one_row, resultset_fixture, net_samples) { setup_and_connect(sample); generate("SELECT * FROM one_row_table"); @@ -170,7 +157,7 @@ BOOST_MYSQL_NETWORK_TEST_EX(one_row, resultset_fixture, sample_gen()) validate_eof(*result); } -BOOST_MYSQL_NETWORK_TEST_EX(two_rows, resultset_fixture, sample_gen()) +BOOST_MYSQL_NETWORK_TEST(two_rows, resultset_fixture, net_samples) { setup_and_connect(sample); generate("SELECT * FROM two_rows_table"); @@ -200,7 +187,7 @@ BOOST_AUTO_TEST_SUITE_END() // read_one BOOST_AUTO_TEST_SUITE(read_some) -BOOST_MYSQL_NETWORK_TEST_EX(no_results, resultset_fixture, sample_gen()) +BOOST_MYSQL_NETWORK_TEST(no_results, resultset_fixture, net_samples) { setup_and_connect(sample); generate("SELECT * FROM empty_table"); @@ -216,7 +203,7 @@ BOOST_MYSQL_NETWORK_TEST_EX(no_results, resultset_fixture, sample_gen()) validate_eof(*result); } -BOOST_MYSQL_NETWORK_TEST_EX(one_row, resultset_fixture, sample_gen()) +BOOST_MYSQL_NETWORK_TEST(one_row, resultset_fixture, net_samples) { setup_and_connect(sample); generate("SELECT * FROM one_row_table"); @@ -237,7 +224,7 @@ BOOST_MYSQL_NETWORK_TEST_EX(one_row, resultset_fixture, sample_gen()) validate_eof(*result); } -BOOST_MYSQL_NETWORK_TEST_EX(several_rows, resultset_fixture, sample_gen()) +BOOST_MYSQL_NETWORK_TEST(several_rows, resultset_fixture, net_samples) { setup_and_connect(sample); generate("SELECT * FROM three_rows_table"); @@ -268,7 +255,7 @@ BOOST_MYSQL_NETWORK_TEST_EX(several_rows, resultset_fixture, sample_gen()) validate_eof(*result); } -BOOST_MYSQL_NETWORK_TEST_EX(several_rows_single_read, resultset_fixture, sample_gen()) +BOOST_MYSQL_NETWORK_TEST(several_rows_single_read, resultset_fixture, net_samples) { // make sure the entire result can be read at once params.set_buffer_config(boost::mysql::buffer_params(4096)); @@ -290,7 +277,7 @@ BOOST_AUTO_TEST_SUITE_END() // read_many BOOST_AUTO_TEST_SUITE(read_all) -BOOST_MYSQL_NETWORK_TEST_EX(no_results, resultset_fixture, sample_gen()) +BOOST_MYSQL_NETWORK_TEST(no_results, resultset_fixture, net_samples) { setup_and_connect(sample); generate("SELECT * FROM empty_table"); @@ -306,7 +293,7 @@ BOOST_MYSQL_NETWORK_TEST_EX(no_results, resultset_fixture, sample_gen()) validate_eof(*result); } -BOOST_MYSQL_NETWORK_TEST_EX(one_row, resultset_fixture, sample_gen()) +BOOST_MYSQL_NETWORK_TEST(one_row, resultset_fixture, net_samples) { setup_and_connect(sample); generate("SELECT * FROM one_row_table"); @@ -322,7 +309,7 @@ BOOST_MYSQL_NETWORK_TEST_EX(one_row, resultset_fixture, sample_gen()) validate_eof(*result); } -BOOST_MYSQL_NETWORK_TEST_EX(several_rows, resultset_fixture, sample_gen()) +BOOST_MYSQL_NETWORK_TEST(several_rows, resultset_fixture, net_samples) { setup_and_connect(sample); generate("SELECT * FROM two_rows_table"); diff --git a/test/integration/statement_lifecycle.cpp b/test/integration/statement_lifecycle.cpp index 53d0dd12..970748e8 100644 --- a/test/integration/statement_lifecycle.cpp +++ b/test/integration/statement_lifecycle.cpp @@ -15,6 +15,8 @@ using boost::mysql::field_view; namespace { +auto net_samples = create_network_samples({"tcp_sync_errc", "tcp_async_callback"}); + BOOST_AUTO_TEST_SUITE(test_statement_lifecycle) struct statement_lifecycle_fixture : network_fixture @@ -30,7 +32,7 @@ struct statement_lifecycle_fixture : network_fixture } }; -BOOST_MYSQL_NETWORK_TEST(select_with_parameters_multiple_executions, statement_lifecycle_fixture) +BOOST_MYSQL_NETWORK_TEST(select_with_parameters, statement_lifecycle_fixture, net_samples) { setup_and_connect(sample.net); @@ -65,7 +67,7 @@ BOOST_MYSQL_NETWORK_TEST(select_with_parameters_multiple_executions, statement_l stmt->close().validate_no_error(); } -BOOST_MYSQL_NETWORK_TEST(insert_with_parameters_multiple_executions, statement_lifecycle_fixture) +BOOST_MYSQL_NETWORK_TEST(insert_with_parameters, statement_lifecycle_fixture, net_samples) { setup_and_connect(sample.net); start_transaction(); @@ -93,7 +95,7 @@ BOOST_MYSQL_NETWORK_TEST(insert_with_parameters_multiple_executions, statement_l stmt->close().validate_no_error(); } -BOOST_MYSQL_NETWORK_TEST(update_with_parameters_multiple_executions, statement_lifecycle_fixture) +BOOST_MYSQL_NETWORK_TEST(update_with_parameters, statement_lifecycle_fixture, net_samples) { setup_and_connect(sample.net); start_transaction(); @@ -124,7 +126,7 @@ BOOST_MYSQL_NETWORK_TEST(update_with_parameters_multiple_executions, statement_l stmt->close().validate_no_error(); } -BOOST_MYSQL_NETWORK_TEST(multiple_statements, statement_lifecycle_fixture) +BOOST_MYSQL_NETWORK_TEST(multiple_statements, statement_lifecycle_fixture, net_samples) { setup_and_connect(sample.net); start_transaction(); @@ -174,7 +176,7 @@ BOOST_MYSQL_NETWORK_TEST(multiple_statements, statement_lifecycle_fixture) stmt_select->close().validate_no_error(); } -BOOST_MYSQL_NETWORK_TEST(insert_with_null_values, statement_lifecycle_fixture) +BOOST_MYSQL_NETWORK_TEST(insert_with_null_values, statement_lifecycle_fixture, net_samples) { setup_and_connect(sample.net); start_transaction(); diff --git a/test/integration/utils/include/er_network_variant.hpp b/test/integration/utils/include/er_network_variant.hpp index ff057775..083fac10 100644 --- a/test/integration/utils/include/er_network_variant.hpp +++ b/test/integration/utils/include/er_network_variant.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include @@ -27,15 +28,14 @@ public: virtual bool supports_ssl() const = 0; virtual const char* stream_name() const = 0; virtual const char* variant_name() const = 0; + std::string name() const { return std::string(stream_name()) + '_' + variant_name(); } virtual er_connection_ptr create_connection(boost::asio::io_context::executor_type, boost::asio::ssl::context&) = 0; virtual er_resultset_ptr create_resultset() = 0; virtual er_statement_ptr create_statement() = 0; }; boost::span all_variants(); -boost::span ssl_variants(); -boost::span non_ssl_variants(); -er_network_variant* tcp_sync_errc_variant(); +er_network_variant* get_variant(boost::string_view name); } // namespace test } // namespace mysql diff --git a/test/integration/utils/include/integration_test_common.hpp b/test/integration/utils/include/integration_test_common.hpp index 10c3cb10..3f5da9ee 100644 --- a/test/integration/utils/include/integration_test_common.hpp +++ b/test/integration/utils/include/integration_test_common.hpp @@ -16,6 +16,7 @@ #include #include +#include #include #include "er_connection.hpp" @@ -156,62 +157,13 @@ inline std::ostream& operator<<(std::ostream& os, const network_sample& value) return os << value.net->stream_name() << "_" << value.net->variant_name(); } -struct all_variants_gen +inline std::vector create_network_samples(std::initializer_list names) { - std::vector make_all() const - { - std::vector res; - for (auto* net : all_variants()) - { - res.emplace_back(net); - } - return res; - } - - const std::vector& operator()() const - { - static auto res = make_all(); - return res; - } -}; - -struct ssl_only_gen -{ - std::vector make_all() const - { - std::vector res; - for (auto* net : ssl_variants()) - { - res.emplace_back(net); - } - return res; - } - - const std::vector& operator()() const - { - static auto res = make_all(); - return res; - } -}; - -struct non_ssl_only_gen -{ - std::vector make_all() const - { - std::vector res; - for (auto* net : non_ssl_variants()) - { - res.emplace_back(net); - } - return res; - } - - const std::vector& operator()() const - { - static auto res = make_all(); - return res; - } -}; + std::vector res; + for (const char* name : names) + res.emplace_back(get_variant(name)); + return res; +} } // namespace test } // namespace mysql diff --git a/test/integration/utils/include/network_test.hpp b/test/integration/utils/include/network_test.hpp index d65c8a6f..e08c84eb 100644 --- a/test/integration/utils/include/network_test.hpp +++ b/test/integration/utils/include/network_test.hpp @@ -12,6 +12,8 @@ #include +#include + /** * Defines the required infrastructure for network tests. * These are data-driven (parametrized) test cases. We don't @@ -34,9 +36,9 @@ namespace mysql { namespace test { // The type of a sample generated by DataGenerator -template -using data_gen_sample_type = typename std::decay< - decltype(std::declval::type>()()[0])>::type; +template +using sample_type = typename std::decay() +))>::type; inline boost::unit_test::test_suite* create_test_suite( boost::unit_test::const_string tc_name, @@ -62,19 +64,19 @@ inline boost::unit_test::test_suite* create_test_suite( template struct network_test_registrar { - template + template network_test_registrar( boost::unit_test::const_string tc_name, boost::unit_test::const_string tc_file, std::size_t tc_line, - const DataGen& datagen + const SampleCollection& samples ) { // Create suite auto* suite = create_test_suite(tc_name, tc_file, tc_line); // Create a test for each sample - for (const auto& sample : datagen()) + for (const auto& sample : samples) { std::string test_name = detail::stringize(sample); auto* test = boost::unit_test::make_test_case( @@ -96,22 +98,13 @@ struct network_test_registrar } // namespace mysql } // namespace boost -#define BOOST_MYSQL_NETWORK_TEST_EX(name, fixture, sample_generator) \ - struct name : public fixture \ - { \ - void test_method(const data_gen_sample_type&); \ - }; \ - static ::boost::mysql::test::network_test_registrar name##_registrar \ - BOOST_ATTRIBUTE_UNUSED(#name, __FILE__, __LINE__, sample_generator); \ - void name::test_method(const data_gen_sample_type& sample) - -#define BOOST_MYSQL_NETWORK_TEST(name, fixture) \ - BOOST_MYSQL_NETWORK_TEST_EX(name, fixture, all_variants_gen()) - -#define BOOST_MYSQL_NETWORK_TEST_SSL(name, fixture) \ - BOOST_MYSQL_NETWORK_TEST_EX(name, fixture, ssl_only_gen()) - -#define BOOST_MYSQL_NETWORK_TEST_NOSSL(name, fixture) \ - BOOST_MYSQL_NETWORK_TEST_EX(name, fixture, non_ssl_only_gen()) +#define BOOST_MYSQL_NETWORK_TEST(name, fixture, samples) \ + struct name : public fixture \ + { \ + void test_method(const sample_type&); \ + }; \ + static ::boost::mysql::test::network_test_registrar name##_registrar \ + BOOST_ATTRIBUTE_UNUSED(#name, __FILE__, __LINE__, samples); \ + void name::test_method(const sample_type& sample) #endif diff --git a/test/integration/utils/src/er_network_variant.cpp b/test/integration/utils/src/er_network_variant.cpp index 961d7aea..4f8c33d8 100644 --- a/test/integration/utils/src/er_network_variant.cpp +++ b/test/integration/utils/src/er_network_variant.cpp @@ -10,6 +10,8 @@ #include #include #include +#include +#include #include "er_impl_common.hpp" #include "er_network_variant.hpp" @@ -30,23 +32,11 @@ static std::vector make_all_variants() return res; } -static std::vector make_ssl_variants() +static std::unordered_map make_variants_map() { - auto all = make_all_variants(); - std::vector res; - std::copy_if(all.begin(), all.end(), std::back_inserter(res), [](er_network_variant* v) { - return v->supports_ssl(); - }); - return res; -} - -static std::vector make_non_ssl_variants() -{ - auto all = make_all_variants(); - std::vector res; - std::copy_if(all.begin(), all.end(), std::back_inserter(res), [](er_network_variant* v) { - return !v->supports_ssl(); - }); + std::unordered_map res; + for (auto* var : all_variants()) + res[var->name()] = var; return res; } @@ -56,14 +46,12 @@ boost::span boost::mysql::test::all_variants() return res; } -boost::span boost::mysql::test::ssl_variants() +er_network_variant* boost::mysql::test::get_variant(boost::string_view name) { - static auto res = make_ssl_variants(); - return res; -} - -boost::span boost::mysql::test::non_ssl_variants() -{ - static auto res = make_non_ssl_variants(); - return res; + static auto by_name = make_variants_map(); + std::string name_str(name); + auto it = by_name.find(name_str); + if (it == by_name.end()) + throw std::out_of_range("Unknown network variant: " + name_str); + return it->second; }