From cb1ca4e66e3d0c6816acc6833c2e078d08b80e0c Mon Sep 17 00:00:00 2001 From: Teemu Ollakka Date: Wed, 17 Oct 2018 12:51:01 +0300 Subject: [PATCH] Rollback and release streaming appliers in unit tests Unit tests which cause streaming rollback leaked memory because the streaming applier handle which was created for rollback fragment handling was not released. Roll back a streaming transaction and release applier handle appropriately in corresponding tests. --- test/client_state_fixture.hpp | 1 + test/mock_server_state.hpp | 5 +++-- test/transaction_test.cpp | 36 +++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/test/client_state_fixture.hpp b/test/client_state_fixture.hpp index 4ea2309..6073d25 100644 --- a/test/client_state_fixture.hpp +++ b/test/client_state_fixture.hpp @@ -203,6 +203,7 @@ namespace BOOST_REQUIRE(tc.state() == wsrep::transaction::s_executing); cc.enable_streaming(wsrep::streaming_context::row, 1); } + wsrep::mock_server_service server_service; wsrep::mock_server_state sc; wsrep::mock_client cc; diff --git a/test/mock_server_state.hpp b/test/mock_server_state.hpp index a9b14c1..7392d08 100644 --- a/test/mock_server_state.hpp +++ b/test/mock_server_state.hpp @@ -115,8 +115,9 @@ namespace wsrep WSREP_OVERRIDE { mock_high_priority_service* mhps( - reinterpret_cast(high_priority_service)); - wsrep::client_state* cs(mhps->client_state()); + static_cast(high_priority_service)); + wsrep::mock_client* cs(static_cast( + mhps->client_state())); cs->after_command_before_result(); cs->after_command_after_result(); cs->close(); diff --git a/test/transaction_test.cpp b/test/transaction_test.cpp index 46ec414..3b78e7d 100644 --- a/test/transaction_test.cpp +++ b/test/transaction_test.cpp @@ -1067,6 +1067,15 @@ BOOST_FIXTURE_TEST_CASE(transaction_row_streaming_rollback, BOOST_REQUIRE(sc.provider().fragments() == 2); BOOST_REQUIRE(sc.provider().start_fragments() == 1); BOOST_REQUIRE(sc.provider().rollback_fragments() == 1); + + wsrep::high_priority_service* hps( + sc.find_streaming_applier( + sc.id(), wsrep::transaction_id(1))); + BOOST_REQUIRE(hps); + hps->rollback(wsrep::ws_handle(), wsrep::ws_meta()); + hps->after_apply(); + sc.stop_streaming_applier(sc.id(), wsrep::transaction_id(1)); + server_service.release_high_priority_service(hps); } // @@ -1087,6 +1096,15 @@ BOOST_FIXTURE_TEST_CASE(transaction_row_streaming_cert_fail_non_commit, BOOST_REQUIRE(sc.provider().fragments() == 2); BOOST_REQUIRE(sc.provider().start_fragments() == 1); BOOST_REQUIRE(sc.provider().rollback_fragments() == 1); + + wsrep::high_priority_service* hps( + sc.find_streaming_applier( + sc.id(), wsrep::transaction_id(1))); + BOOST_REQUIRE(hps); + hps->rollback(wsrep::ws_handle(), wsrep::ws_meta()); + hps->after_apply(); + sc.stop_streaming_applier(sc.id(), wsrep::transaction_id(1)); + server_service.release_high_priority_service(hps); } // @@ -1109,6 +1127,15 @@ BOOST_FIXTURE_TEST_CASE(transaction_row_streaming_cert_fail_commit, BOOST_REQUIRE(sc.provider().fragments() == 2); BOOST_REQUIRE(sc.provider().start_fragments() == 1); BOOST_REQUIRE(sc.provider().rollback_fragments() == 1); + + wsrep::high_priority_service* hps( + sc.find_streaming_applier( + sc.id(), wsrep::transaction_id(1))); + BOOST_REQUIRE(hps); + hps->rollback(wsrep::ws_handle(), wsrep::ws_meta()); + hps->after_apply(); + sc.stop_streaming_applier(sc.id(), wsrep::transaction_id(1)); + server_service.release_high_priority_service(hps); } // @@ -1243,6 +1270,15 @@ BOOST_FIXTURE_TEST_CASE(transaction_statement_streaming_cert_fail, BOOST_REQUIRE(sc.provider().fragments() == 1); BOOST_REQUIRE(sc.provider().start_fragments() == 0); BOOST_REQUIRE(sc.provider().rollback_fragments() == 1); + + wsrep::high_priority_service* hps( + sc.find_streaming_applier( + sc.id(), wsrep::transaction_id(1))); + BOOST_REQUIRE(hps); + hps->rollback(wsrep::ws_handle(), wsrep::ws_meta()); + hps->after_apply(); + sc.stop_streaming_applier(sc.id(), wsrep::transaction_id(1)); + server_service.release_high_priority_service(hps); } ///////////////////////////////////////////////////////////////////////////////