예제 #1
0
파일: test.cpp 프로젝트: mlove-au/utils
TEST(AsyncQueue, TestConsumeAllEmptiesQueue) 
{
    AsyncQueue<int> q;

    q.push(1);
    q.push(2);
    ASSERT_EQ(2, q.size());
    q.consumeAll( [](int i) {});
    EXPECT_EQ(0, q.size());
}
예제 #2
0
파일: test.cpp 프로젝트: mlove-au/utils
TEST(AsyncQueue, TestEmptyQueueBlocksConsumeAllUntilPushed)
{
    AsyncQueue<int> q;

    // run a separate thread to count how many items are consumed from the queue.	
    std::atomic<int> calls = 0;	
    std::thread t1([&] ()
    {	
        q.consumeAll([&calls] (int i)
        { 
            calls++; 
        });
    });

    // wait for 250 ms. Should be enougth to ensure no items have been consumed by the other thread
    std::this_thread::sleep_for(std::chrono::milliseconds(250));
    ASSERT_EQ(0, calls);	

    // push something onto the queue and wait for consumer t1 to complete.
    q.push(1); 
    t1.join();
    ASSERT_EQ(1, calls);
    ASSERT_EQ(0, q.size());
}