From cad7af3ec2d6fd8e1d70c3575088d0edab4bbe41 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 2 Feb 2021 05:31:48 +0000 Subject: Properly track execution of BucketTasks and provide sync() and orderly shutdown. --- .../filestorage/filestormanagertest.cpp | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'storage/src/tests/persistence/filestorage/filestormanagertest.cpp') diff --git a/storage/src/tests/persistence/filestorage/filestormanagertest.cpp b/storage/src/tests/persistence/filestorage/filestormanagertest.cpp index acccbb8b9b9..5a7a4394da4 100644 --- a/storage/src/tests/persistence/filestorage/filestormanagertest.cpp +++ b/storage/src/tests/persistence/filestorage/filestormanagertest.cpp @@ -456,6 +456,40 @@ TEST_F(FileStorManagerTest, running_task_against_existing_bucket_works) { EXPECT_EQ(1, numInvocations); } +TEST_F(FileStorManagerTest, sync_waits_for_already_started_tasks) { + TestFileStorComponents c(*this); + + setClusterState("storage:3 distributor:3"); + EXPECT_TRUE(getDummyPersistence().getClusterState().nodeUp()); + + auto executor = getDummyPersistence().get_bucket_executor(); + ASSERT_TRUE(executor); + + spi::Bucket b1 = makeSpiBucket(document::BucketId(1)); + + createBucket(b1.getBucketId()); + + std::atomic numInvocations(0); + vespalib::Gate gate; + auto response = executor->execute(b1, spi::makeBucketTask([&numInvocations, &gate](const spi::Bucket &, std::shared_ptr) { + gate.await(); + numInvocations++; + })); + EXPECT_FALSE(response); + EXPECT_EQ(0, numInvocations); + std::atomic syncComplete(false); + std::thread thread([&syncComplete, &executor]() { + executor->sync(); + syncComplete = true; + }); + std::this_thread::sleep_for(100us); + EXPECT_FALSE(syncComplete); + gate.countDown(); + thread.join(); + EXPECT_TRUE(syncComplete); + EXPECT_EQ(1, numInvocations); +} + TEST_F(FileStorManagerTest, state_change) { TestFileStorComponents c(*this); -- cgit v1.2.3