From ec4069246deb79110314700c9a5b945b1d8034f2 Mon Sep 17 00:00:00 2001 From: Benny Halevy Date: Sun, 21 Dec 2025 17:55:21 +0200 Subject: [PATCH] test: database_test: do_with_some_data_in_thread: accept void callback function Many test cases already assume `func` is being called a seastar thread and although the function they pass returns a (ready) future, it serves no purpose other than to conform to the interface. Signed-off-by: Benny Halevy --- test/boost/database_test.cc | 47 +++++++++++++++---------------------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/test/boost/database_test.cc b/test/boost/database_test.cc index 97150151f2..3f69c23f3a 100644 --- a/test/boost/database_test.cc +++ b/test/boost/database_test.cc @@ -568,7 +568,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) { @@ -607,11 +608,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(cql_test_env& e, sstring ks_name = "ks", sstring cf_name = "cf", sstring snapshot_name = "test", bool skip_flush = false) { try { auto uuid = e.db().local().find_uuid(ks_name, cf_name); @@ -633,7 +640,7 @@ future> collect_files(fs::path path) { } 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(); auto& cf = e.local_db().find_column_family("ks", table_name); @@ -650,8 +657,6 @@ static future<> snapshot_works(const std::string& table_name) { in_table_dir.insert("schema.cql"); // all files were copied and manifest was generated BOOST_REQUIRE_EQUAL(in_table_dir, in_snapshot_dir); - - return make_ready_future<>(); }, true); } @@ -668,7 +673,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, "ks", "cf", "test", true /* skip_flush */).get(); auto& cf = e.local_db().find_column_family("ks", "cf"); @@ -678,12 +683,11 @@ SEASTAR_TEST_CASE(snapshot_skip_flush_works) { BOOST_REQUIRE(in_table_dir.empty()); auto in_snapshot_dir = collect_files(table_dir(cf) / sstables::snapshots_dir / "test").get(); BOOST_REQUIRE_EQUAL(in_snapshot_dir, std::set({"manifest.json", "schema.cql"})); - 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(); @@ -703,13 +707,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(); @@ -744,23 +746,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"); @@ -771,7 +770,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<>(); }); } @@ -784,7 +782,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; @@ -839,21 +837,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); @@ -897,13 +892,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); @@ -933,8 +926,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<>(); }); }