wangyong9999 commented on code in PR #282:
URL: https://github.com/apache/paimon-cpp/pull/282#discussion_r3932570934
##########
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:
`add_test` registers the whole `paimon-common-test` binary, so every
`DefaultExecutorTest.*` (and whatever ran before it) shares this process. A
worker joined by the previous test can still show up in `/proc/self/task` when
`threads_before` is read at line 62 and be gone by here, and the exact `==
threads_before + 4` / `== threads_before` checks then fail on an unrelated
off-by-one. Capture the baseline the same way the tail does (poll until two
reads agree), and relax the comparisons to `>= threads_before + 4` after the
tasks and `<= threads_before` after reset; that still proves "no thread at
construction, four after the first task, none after destruction" without
depending on other tests being quiet.
--
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]