tensorflow/core/kernels/batching_util/basic_batch_scheduler_test.cc
// Since BasicBatchScheduler is implemented as a thin wrapper around
// SharedBatchScheduler, we only do some basic testing. More comprehensive
// testing is done in shared_batch_scheduler_test.cc.
Since BasicBatchScheduler is implemented as a thin wrapper around
SharedBatchScheduler, we only do some basic testing. More comprehensive
testing is done in shared_batch_scheduler_test.cc.
Since BasicBatchScheduler is implemented as a thin wrapper around SharedBatchScheduler we only do some basic testing . More comprehensive testing is done in shared_batch_scheduler_test . cc .
TEST(BasicBatchSchedulerTest, Basic) {
  bool callback_called = false;
  auto callback = [&callback_called](std::unique_ptr<Batch<FakeTask>> batch) {
    callback_called = true;
    ASSERT_TRUE(batch->IsClosed());
    ASSERT_EQ(2, batch->num_tasks());
    EXPECT_EQ(3, batch->task(0).size());
    EXPECT_EQ(5, batch->task(1).size());
  };
  {
    BasicBatchScheduler<FakeTask>::Options options;
    options.max_batch_size = 10;
    options.batch_timeout_micros = 100 * 1000;  
    options.num_batch_threads = 1;
    options.max_enqueued_batches = 3;
    std::unique_ptr<BasicBatchScheduler<FakeTask>> scheduler;
    TF_ASSERT_OK(
        BasicBatchScheduler<FakeTask>::Create(options, callback, &scheduler));
    EXPECT_EQ(10, scheduler->max_task_size());
    EXPECT_EQ(0, scheduler->NumEnqueuedTasks());
    EXPECT_EQ(3 * 10, scheduler->SchedulingCapacity());
    TF_ASSERT_OK(ScheduleTask(3, scheduler.get()));
    EXPECT_EQ(1, scheduler->NumEnqueuedTasks());
    EXPECT_EQ((3 * 10) - 3, scheduler->SchedulingCapacity());
    TF_ASSERT_OK(ScheduleTask(5, scheduler.get()));
    EXPECT_EQ(2, scheduler->NumEnqueuedTasks());
    EXPECT_EQ((3 * 10) - (3 + 5), scheduler->SchedulingCapacity());
  }
  EXPECT_TRUE(callback_called);
}
TEST ( BasicBatchSchedulerTest , Basic ) { bool callback_called = false ; auto callback = [ & callback_called ] ( std :: unique_ptr < Batch < FakeTask > > batch ) { callback_called = true ; ASSERT_TRUE ( batch -> IsClosed ( ) ) ; ASSERT_EQ ( 2 , batch -> num_tasks ( ) ) ; EXPECT_EQ ( 3 , batch -> task ( 0 ) . size ( ) ) ; EXPECT_EQ ( 5 , batch -> task ( 1 ) . size ( ) ) ; } ; { BasicBatchScheduler < FakeTask > :: Options options ; options . max_batch_size = 10 ; options . batch_timeout_micros = 100 * 1000 ; options . num_batch_threads = 1 ; options . max_enqueued_batches = 3 ; std :: unique_ptr < BasicBatchScheduler < FakeTask > > scheduler ; TF_ASSERT_OK ( BasicBatchScheduler < FakeTask > :: Create ( options , callback , & scheduler ) ) ; EXPECT_EQ ( 10 , scheduler -> max_task_size ( ) ) ; EXPECT_EQ ( 0 , scheduler -> NumEnqueuedTasks ( ) ) ; EXPECT_EQ ( 3 * 10 , scheduler -> SchedulingCapacity ( ) ) ; TF_ASSERT_OK ( ScheduleTask ( 3 , scheduler . get ( ) ) ) ; EXPECT_EQ ( 1 , scheduler -> NumEnqueuedTasks ( ) ) ; EXPECT_EQ ( ( 3 * 10 ) - 3 , scheduler -> SchedulingCapacity ( ) ) ; TF_ASSERT_OK ( ScheduleTask ( 5 , scheduler . get ( ) ) ) ; EXPECT_EQ ( 2 , scheduler -> NumEnqueuedTasks ( ) ) ; EXPECT_EQ ( ( 3 * 10 ) - ( 3 + 5 ) , scheduler -> SchedulingCapacity ( ) ) ; } EXPECT_TRUE ( callback_called ) ; }
Since BasicBatchScheduler is implemented as a thin wrapper around
SharedBatchScheduler, we only do some basic testing.
Since BasicBatchScheduler is implemented as a thin wrapper around SharedBatchScheduler we only do some basic testing .
// 100 milliseconds