Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-55760

Cancelation tests for AsyncTry are racy

    • Fully Compatible
    • ALL
    • v5.0
    • Service Arch 2021-06-14, Service Arch 2021-06-28
    • 124

      These two tests that AsyncTryUntilWithDelay loops can be canceled by a CancellationToken should be split into four tests that use barriers to specify exactly when cancelSource.cancel() is called with respect to the execution of the loop.

      E.g. AsyncTryUntilWithBackoffCanBeCanceled should be changed to AsyncTryUntilWithBackoffCanBeCanceledAfterLoopIsDoneExecuting and AsyncTryUntilWithBackoffCanBeCanceledWhileLoopIsExecuting. Example code for the former:

          
      TEST_F(AsyncTryUntilTest, AsyncTryUntilWithBackoffCanBeCanceledAfterLoopIsDoneExecuting) {
              CancellationSource cancelSource;
              unittest::Barrier barrier{2};
              auto resultFut = AsyncTry([] {})
                                         .until([&](Status) {
                                              barrier.countDownAndWait();
                                              return false;
                                         })
                                         .withBackoffBetweenIterations(TestBackoff{Seconds(10000000)})
                                        .on(executor(), cancelSource.token());
              barrier.countDownAndWait();
              cancelSource.cancel();
              ASSERT_EQ(resultFut.getNoThrow(), kCanceledStatus);
          }
      

      This will help tease out more possible bugs in the implementation.

            Assignee:
            alex.li@mongodb.com Alex Li
            Reporter:
            matthew.saltz@mongodb.com Matthew Saltz (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: