qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/1] test-thread-pool: Fix occasional test fail


From: Hiroki Narukawa
Subject: [PATCH 1/1] test-thread-pool: Fix occasional test fail
Date: Tue, 17 May 2022 17:29:54 +0900

I encountered occasional test fail in some of build environment.

Then I found that adding g_usleep(20000); soon after
> if (qatomic_cmpxchg(&data[i].n, 0, 4) == 0) {
in do_test_cancel() in tests/unit/test-thread-pool.c reproduces.

In this test, cancel operation is not done atomically.

If data.n is set to 4, long_cb() finishes immediately, bdrv_aio_cancel()
is called after that, the job is done and
> g_assert_cmpint(data[i].ret, ==, -ECANCELED);
at the case data[i].n == 4 fails.

This patch makes this rare situation to pass correctly.

Signed-off-by: Hiroki Narukawa <hnarukaw@yahoo-corp.jp>
---
 tests/unit/test-thread-pool.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/tests/unit/test-thread-pool.c b/tests/unit/test-thread-pool.c
index 6020e65d69..c29afe2bef 100644
--- a/tests/unit/test-thread-pool.c
+++ b/tests/unit/test-thread-pool.c
@@ -29,8 +29,12 @@ static int long_cb(void *opaque)
     if (qatomic_cmpxchg(&data->n, 0, 1) == 0) {
         g_usleep(2000000);
         qatomic_or(&data->n, 2);
+        return 0;
     }
-    return 0;
+    /* In rare cases that reach here, this job will be done,
+     * but should be treated as canceled.
+     */
+    return -ECANCELED;
 }
 
 static void done_cb(void *opaque, int ret)
-- 
2.17.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]