| 54 | } |
| 55 | |
| 56 | TEST(BthreadOnceTest, once) { |
| 57 | bthread_t bid; |
| 58 | ASSERT_EQ(0, bthread_start_background( |
| 59 | &bid, NULL, first_bthread_once_task, NULL)); |
| 60 | while (!g_bthread_once_started) { |
| 61 | bthread_usleep(1000); |
| 62 | } |
| 63 | ASSERT_NE(nullptr, bthread::g_task_control); |
| 64 | int concurrency = bthread::g_task_control->concurrency(); |
| 65 | LOG(INFO) << "concurrency: " << concurrency; |
| 66 | ASSERT_GT(concurrency, 0); |
| 67 | std::vector<bthread_t> bids(concurrency * 100); |
| 68 | for (auto& id : bids) { |
| 69 | ASSERT_EQ(0, bthread_start_background( |
| 70 | &id, NULL, other_bthread_once_task, NULL)); |
| 71 | } |
| 72 | bthread_once_task(); |
| 73 | |
| 74 | for (auto& id : bids) { |
| 75 | bthread_join(id, NULL); |
| 76 | } |
| 77 | bthread_join(bid, NULL); |
| 78 | } |
| 79 | |
| 80 | bool g_bthread_started = false; |
| 81 | butil::atomic<int> g_bthread_singleton_count(0); |
nothing calls this directly
no test coverage detected