From 6230cc88b6b3902902c58e4331ca6273e71b8e2e Mon Sep 17 00:00:00 2001 From: Qi Wang Date: Thu, 6 Jan 2022 17:46:55 -0800 Subject: [PATCH] Add background thread sleep retry in test/unit/hpa_background_thread Under high concurrency / heavy test load (e.g. using run_tests.sh), the background thread may not get scheduled for a longer period of time. Retry 100 times max before bailing out. --- test/unit/hpa_background_thread.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/test/unit/hpa_background_thread.c b/test/unit/hpa_background_thread.c index ad7bac4b..81c25612 100644 --- a/test/unit/hpa_background_thread.c +++ b/test/unit/hpa_background_thread.c @@ -4,8 +4,8 @@ static void sleep_for_background_thread_interval() { /* - * The sleep interval set in our .sh file is 50ms. So it should - * definitely run if we sleep for for times that. + * The sleep interval set in our .sh file is 50ms. So it likely will + * run if we sleep for four times that. */ sleep_ns(200 * 1000 * 1000); } @@ -117,10 +117,18 @@ expect_purging(unsigned arena_ind, bool expect_deferred) { } } expect_b_eq(expect_deferred, observed_dirty_page, ""); - if (expect_deferred) { + + /* + * Under high concurrency / heavy test load (e.g. using run_test.sh), + * the background thread may not get scheduled for a longer period of + * time. Retry 100 times max before bailing out. + */ + unsigned retry = 0; + while ((empty_ndirty = get_empty_ndirty(arena_ind)) > 0 && + expect_deferred && (retry++ < 100)) { sleep_for_background_thread_interval(); } - empty_ndirty = get_empty_ndirty(arena_ind); + expect_zu_eq(0, empty_ndirty, "Should have seen a background purge"); }