private MockComponents createTimeoutMocksAtInitialTime(long messageTimeoutMillis, long sessionTimeoutMillis,
                                                           long currentTimeMillis, int maxPending) {
        MockComponentsBuilder builder = new MockComponentsBuilder();
        builder.params.setTimeoutMs(messageTimeoutMillis);
        builder.params.setSessionTimeoutMs(sessionTimeoutMillis);
        builder.params.setControlHandler(builder.controlHandler);
        builder.params.setLocalDataHandler(builder.dataHandler);
        MockComponents mc = builder.createMockComponents();
        mc.sender.setMaxPending(maxPending);
        mc.clock.setMonotonicTime(currentTimeMillis, TimeUnit.MILLISECONDS); // Baseline time

        mc.visitorSession.start();
        mc.controlHandler.resetMock(); // clear messages
        mc.executor.expectAndProcessTasks(1);
        return mc;
    }
Test that there is no race condition between a reply is handed off
to the executor service via a task (thus decrementing the pending count
for the sender) and the session checking for completion early, e.g.
because of an error transitioning it into a failure state.
documentapi/src/test/java/com/yahoo/documentapi/messagebus/MessageBusVisitorSessionTestCase.java