wangyong9999 commented on code in PR #282:
URL: https://github.com/apache/paimon-cpp/pull/282#discussion_r3932663660
##########
src/paimon/common/executor/default_executor_test.cpp:
##########
@@ -35,6 +39,72 @@
namespace paimon::test {
+#ifdef __linux__
+// Number of threads of the current process according to /proc.
+int32_t CountProcessThreads() {
+ DIR* dir = opendir("/proc/self/task");
+ if (dir == nullptr) {
+ return -1;
+ }
+ int32_t count = 0;
+ while (struct dirent* entry = readdir(dir)) {
+ if (entry->d_name[0] != '.') {
+ ++count;
+ }
+ }
+ closedir(dir);
+ return count;
+}
+#endif
+
+TEST(DefaultExecutorTest, TestWorkersStartOnFirstTask) {
+#ifdef __linux__
+ int32_t threads_before = CountProcessThreads();
+ ASSERT_GT(threads_before, 0);
+#endif
+ ASSERT_OK_AND_ASSIGN(std::unique_ptr<Executor> executor,
CreateDefaultExecutor(4));
+ ASSERT_EQ(4u, executor->GetThreadNum());
+#ifdef __linux__
+ // Constructing the executor does not spawn any worker thread.
+ ASSERT_EQ(threads_before, CountProcessThreads());
+#endif
+
+ std::atomic<int64_t> sum = {0};
+ std::vector<std::future<void>> futures;
+ for (int32_t index = 0; index < 8; ++index) {
+ futures.push_back(Via(executor.get(), [&sum]() { sum++; }));
+ }
+ Wait(futures);
+ ASSERT_EQ(8, sum.load());
+#ifdef __linux__
+ ASSERT_EQ(threads_before + 4, CountProcessThreads());
Review Comment:
Good catch, and it is not hypothetical: with the exact comparisons the first
local run of this test failed on precisely that window (a worker joined by the
previous executor was still listed in `/proc/self/task`). Addressed in c2d25dc7:
- the baseline is now taken with `StableProcessThreadCount()`, which returns
only once two consecutive reads agree;
- the checks are `<= threads_before` after construction, `>= threads_before
+ 4` after the first tasks, and `<= threads_before` after destruction (the last
one polls briefly, as before).
Validated by running the whole `paimon-common-test` binary, the same way
`add_test` registers it, plus three filtered `DefaultExecutorTest.*` runs.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]