This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.1 by this push:
new 5c964a0ab28 branch-4.1: [test](cloud) Make SyncExecutor delay test
deterministic (#68145) (#68586)
5c964a0ab28 is described below
commit 5c964a0ab283c48c5291795227e963919d1e94a8
Author: Gavin Chou <[email protected]>
AuthorDate: Tue Sep 29 09:34:31 2026 +0800
branch-4.1: [test](cloud) Make SyncExecutor delay test deterministic
(#68145) (#68586)
### What problem does this PR solve?
Issue Number: None
Related PR: #68145
Problem Summary:
Backport #68145 to branch-4.1. Replace timing-based sleeps in
UtilTest.delay with countdown events so the normal tasks have entered
their callbacks before the cancellation task returns.
The cherry-pick conflicted only in the include block because master
contains unrelated AWS/S3 additions. The resolution keeps the branch-4.1
file structure and brings over only the deterministic synchronization
change.
### Release note
None
### Check List (For Author)
- Test: Unit Test
- local_to_dev run cloud-ut --run --filter=util_test:UtilTest.delay
- UtilTest.delay repeated 1000 times under ASAN
- Behavior changed: No
- Does this need documentation: No
---
cloud/test/util_test.cpp | 85 +++++++++++++++++++++++++-----------------------
1 file changed, 45 insertions(+), 40 deletions(-)
diff --git a/cloud/test/util_test.cpp b/cloud/test/util_test.cpp
index 435feb6e0c3..0b20ae08171 100644
--- a/cloud/test/util_test.cpp
+++ b/cloud/test/util_test.cpp
@@ -17,11 +17,11 @@
#include "cpp/util.h"
-#include <chrono>
+#include <bthread/countdown_event.h>
+
#include <stdexcept>
#include <string>
#include <string_view>
-#include <thread>
#include <tuple>
#include <vector>
@@ -138,44 +138,49 @@ TEST(UtilTest, stage_wrapper) {
ASSERT_EQ(0, f());
}
+template <typename T>
+void test_cancel_after_tasks_started(T normal_value, T cancel_value,
+ std::function<bool(const T&)> is_cancel) {
+ auto pool = std::make_shared<SimpleThreadPool>(3);
+ pool->start();
+
+ bthread::CountdownEvent normal_tasks_started(2);
+ bthread::CountdownEvent cancellation_observed(1);
+ SyncExecutor<T> sync_executor(pool, "cancel after tasks started",
[&](const T& value) {
+ bool cancelled = is_cancel(value);
+ if (cancelled) {
+ cancellation_observed.signal();
+ }
+ return cancelled;
+ });
+
+ auto normal_task = [&, normal_value]() {
+ normal_tasks_started.signal();
+ cancellation_observed.wait();
+ return normal_value;
+ };
+ auto cancel_task = [&, cancel_value]() {
+ normal_tasks_started.wait();
+ return cancel_value;
+ };
+
+ sync_executor.add(normal_task);
+ sync_executor.add(normal_task);
+ sync_executor.add(cancel_task);
+
+ bool finished = true;
+ auto results = sync_executor.when_all(&finished);
+ ASSERT_FALSE(finished);
+ ASSERT_EQ(3, results.size());
+ EXPECT_EQ(normal_value, results[0]);
+ EXPECT_EQ(normal_value, results[1]);
+ EXPECT_EQ(cancel_value, results[2]);
+}
+
TEST(UtilTest, delay) {
- auto s3_producer_pool =
std::make_shared<SimpleThreadPool>(config::recycle_pool_parallelism);
- s3_producer_pool->start();
- // test normal execute
- {
- SyncExecutor<int> sync_executor(s3_producer_pool, "normal test",
- [](int k) { return k == -1; });
- auto f1 = []() { return -1; };
- auto f2 = []() {
- std::this_thread::sleep_for(std::chrono::seconds(1));
- return 1;
- };
- sync_executor.add(f2);
- sync_executor.add(f2);
- sync_executor.add(f1);
- bool finished = true;
- std::vector<int> res = sync_executor.when_all(&finished);
- ASSERT_EQ(finished, false);
- ASSERT_EQ(3, res.size());
- }
- // test normal execute
- {
- SyncExecutor<std::string_view> sync_executor(
- s3_producer_pool, "normal test",
- [](const std::string_view k) { return k.empty(); });
- auto f1 = []() { return ""; };
- auto f2 = []() {
- std::this_thread::sleep_for(std::chrono::seconds(1));
- return "fake";
- };
- sync_executor.add(f2);
- sync_executor.add(f2);
- sync_executor.add(f1);
- bool finished = true;
- auto res = sync_executor.when_all(&finished);
- ASSERT_EQ(finished, false);
- ASSERT_EQ(3, res.size());
- }
+ test_cancel_after_tasks_started<int>(1, -1, [](const int& value) { return
value == -1; });
+ test_cancel_after_tasks_started<std::string_view>(
+ "fake", "", [](const std::string_view value) { return
value.empty(); });
}
TEST(UtilTest, normal) {
@@ -450,4 +455,4 @@ TEST(UtilTest, test_long_normalize_http_uri) {
}
EXPECT_EQ(doris::normalize_http_uri(longPath), expected);
-}
\ No newline at end of file
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]