| 37 | }; |
| 38 | |
| 39 | TEST_F(ThreadPoolTest, testScheduleWithId) { |
| 40 | _tp = make_shared<async_simple::util::ThreadPool>(2); |
| 41 | std::thread::id id1, id2, id3; |
| 42 | std::atomic<bool> done1(false), done2(false), done3(false), done4(false); |
| 43 | std::function<void()> f1 = [this, &done1, &id1]() { |
| 44 | id1 = std::this_thread::get_id(); |
| 45 | ASSERT_EQ(_tp->getCurrentId(), 0); |
| 46 | done1 = true; |
| 47 | }; |
| 48 | std::function<void()> f2 = [this, &done2, &id2]() { |
| 49 | id2 = std::this_thread::get_id(); |
| 50 | ASSERT_EQ(_tp->getCurrentId(), 0); |
| 51 | done2 = true; |
| 52 | }; |
| 53 | std::function<void()> f3 = [this, &done3, &id3]() { |
| 54 | id3 = std::this_thread::get_id(); |
| 55 | ASSERT_EQ(_tp->getCurrentId(), 1); |
| 56 | done3 = true; |
| 57 | }; |
| 58 | std::function<void()> f4 = [&done4]() { done4 = true; }; |
| 59 | _tp->scheduleById(std::move(f1), 0); |
| 60 | _tp->scheduleById(std::move(f2), 0); |
| 61 | _tp->scheduleById(std::move(f3), 1); |
| 62 | _tp->scheduleById(std::move(f4)); |
| 63 | |
| 64 | while (!done1.load() || !done2.load() || !done3.load() || !done4.load()) |
| 65 | ; |
| 66 | ASSERT_TRUE(id1 == id2) << id1 << " " << id2; |
| 67 | ASSERT_TRUE(id1 != id3) << id1 << " " << id3; |
| 68 | ASSERT_TRUE(_tp->getCurrentId() == -1); |
| 69 | } |
| 70 | |
| 71 | using namespace async_simple::util; |
| 72 |
nothing calls this directly
no test coverage detected