Don't assume visitor threads immediately destroy visitors
using document::test::makeDocumentBucket;
using document::test::makeBucketSpace;
using documentapi::Priority;
+using namespace std::chrono_literals;
namespace storage {
namespace {
@@ -274,7 +275,7 @@ VisitorManagerTest::getSession(uint32_t n)
throw vespalib::IllegalStateException(
"Timed out waiting for visitor session", VESPA_STRLOC);
}
- std::this_thread::sleep_for(std::chrono::milliseconds(10));
+ std::this_thread::sleep_for(10ms);
}
throw std::logic_error("unreachable");
}
@@ -745,9 +746,11 @@ VisitorManagerTest::testVisitorCleanup()
// Should get a reply for the visitor.
verifyCreateVisitorReply(api::ReturnCode::INTERNAL_FAILURE);
- // 2 pending
-
- CPPUNIT_ASSERT_EQUAL(2u, _manager->getActiveVisitorCount());
+ // Wait until there are 2 pending. Visitor threads might not have completed
+ // cleanup of existing visitors yet.
+ while (_manager->getActiveVisitorCount() != 2) {
+ std::this_thread::sleep_for(10ms);
+ }
// Start a bunch of more visitors
for (uint32_t i=0; i<10; ++i) {
@@ -774,15 +777,10 @@ VisitorManagerTest::testVisitorCleanup()
CPPUNIT_ASSERT_EQUAL(api::ReturnCode::BUSY, reply->getResult().getResult());
}
- // 4 still pending, need to clean up our stuff before tearing down.
- CPPUNIT_ASSERT_EQUAL(4u, _manager->getActiveVisitorCount());
-
for (uint32_t i = 0; i < 4; ++i) {
getMessagesAndReply(1, getSession(i + 2), docs, docIds);
verifyCreateVisitorReply(api::ReturnCode::OK);
}
-
- CPPUNIT_ASSERT_EQUAL(0u, _manager->getActiveVisitorCount());
}
void
@@ -957,7 +955,6 @@ VisitorManagerTest::testPrioritizedVisitorQueing()
for (auto session : pending_sessions) {
finishAndWaitForVisitorSessionCompletion(session);
}
- CPPUNIT_ASSERT_EQUAL(0u, _manager->getActiveVisitorCount());
}
void VisitorManagerTest::finishAndWaitForVisitorSessionCompletion(uint32_t sessionIndex) {
@@ -1071,7 +1068,6 @@ VisitorManagerTest::testPrioritizedMaxConcurrentVisitors() {
CPPUNIT_ASSERT(finishedVisitors.find(ids[11]) != finishedVisitors.end());
CPPUNIT_ASSERT(finishedVisitors.find(ids[14]) != finishedVisitors.end());
- CPPUNIT_ASSERT_EQUAL(0u, _manager->getActiveVisitorCount());
}
void
