| 41 | } |
| 42 | |
| 43 | TEST(ThreadPoolTest, BasicTest) { |
| 44 | const int OFFERED_RANGE = 10000; |
| 45 | for (int i = 0; i < NUM_THREADS; ++i) { |
| 46 | thread_counters[i] = 0; |
| 47 | } |
| 48 | |
| 49 | ThreadPool<int> thread_pool("thread-pool", "worker", 5, 250, Count); |
| 50 | ASSERT_OK(thread_pool.Init()); |
| 51 | for (int i = 0; i <= OFFERED_RANGE; ++i) { |
| 52 | ASSERT_TRUE(thread_pool.Offer(i)); |
| 53 | } |
| 54 | |
| 55 | thread_pool.DrainAndShutdown(); |
| 56 | |
| 57 | // Check that Offer() after Shutdown() will return false |
| 58 | ASSERT_FALSE(thread_pool.Offer(-1)); |
| 59 | EXPECT_EQ(0, thread_pool.GetQueueSize()); |
| 60 | |
| 61 | int expected_count = (OFFERED_RANGE * (OFFERED_RANGE + 1)) / 2; |
| 62 | int count = 0; |
| 63 | for (int i = 0; i < NUM_THREADS; ++i) { |
| 64 | lock_guard<mutex> l(thread_mutexes[i]); |
| 65 | LOG(INFO) << "Counter " << i << ": " << thread_counters[i]; |
| 66 | count += thread_counters[i]; |
| 67 | } |
| 68 | |
| 69 | EXPECT_EQ(expected_count, count); |
| 70 | } |
| 71 | |
| 72 | class SleepWorkItem : public SynchronousWorkItem { |
| 73 | public: |
nothing calls this directly
no test coverage detected