Skip to content

Commit

Permalink
SERVER-94712 duplicate existing NITL and AsyncDBClient tests to run o…
Browse files Browse the repository at this point in the history
…n the baton (#27695)

GitOrigin-RevId: 79132b502acdab2534de5a41e701ae0ec7f463dc
  • Loading branch information
jpbronsted authored and MongoDB Bot committed Oct 1, 2024
1 parent fbd738b commit dedc17d
Show file tree
Hide file tree
Showing 4 changed files with 308 additions and 201 deletions.
17 changes: 8 additions & 9 deletions src/mongo/executor/network_interface_integration_fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,10 @@ void NetworkInterfaceIntegrationFixture::resetIsInternalClient(bool isInternalCl
}

Future<RemoteCommandResponse> NetworkInterfaceIntegrationFixture::runCommand(
const TaskExecutor::CallbackHandle& cbHandle,
RemoteCommandRequest request,
const std::shared_ptr<Baton>& baton) {

const TaskExecutor::CallbackHandle& cbHandle, RemoteCommandRequest request) {
_onSchedulingCommand();

return net()
.startCommand(cbHandle, request, baton)
.startCommand(cbHandle, request, baton())
.unsafeToInlineFuture()
.then([request](TaskExecutor::ResponseStatus resStatus) {
if (resStatus.isOK()) {
Expand All @@ -153,6 +149,11 @@ Future<RemoteCommandResponse> NetworkInterfaceIntegrationFixture::runCommand(
});
}

void NetworkInterfaceIntegrationFixture::cancelCommand(
const TaskExecutor::CallbackHandle& cbHandle) {
net().cancelCommand(cbHandle, baton());
}

Future<void> NetworkInterfaceIntegrationFixture::startExhaustCommand(
const TaskExecutor::CallbackHandle& cbHandle,
RemoteCommandRequest request,
Expand Down Expand Up @@ -226,9 +227,7 @@ NetworkInterfaceIntegrationFixture::configureFailCommand(

RemoteCommandResponse NetworkInterfaceIntegrationFixture::runCommandSync(
RemoteCommandRequest& request) {
auto deferred = runCommand(makeCallbackHandle(), request);
auto& res = deferred.get();
return res;
return runCommand(makeCallbackHandle(), request).get(interruptible());
}

void NetworkInterfaceIntegrationFixture::assertCommandOK(const DatabaseName& db,
Expand Down
30 changes: 28 additions & 2 deletions src/mongo/executor/network_interface_integration_fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,14 @@ class NetworkInterfaceIntegrationFixture : public mongo::unittest::Test {

PseudoRandom* getRandomNumberGenerator();

/**
* Runs a command, returning a future representing its response. When waiting on this future,
* use the interruptible returned by interruptible() and only do so from one thread.
*/
Future<RemoteCommandResponse> runCommand(const TaskExecutor::CallbackHandle& cbHandle,
RemoteCommandRequest rcroa,
const std::shared_ptr<Baton>& baton = nullptr);
RemoteCommandRequest rcroa);

void cancelCommand(const TaskExecutor::CallbackHandle& cbHandle);

/**
* Runs a command on the fixture NetworkInterface and asserts it suceeded.
Expand All @@ -116,8 +121,16 @@ class NetworkInterfaceIntegrationFixture : public mongo::unittest::Test {
std::function<void(const RemoteCommandResponse&)> exhaustUtilCB,
const BatonHandle& baton = nullptr);

/**
* Runs a command synchronously, returning its response. While this executes, no other thread
* may use interruptible().
*/
RemoteCommandResponse runCommandSync(RemoteCommandRequest& request);

/**
* Asserts that a command succeeds or fails in some disposition. While these execute, no other
* thread may use interruptible().
*/
void assertCommandOK(const DatabaseName& db,
const BSONObj& cmd,
Milliseconds timeoutMillis = Minutes(5),
Expand Down Expand Up @@ -187,6 +200,19 @@ class NetworkInterfaceIntegrationFixture : public mongo::unittest::Test {
boost::optional<ErrorCodes::Error> errorCode = boost::none,
boost::optional<Milliseconds> blockTime = boost::none);

/**
* Returns a Baton that can be used to run commands on, or nullptr for reactor-only operation.
* Implicitly used by runCommand, cancelCommand, runCommandSync, and assertCommand* variants.
*/
virtual BatonHandle baton() {
return nullptr;
}

/** Returns an Interruptible appropriate for the Baton returned from baton(). */
virtual Interruptible* interruptible() {
return Interruptible::notInterruptible();
}

private:
void _onSchedulingCommand();
void _onCompletingCommand();
Expand Down
Loading

0 comments on commit dedc17d

Please sign in to comment.