@Test
    public void timeout_with_pending_inbound_messages_does_not_close_session_until_all_operations_acked() {
        MockComponents mc = createTimeoutMocksAtInitialTime(1_000, 5_000, 20_000, 2);
        assertEquals(2, mc.sender.getMessageCount()); // 1 distribution bit => 2 buckets visited

        mc.receiver.send(new RemoveDocumentMessage(new DocumentId("id:ns:testdoc::bar")));
        mc.clock.setMonotonicTime(25_000, TimeUnit.MILLISECONDS); // Beyond timeout
        replyToCreateVisitor(mc.sender, ProgressToken.FINISHED_BUCKET); // Super bucket 1 of 2
        replyToCreateVisitor(mc.sender, ProgressToken.FINISHED_BUCKET); // Super bucket 2 of 2
        mc.executor.expectAndProcessTasks(3); // 1) Document operation, 2+3) CreateVisitorReply
        mc.executor.expectNoTasks();

        assertFalse(mc.controlHandler.isDone()); // Still a pending op, session _not_ yet done.

        var msgs = mc.dataHandler.getMessages();
        assertEquals(1, msgs.size());
        mc.dataHandler.ack(msgs.get(0).getAckToken());
        mc.executor.expectNoTasks();

        assertTrue(mc.controlHandler.isDone()); // Now it's done.
    }
Similar to the above test, but tests the case where we have received messages from a
content node and are asynchronously processing it. The session should not be closed
prior to completing all pending work.
documentapi/src/test/java/com/yahoo/documentapi/messagebus/MessageBusVisitorSessionTestCase.java