@@ -336,70 +336,78 @@ TEST_F(BucketCacheFixtureMarker1, ListMarker1)
336336
337337class BucketCacheFixtureInotify1 : public testing ::Test, protected BucketCacheFixtureBase {
338338protected:
339- static void SetUpTestSuite () {
340- int nfiles = 20 ;
341- std::string bucket{" inotify1" };
339+ void SetUp () override {
340+ sf::path tp{sf::path{bucket_root} / " inotify1" };
341+ sf::remove_all (tp);
342+ sf::create_directory (tp);
343+ bucket_cache = new BucketCache{&sal_driver, bucket_root, database_root};
344+ }
342345
343- sf::path tp{sf::path{bucket_root} / bucket};
346+ void TearDown () override {
347+ delete bucket_cache;
348+ bucket_cache = nullptr ;
349+ sf::path tp{sf::path{bucket_root} / " inotify1" };
344350 sf::remove_all (tp);
345351 sf::create_directory (tp);
352+ }
353+
354+ static void create_files (std::string bucket, std::string fbase, int nfiles) {
355+ sf::path tp{sf::path{bucket_root} / " inotify1" };
346356
347- std::string fbase{" file_" };
348357 for (int ix = 0 ; ix < nfiles; ++ix) {
349358 sf::path ttp{tp / fmt::format (" {}{}" , fbase, ix)};
350359 std::ofstream ofs (ttp);
351360 ofs << " data for " << ttp << std::endl;
352361 ofs.close ();
362+ ASSERT_TRUE (sf::exists (ttp));
353363 }
354- bucket_cache = new BucketCache{&sal_driver, bucket_root, database_root};
355364 }
356365
357- static void TearDownTestSuite () {
358- delete bucket_cache;
359- bucket_cache = nullptr ;
366+ static void remove_files (std::string bucket, std::string fbase, int fstart, int fend) {
367+ sf::path tp{sf::path{bucket_root} / " inotify1" };
368+ for (int ix = fstart; ix < fend; ++ix) {
369+ sf::path ttp{tp / fmt::format (" {}{}" , fbase, ix)};
370+ sf::remove (ttp);
371+ ASSERT_FALSE (sf::exists (ttp));
372+ }
360373 }
374+
361375};
362376
363377TEST_F (BucketCacheFixtureInotify1, ListInotify1)
364378{
365379 std::string bucket{" inotify1" };
366380 std::string marker{" " };
367381 std::vector<std::string> names;
382+ int nfiles{20 };
368383
369384 auto f = [&](const rgw_bucket_dir_entry& bde) -> int {
370385 // std::cout << fmt::format("called back with {}", bde.key.name) << std::endl;
371386 names.push_back (bde.key .name );
372387 return true ;
373388 };
374389
390+ create_files (bucket, " file_" , nfiles);
391+
375392 MockSalBucket sb{bucket};
376393
377394 (void ) bucket_cache->list_bucket (dpp, null_yield, &sb, marker, f);
378- ASSERT_EQ (names.size (), 20 );
395+ ASSERT_EQ (names.size (), nfiles );
379396} /* ListInotify1 */
380397
381398TEST_F (BucketCacheFixtureInotify1, UpdateInotify1)
382399{
383- int nfiles = 10 ;
384400 std::string bucket{" inotify1" };
385401
386402 sf::path tp{sf::path{bucket_root} / bucket};
387403
404+ create_files (bucket, " file_" , 20 );
405+
388406 /* add some */
389- std::string fbase{" upfile_" };
390- for (int ix = 0 ; ix < nfiles; ++ix) {
391- sf::path ttp{tp / fmt::format (" {}{}" , fbase, ix)};
392- std::ofstream ofs (ttp);
393- ofs << " data for " << ttp << std::endl;
394- ofs.close ();
395- }
407+ create_files (bucket, " upfile_" , 10 );
396408
397409 /* remove some */
398- fbase = " file_" ;
399- for (int ix = 5 ; ix < 10 ; ++ix) {
400- sf::path ttp{tp / fmt::format (" {}{}" , fbase, ix)};
401- sf::remove (ttp);
402- }
410+ remove_files (bucket, " file_" , 5 , 10 );
403411} /* SetupInotify1 */
404412
405413TEST_F (BucketCacheFixtureInotify1, List2Inotify1)
@@ -415,35 +423,56 @@ TEST_F(BucketCacheFixtureInotify1, List2Inotify1)
415423 return true ;
416424 };
417425
426+ create_files (bucket, " file_" , 20 );
427+
418428 MockSalBucket sb{bucket};
419429
420430 /* Do a timed backoff up to ~20 seconds to pass on CI */
421431 while (timeout < 16000 ) {
432+ names.clear ();
422433 (void )bucket_cache->list_bucket (dpp, null_yield, &sb, marker, f);
423- if (names.size () == 25 )
434+ if (names.size () == 20 )
424435 break ;
425- std::cout << fmt::format (" waiting for {}ms for cache sync" , timeout) << std::endl;
436+ std::cout << fmt::format (" waiting for {}ms for cache sync size={} " , timeout, names. size () ) << std::endl;
426437 std::this_thread::sleep_for (1000ms);
427438 timeout *= 2 ;
428- names.clear ();
429439 }
430- ASSERT_EQ (names.size (), 25 );
440+ ASSERT_EQ (names.size (), 20 );
431441
432- /* check these */
442+ /* Add some */
433443 sf::path tp{sf::path{bucket_root} / bucket};
444+ timeout = 50 ;
445+
446+ create_files (bucket, " upfile_" , 10 );
434447
435- std::string fbase{" upfile_" };
436- for (int ix = 0 ; ix < 10 ; ++ix) {
437- sf::path ttp{tp / fmt::format (" {}{}" , fbase, ix)};
438- ASSERT_TRUE (sf::exists (ttp));
448+ /* Do a timed backoff up to ~20 seconds to pass on CI */
449+ while (timeout < 16000 ) {
450+ names.clear ();
451+ (void )bucket_cache->list_bucket (dpp, null_yield, &sb, marker, f);
452+ if (names.size () == 30 )
453+ break ;
454+ std::cout << fmt::format (" waiting for {}ms for cache sync size={}" , timeout, names.size ()) << std::endl;
455+ std::this_thread::sleep_for (1000ms);
456+ timeout *= 2 ;
439457 }
458+ ASSERT_EQ (names.size (), 30 );
440459
441460 /* remove some */
442- fbase = " file_" ;
443- for (int ix = 5 ; ix < 10 ; ++ix) {
444- sf::path ttp{tp / fmt::format (" {}{}" , fbase, ix)};
445- ASSERT_FALSE (sf::exists (ttp));
461+ timeout = 50 ;
462+
463+ remove_files (bucket, " file_" , 5 , 10 );
464+
465+ /* Do a timed backoff up to ~20 seconds to pass on CI */
466+ while (timeout < 16000 ) {
467+ names.clear ();
468+ (void )bucket_cache->list_bucket (dpp, null_yield, &sb, marker, f);
469+ if (names.size () == 25 )
470+ break ;
471+ std::cout << fmt::format (" waiting for {}ms for cache sync size={}" , timeout, names.size ()) << std::endl;
472+ std::this_thread::sleep_for (1000ms);
473+ timeout *= 2 ;
446474 }
475+ ASSERT_EQ (names.size (), 25 );
447476} /* List2Inotify1 */
448477
449478int main (int argc, char *argv[])
0 commit comments