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

Function TEST

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

Source from the content-addressed store, hash-verified

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