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

Function TEST

cpp/src/arrow/util/async_util_test.cc:46–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44constexpr std::string_view kDummyName = "unit test";
45
46TEST(AsyncTaskScheduler, ShouldScheduleConcurrentTasks) {
47 // A basic test to make sure we schedule the right number of concurrent tasks
48 constexpr int kMaxConcurrentTasks = 2;
49 constexpr int kTotalNumTasks = kMaxConcurrentTasks + 1;
50 Future<> futures[kTotalNumTasks];
51 bool submitted[kTotalNumTasks];
52 Future<> finished = AsyncTaskScheduler::Make([&](AsyncTaskScheduler* scheduler) {
53 std::shared_ptr<ThrottledAsyncTaskScheduler> throttled =
54 ThrottledAsyncTaskScheduler::Make(scheduler, kMaxConcurrentTasks);
55 for (int i = 0; i < kTotalNumTasks; i++) {
56 futures[i] = Future<>::Make();
57 submitted[i] = false;
58 throttled->AddSimpleTask(
59 [&, i] {
60 submitted[i] = true;
61 return futures[i];
62 },
63 kDummyName);
64 }
65 return Status::OK();
66 });
67 AssertNotFinished(finished);
68 for (int i = 0; i < kTotalNumTasks; i++) {
69 if (i < kMaxConcurrentTasks) {
70 ASSERT_TRUE(submitted[i]);
71 } else {
72 ASSERT_FALSE(submitted[i]);
73 }
74 }
75
76 for (int j = 0; j < kTotalNumTasks; j++) {
77 futures[j].MarkFinished();
78 if (j + kMaxConcurrentTasks < kTotalNumTasks) {
79 ASSERT_TRUE(submitted[j + kMaxConcurrentTasks]);
80 }
81 }
82 ASSERT_FINISHES_OK(finished);
83}
84
85TEST(AsyncTaskScheduler, CancelWaitsForTasksToFinish) {
86 StopSource stop_source;

Callers

nothing calls this directly

Calls 15

AssertNotFinishedFunction · 0.85
SleepABitFunction · 0.85
SleepABitAsyncFunction · 0.85
SlowdownABitFunction · 0.85
tokenMethod · 0.80
RequestStopMethod · 0.80
ThenMethod · 0.80
push_backMethod · 0.80
AddAsyncGeneratorMethod · 0.80
MakeFunction · 0.70
OKFunction · 0.50
InvalidFunction · 0.50

Tested by

no test coverage detected