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

Cancelation tests for AsyncTry are racy

    XMLWordPrintable

    Details

    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      ALL
    • Backport Requested:
      v5.0
    • Sprint:
      Service Arch 2021-06-14, Service Arch 2021-06-28
    • Linked BF Score:
      124

      Description

      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.

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: