diff --git a/test/boost/database_test.cc b/test/boost/database_test.cc index c28c9d6b49..8a24a11f7c 100644 --- a/test/boost/database_test.cc +++ b/test/boost/database_test.cc @@ -564,7 +564,8 @@ SEASTAR_THREAD_TEST_CASE(test_distributed_loader_with_pending_delete) { } // Snapshot tests and their helpers -future<> do_with_some_data(std::vector cf_names, std::function (cql_test_env& env)> func, bool create_mvs = false, shared_ptr db_cfg_ptr = {}) { +// \param func: function to be called back, in a seastar thread. +future<> do_with_some_data_in_thread(std::vector cf_names, std::function func, bool create_mvs = false, shared_ptr db_cfg_ptr = {}) { return seastar::async([cf_names = std::move(cf_names), func = std::move(func), create_mvs, db_cfg_ptr = std::move(db_cfg_ptr)] () mutable { lw_shared_ptr tmpdir_for_data; if (!db_cfg_ptr) { @@ -603,11 +604,17 @@ future<> do_with_some_data(std::vector cf_names, std::function } } - func(e).get(); + func(e); }, db_cfg_ptr).get(); }); } +future<> do_with_some_data(std::vector cf_names, std::function (cql_test_env&)> func, bool create_mvs = false, shared_ptr db_cfg_ptr = {}) { + co_await do_with_some_data_in_thread(cf_names, [&] (cql_test_env& e) { + func(e).get(); + }, create_mvs, db_cfg_ptr); +} + future<> take_snapshot(sharded& db, bool skip_flush = false, sstring ks_name = "ks", sstring cf_name = "cf", sstring snapshot_name = "test") { try { co_await replica::database::snapshot_table_on_all_shards(db, ks_name, cf_name, snapshot_name, skip_flush); @@ -633,7 +640,7 @@ fs::path table_dir(const replica::column_family& cf) { } static future<> snapshot_works(const std::string& table_name) { - return do_with_some_data({"cf"}, [table_name] (cql_test_env& e) { + return do_with_some_data_in_thread({"cf"}, [table_name] (cql_test_env& e) { take_snapshot(e, "ks", table_name).get(); std::set expected = { @@ -659,7 +666,6 @@ static future<> snapshot_works(const std::string& table_name) { }).get(); BOOST_REQUIRE_EQUAL(expected.size(), 0); - return make_ready_future<>(); }, true); } @@ -676,7 +682,7 @@ SEASTAR_TEST_CASE(index_snapshot_works) { } SEASTAR_TEST_CASE(snapshot_skip_flush_works) { - return do_with_some_data({"cf"}, [] (cql_test_env& e) { + return do_with_some_data_in_thread({"cf"}, [] (cql_test_env& e) { take_snapshot(e, true /* skip_flush */).get(); std::set expected = { @@ -699,12 +705,11 @@ SEASTAR_TEST_CASE(snapshot_skip_flush_works) { }).get(); BOOST_REQUIRE_EQUAL(expected.size(), 0); - return make_ready_future<>(); }); } SEASTAR_TEST_CASE(snapshot_list_okay) { - return do_with_some_data({"cf"}, [] (cql_test_env& e) { + return do_with_some_data_in_thread({"cf"}, [] (cql_test_env& e) { auto& cf = e.local_db().find_column_family("ks", "cf"); take_snapshot(e).get(); @@ -724,13 +729,11 @@ SEASTAR_TEST_CASE(snapshot_list_okay) { BOOST_REQUIRE_EQUAL(sd_post_deletion.total, sd_post_deletion.live); BOOST_REQUIRE_EQUAL(sd.total, sd_post_deletion.live); - - return make_ready_future<>(); }); } SEASTAR_TEST_CASE(snapshot_list_contains_dropped_tables) { - return do_with_some_data({"cf1", "cf2", "cf3", "cf4"}, [] (cql_test_env& e) { + return do_with_some_data_in_thread({"cf1", "cf2", "cf3", "cf4"}, [] (cql_test_env& e) { e.execute_cql("DROP TABLE ks.cf1;").get(); auto details = e.local_db().get_snapshot_details().get(); @@ -765,23 +768,20 @@ SEASTAR_TEST_CASE(snapshot_list_contains_dropped_tables) { BOOST_REQUIRE_EQUAL(sd.total, sd.live); } } - - return make_ready_future<>(); }); } SEASTAR_TEST_CASE(snapshot_list_inexistent) { - return do_with_some_data({"cf"}, [] (cql_test_env& e) { + return do_with_some_data_in_thread({"cf"}, [] (cql_test_env& e) { auto& cf = e.local_db().find_column_family("ks", "cf"); auto details = cf.get_snapshot_details().get(); BOOST_REQUIRE_EQUAL(details.size(), 0); - return make_ready_future<>(); }); } SEASTAR_TEST_CASE(clear_snapshot) { - return do_with_some_data({"cf"}, [] (cql_test_env& e) { + return do_with_some_data_in_thread({"cf"}, [] (cql_test_env& e) { take_snapshot(e).get(); auto& cf = e.local_db().find_column_family("ks", "cf"); @@ -796,7 +796,6 @@ SEASTAR_TEST_CASE(clear_snapshot) { count = 0; BOOST_REQUIRE_EQUAL(fs::exists(table_dir(cf) / sstables::snapshots_dir / "test"), false); - return make_ready_future<>(); }); } @@ -809,7 +808,7 @@ SEASTAR_TEST_CASE(clear_multiple_snapshots) { return format("test-snapshot-{}", idx); }; - co_await do_with_some_data({table_name}, [&] (cql_test_env& e) { + co_await do_with_some_data_in_thread({table_name}, [&] (cql_test_env& e) { auto& t = e.local_db().find_column_family(ks_name, table_name); auto tdir = table_dir(t); auto snapshots_dir = tdir / sstables::snapshots_dir; @@ -868,21 +867,18 @@ SEASTAR_TEST_CASE(clear_multiple_snapshots) { // after all snapshots had been cleared, // the dropped table directory is expected to be removed. BOOST_REQUIRE_EQUAL(fs::exists(tdir), false); - - return make_ready_future<>(); }); } SEASTAR_TEST_CASE(clear_nonexistent_snapshot) { // no crashes, no exceptions - return do_with_some_data({"cf"}, [] (cql_test_env& e) { + return do_with_some_data_in_thread({"cf"}, [] (cql_test_env& e) { e.local_db().clear_snapshot("test", {"ks"}, "").get(); - return make_ready_future<>(); }); } SEASTAR_TEST_CASE(test_snapshot_ctl_details) { - return do_with_some_data({"cf"}, [] (cql_test_env& e) { + return do_with_some_data_in_thread({"cf"}, [] (cql_test_env& e) { sharded sc; sc.start(std::ref(e.db()), std::ref(e.get_task_manager()), std::ref(e.get_sstorage_manager()), db::snapshot_ctl::config{}).get(); auto stop_sc = deferred_stop(sc); @@ -926,13 +922,11 @@ SEASTAR_TEST_CASE(test_snapshot_ctl_details) { BOOST_REQUIRE_EQUAL(sc_sd_post_deletion.cf, "cf"); BOOST_REQUIRE_EQUAL(sc_sd_post_deletion.details.live, sd_post_deletion.live); BOOST_REQUIRE_EQUAL(sc_sd_post_deletion.details.total, sd_post_deletion.total); - - return make_ready_future<>(); }); } SEASTAR_TEST_CASE(test_snapshot_ctl_true_snapshots_size) { - return do_with_some_data({"cf"}, [] (cql_test_env& e) { + return do_with_some_data_in_thread({"cf"}, [] (cql_test_env& e) { sharded sc; sc.start(std::ref(e.db()), std::ref(e.get_task_manager()), std::ref(e.get_sstorage_manager()), db::snapshot_ctl::config{}).get(); auto stop_sc = deferred_stop(sc); @@ -962,8 +956,6 @@ SEASTAR_TEST_CASE(test_snapshot_ctl_true_snapshots_size) { sc_live_size = sc.local().true_snapshots_size().get(); BOOST_REQUIRE_EQUAL(sc_live_size, sd_post_deletion.live); - - return make_ready_future<>(); }); }