Before returning the batch response in ClonerOneBatchThenCanceled, the test should cancel the cancelToken to prevent the cloner from potentially making it another round before it gets cancelled. This is done in other test cases for the ReshardingTxnCloner.
Note - the token should be canceled only once the request is sent to make sure the first batch doesn't get skipped entirely.
Motivation:
The test can hang if the token gets cancelled after the first batch is processed and already awaiting a new response.
It can be reproduced as follows
TEST_F(ReshardingTxnClonerTest, ClonerOneBatchThenCanceled) { const auto txns = makeSortedTxns(4); auto executor = makeTaskExecutorForCloner(); ReshardingTxnCloner cloner(kTwoSourceIdList[1], Timestamp::max()); auto opCtxToken = operationContext()->getCancellationToken(); auto cancelSource = CancellationSource(opCtxToken); auto future = runCloner(cloner, executor, cancelSource.token()); onCommandReturnTxnBatch(std::vector<BSONObj>(txns.begin(), txns.begin() + 2), CursorId{123}, true /* isFirstBatch */); sleepsecs(2); // <---------------------- added for repro cancelSource.cancel(); auto status = future.getNoThrow(); ASSERT_EQ(status.code(), ErrorCodes::CallbackCanceled); }