westonpace commented on a change in pull request #10258:
URL: https://github.com/apache/arrow/pull/10258#discussion_r643636361



##########
File path: cpp/src/arrow/util/future_test.cc
##########
@@ -952,6 +951,85 @@ TEST(FutureCompletionTest, FutureVoid) {
   }
 }
 
+class FutureSchedulingTest : public testing::Test {
+ public:
+  internal::Executor* executor() { return mock_executor.get(); }
+  int spawn_count() { return mock_executor->spawn_count; }
+
+  std::function<void(const Status&)> callback = [](const Status&) {};
+  std::shared_ptr<MockExecutor> mock_executor = 
std::make_shared<MockExecutor>();
+};
+
+TEST_F(FutureSchedulingTest, ScheduleAlways) {
+  CallbackOptions options;
+  options.should_schedule = ShouldSchedule::ALWAYS;
+  options.executor = executor();
+  // Successful future
+  {
+    auto fut = Future<>::Make();
+    fut.AddCallback(callback, options);
+    fut.MarkFinished();
+    fut.AddCallback(callback, options);
+    ASSERT_EQ(2, spawn_count());
+  }
+  // Failing future
+  {
+    auto fut = Future<>::Make();
+    fut.AddCallback(callback, options);
+    fut.MarkFinished(Status::Invalid("XYZ"));
+    fut.AddCallback(callback, options);
+    ASSERT_EQ(4, spawn_count());
+  }
+}
+
+TEST_F(FutureSchedulingTest, ScheduleIfUnfinished) {
+  CallbackOptions options;
+  options.should_schedule = ShouldSchedule::IF_UNFINISHED;
+  options.executor = executor();
+  // Successful future
+  {
+    auto fut = Future<>::Make();
+    fut.AddCallback(callback, options);
+    fut.MarkFinished();
+    fut.AddCallback(callback, options);
+    ASSERT_EQ(1, spawn_count());
+  }
+  // Failing future
+  {
+    auto fut = Future<>::Make();
+    fut.AddCallback(callback, options);
+    fut.MarkFinished(Status::Invalid("XYZ"));
+    fut.AddCallback(callback, options);
+    ASSERT_EQ(2, spawn_count());
+  }
+}
+
+class DelayedExecutor : public internal::Executor {

Review comment:
       My rationale was only that `DelayedExecutor` is only used in 
`future_test.cc` while `MockExecutor` is used in `future_test.cc` and 
`thread_pool_test.cc` but I see your point.  I'll move this into 
`test_common.h`.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to