PrimaryOnlyServiceMongoDTest::stepUp artificially advances the last applied optime by incrementing the term but keeping the same timestamp. Reading the existing timestamp and updating it are done non-atomically, so if there are operations in the background that could modify the last applied op time, then it is possible that stepUp could try to set the op time to an older time, triggering an invariant failure.
PrimaryOnlyServiceTest runs into this race because the _rebuildService implementation in the service it uses (TestService) builds an index. _rebuildService is invoked asynchronously via opStepUpComplete, so its possible that a test case could begin while this index build is happening in the background.
There are several test cases that may fail due to this (e.g. ShutdownDuringStepUp and StateTransitionFromRebuildingShouldWakeUpConditionVariable).