| 335 | } |
| 336 | |
| 337 | void TestFinishAlreadyCompleted(std::function<std::shared_ptr<TaskGroup>()> factory) { |
| 338 | // If we call FinishAsync we are done adding tasks so even if no tasks are running we |
| 339 | // should still be completed |
| 340 | const int NTASKS = 100; |
| 341 | for (int i = 0; i < NTASKS; ++i) { |
| 342 | auto task_group = factory(); |
| 343 | // Add a task and let it complete |
| 344 | task_group->Append([] { return Status::OK(); }); |
| 345 | // Wait a little bit, hopefully enough time for the task to finish on one of these |
| 346 | // iterations |
| 347 | SleepFor(1e-2); |
| 348 | auto finished = task_group->FinishAsync(); |
| 349 | ASSERT_FINISHES_OK(finished); |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | TEST(SerialTaskGroup, Success) { TestTaskGroupSuccess(TaskGroup::MakeSerial()); } |
| 354 | |