MCPcopy Create free account
hub / github.com/apache/brpc / test_cancel

Function test_cancel

test/bthread_execution_queue_unittest.cpp:646–674  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

644}
645
646void test_cancel(bool use_pthread) {
647 bthread::ExecutionQueueId<LongIntTask> queue_id = { 0 }; // to suppress warnings
648 bthread::ExecutionQueueOptions options;
649 options.use_pthread = use_pthread;
650 if (options.use_pthread) {
651 LOG(INFO) << "================ pthread ================";
652 } else {
653 LOG(INFO) << "================ bthread ================";
654 }
655 int64_t result = 0;
656 ASSERT_EQ(0, bthread::execution_queue_start(&queue_id, &options,
657 add_with_suspend2, &result));
658 g_suspending = false;
659 bthread::TaskHandle handle0;
660 ASSERT_EQ(0, bthread::execution_queue_execute(queue_id, -100, NULL, &handle0));
661 while (!g_suspending) {
662 usleep(10);
663 }
664 ASSERT_EQ(1, bthread::execution_queue_cancel(handle0));
665 ASSERT_EQ(1, bthread::execution_queue_cancel(handle0));
666 bthread::TaskHandle handle1;
667 ASSERT_EQ(0, bthread::execution_queue_execute(queue_id, 100, NULL, &handle1));
668 ASSERT_EQ(0, bthread::execution_queue_cancel(handle1));
669 g_suspending = false;
670 ASSERT_EQ(-1, bthread::execution_queue_cancel(handle1));
671 ASSERT_EQ(0, bthread::execution_queue_stop(queue_id));
672 ASSERT_EQ(0, bthread::execution_queue_join(queue_id));
673 ASSERT_EQ(0, result);
674}
675
676TEST_F(ExecutionQueueTest, cancel) {
677 for (int i = 0; i < 2; ++i) {

Callers 1

TEST_FFunction · 0.85

Calls 5

execution_queue_startFunction · 0.85
execution_queue_executeFunction · 0.85
execution_queue_cancelFunction · 0.85
execution_queue_stopFunction · 0.85
execution_queue_joinFunction · 0.85

Tested by

no test coverage detected