Skip to content

Commit 934f6dc

Browse files
Akshit Khuranafacebook-github-bot
Akshit Khurana
authored andcommitted
Fix pthreadpool guard test (pytorch#58977)
Summary: Pull Request resolved: pytorch#58977 * Test was flaky as part of it ran async * Remove async part to test only the functionality added Test Plan: regular test: `buck test mode/dev //caffe2/aten:test_thread_pool_guard -- --exact 'caffe2/aten:test_thread_pool_guard - TestThreadPoolGuard.TestRunWithGuard' --run-disabled` stress test: `buck test mode/dev //caffe2/aten:test_thread_pool_guard -- --exact 'caffe2/aten:test_thread_pool_guard - TestThreadPoolGuard.TestRunWithGuard' --run-disabled --jobs 18 --stress-runs 10 --record-results` Reviewed By: kimishpatel Differential Revision: D28703064 fbshipit-source-id: be19da3f42f44288afc726bdb2f40342eee26e01
1 parent e89b150 commit 934f6dc

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

aten/src/ATen/test/test_thread_pool_guard.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,19 @@ TEST(TestThreadPoolGuard, TestThreadPoolGuard) {
3333
TEST(TestThreadPoolGuard, TestRunWithGuard) {
3434
const std::vector<int64_t> array = {1, 2, 3};
3535

36-
// Run via pthreadpool_parallelize_1d
37-
int64_t outer = 0;
38-
auto fn1 = [&array, &outer](const size_t task_id) {
39-
outer += array[task_id];
40-
};
4136
auto pool = caffe2::pthreadpool();
42-
pool->run(fn1, 3);
43-
4437
int64_t inner = 0;
4538
{
4639
// Run on same thread
4740
caffe2::_NoPThreadPoolGuard g1;
48-
auto fn2 = [&array, &inner](const size_t task_id) {
41+
auto fn = [&array, &inner](const size_t task_id) {
4942
inner += array[task_id];
5043
};
51-
pool->run(fn2, 3);
44+
pool->run(fn, 3);
5245

5346
// confirm the guard is on
54-
auto threadpool_ptr1 = caffe2::pthreadpool_();
55-
ASSERT_EQ(threadpool_ptr1, nullptr);
47+
auto threadpool_ptr = caffe2::pthreadpool_();
48+
ASSERT_EQ(threadpool_ptr, nullptr);
5649
}
57-
ASSERT_NE(outer, 0);
58-
ASSERT_NE(inner, 0);
59-
ASSERT_EQ(outer, 6);
6050
ASSERT_EQ(inner, 6);
6151
}

0 commit comments

Comments
 (0)