MCPcopy Create free account
hub / github.com/apache/arrow / TestTaskGroupCancel

Function TestTaskGroupCancel

cpp/src/arrow/util/task_group_test.cc:118–159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

116}
117
118void TestTaskGroupCancel(std::shared_ptr<TaskGroup> task_group, StopSource* stop_source) {
119 const int NSUCCESSES = 2;
120 const int NCANCELS = 20;
121
122 std::atomic<int> count(0);
123
124 auto task_group_was_ok = false;
125 task_group->Append([&]() -> Status {
126 for (int i = 0; i < NSUCCESSES; ++i) {
127 task_group->Append([&]() {
128 count++;
129 return Status::OK();
130 });
131 }
132 task_group_was_ok = task_group->ok();
133 for (int i = 0; i < NCANCELS; ++i) {
134 task_group->Append([&]() {
135 SleepFor(1e-2);
136 stop_source->RequestStop();
137 count++;
138 return Status::OK();
139 });
140 }
141
142 return Status::OK();
143 });
144
145 // Cancellation is propagated
146 ASSERT_RAISES(Cancelled, task_group->Finish());
147 ASSERT_TRUE(task_group_was_ok);
148 ASSERT_FALSE(task_group->ok());
149 if (task_group->parallelism() == 1) {
150 // Serial: exactly three successes
151 ASSERT_EQ(count.load(), NSUCCESSES + 1);
152 } else {
153 // Parallel: at least three successes
154 ASSERT_GE(count.load(), NSUCCESSES + 1);
155 ASSERT_LE(count.load(), NSUCCESSES * task_group->parallelism());
156 }
157 // Finish() is idempotent
158 ASSERT_RAISES(Cancelled, task_group->Finish());
159}
160
161class CopyCountingTask {
162 public:

Callers 1

TESTFunction · 0.85

Calls 8

SleepForFunction · 0.85
RequestStopMethod · 0.80
OKFunction · 0.50
AppendMethod · 0.45
okMethod · 0.45
FinishMethod · 0.45
parallelismMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected