src/connectivity/wlan/drivers/third_party/broadcom/brcmfmac/test/workqueue_test.cc
// Upon canceling a job that is in progress, the canceler should block until the job completes.
// Subsequent jobs should also complete.
Upon canceling a job that is in progress, the canceler should block until the job completes.
Subsequent jobs should also complete.
Upon canceling a job that is in progress the canceler should block until the job completes . Subsequent jobs should also complete .
TEST(Workqueue, CancelCurrent) {
  WorkQueue* queue = new WorkQueue("MyWork");
  TestWork work1;
  TestWork work2;
  WorkCanceler canceler;
  canceler.target = &work1;
  work1.work = WorkItem(handler);
  work2.work = WorkItem(handler);
  canceler.work = WorkItem(cancel_handler);
  queue->Schedule(&work1.work);
  queue->Schedule(&work2.work);
  sync_completion_wait(&work1.entered, ZX_TIME_INFINITE);
  EXPECT_EQ(work1.state, 1);
  EXPECT_EQ(work2.state, 0);
  WorkQueue::ScheduleDefault(&canceler.work);
  zx_nanosleep(zx_deadline_after(ZX_MSEC(50)));
  EXPECT_EQ(work1.state, 1);
  EXPECT_EQ(canceler.state, 0);
  sync_completion_signal(&work1.proceed);
  sync_completion_wait(&work2.entered, ZX_TIME_INFINITE);
  EXPECT_EQ(work1.state, 2);
  EXPECT_EQ(work2.state, 1);
  sync_completion_wait(&canceler.leaving, ZX_TIME_INFINITE);
  sync_completion_signal(&work2.proceed);
  delete queue;
}
TEST ( Workqueue , CancelCurrent ) { WorkQueue * queue = new WorkQueue ( " " ) ; TestWork work1 ; TestWork work2 ; WorkCanceler canceler ; canceler . target = & work1 ; work1 . work = WorkItem ( handler ) ; work2 . work = WorkItem ( handler ) ; canceler . work = WorkItem ( cancel_handler ) ; queue -> Schedule ( & work1 . work ) ; queue -> Schedule ( & work2 . work ) ; sync_completion_wait ( & work1 . entered , ZX_TIME_INFINITE ) ; EXPECT_EQ ( work1 . state , 1 ) ; EXPECT_EQ ( work2 . state , 0 ) ; WorkQueue :: ScheduleDefault ( & canceler . work ) ; zx_nanosleep ( zx_deadline_after ( ZX_MSEC ( 50 ) ) ) ; EXPECT_EQ ( work1 . state , 1 ) ; EXPECT_EQ ( canceler . state , 0 ) ; sync_completion_signal ( & work1 . proceed ) ; sync_completion_wait ( & work2 . entered , ZX_TIME_INFINITE ) ; EXPECT_EQ ( work1 . state , 2 ) ; EXPECT_EQ ( work2 . state , 1 ) ; sync_completion_wait ( & canceler . leaving , ZX_TIME_INFINITE ) ; sync_completion_signal ( & work2 . proceed ) ; delete queue ; }
Upon canceling a job that is in progress, the canceler should block until the job completes.
Upon canceling a job that is in progress the canceler should block until the job completes .
// If this timeout is too short and the canceler hasn't entered yet, it may cause a false pass, // but not a flaky fail.