Repository: apache/kafka
File: raft/src/test/java/org/apache/kafka/raft/RequestManagerTest.java (Java)

Code before:
            requestTimeoutMs,
            random
        );

        // Find a ready node with the starting state
        Node bootstrapNode1 = cache.findReadyBootstrapServer(time.milliseconds()).get();
        assertTrue(
            bootstrapList.contains(bootstrapNode1),
            String.format("%s is not in %s", bootstrapNode1, bootstrapList)
        );
        // Before sending a request, no request should have timed out
        assertFalse(cache.hasRequestTimedOut(bootstrapNode1, time.milliseconds()));

        // Send a request
        cache.onRequestSent(bootstrapNode1, 1, time.milliseconds());
        assertEquals(
            Optional.empty(),
            cache.findReadyBootstrapServer(time.milliseconds())
        );
        assertFalse(cache.hasRequestTimedOut(bootstrapNode1, time.milliseconds()));

        time.sleep(requestTimeoutMs / 2);
        assertFalse(cache.hasRequestTimedOut(bootstrapNode1, time.milliseconds()));

        // Timeout the request
        time.sleep(requestTimeoutMs / 2);
        assertTrue(cache.hasRequestTimedOut(bootstrapNode1, time.milliseconds()));
    }

    @Test
    public void testAnyInflightRequestWithAnyRequest() {
        Node otherNode = new Node(1, "other-node", 1234);
        List<Node> bootstrapList = makeBootstrapList(3);
        RequestManager cache = new RequestManager(
            bootstrapList,
            retryBackoffMs,
            requestTimeoutMs,
            random
        );

        assertFalse(cache.hasAnyInflightRequest(time.milliseconds()));

        // Send a request and check state
        cache.onRequestSent(otherNode, 11, time.milliseconds());
        assertTrue(cache.hasAnyInflightRequest(time.milliseconds()));

        // Wait until the request times out
        time.sleep(requestTimeoutMs);
        assertFalse(cache.hasAnyInflightRequest(time.milliseconds()));

        // Send another request and fail it

Review comment (performance):
In integer division, `value / 2 + value / 2` does not equal `value`. You can see this when value is 3. `3/2`  is `1` and `1 + 1` is not `3`. A more obvious sleep logic is:
 ```java
        time.sleep(requestTimeoutMs - 1);
        assertFalse(cache.hasRequestTimedOut(bootstrapNode1, time.milliseconds()));

        // Timeout the request
        time.sleep(1);
```

Code after:
            requestTimeoutMs,
            random
        );

        // Find a ready node with the starting state
        Node bootstrapNode1 = cache.findReadyBootstrapServer(time.milliseconds()).get();
        assertTrue(
            bootstrapList.contains(bootstrapNode1),
            String.format("%s is not in %s", bootstrapNode1, bootstrapList)
        );
        // Before sending a request, no request should have timed out
        assertFalse(cache.hasRequestTimedOut(bootstrapNode1, time.milliseconds()));

        // Send a request
        cache.onRequestSent(bootstrapNode1, 1, time.milliseconds());
        assertEquals(
            Optional.empty(),
            cache.findReadyBootstrapServer(time.milliseconds())
        );
        assertFalse(cache.hasRequestTimedOut(bootstrapNode1, time.milliseconds()));

        time.sleep(requestTimeoutMs - 1);
        assertFalse(cache.hasRequestTimedOut(bootstrapNode1, time.milliseconds()));

        // Timeout the request
        time.sleep(1);
        assertTrue(cache.hasRequestTimedOut(bootstrapNode1, time.milliseconds()));
    }

    @Test
    public void testAnyInflightRequestWithAnyRequest() {
        Node otherNode = new Node(1, "other-node", 1234);
        List<Node> bootstrapList = makeBootstrapList(3);
        RequestManager cache = new RequestManager(
            bootstrapList,
            retryBackoffMs,
            requestTimeoutMs,
            random
        );

        assertFalse(cache.hasAnyInflightRequest(time.milliseconds()));

        // Send a request and check state
        cache.onRequestSent(otherNode, 11, time.milliseconds());
        assertTrue(cache.hasAnyInflightRequest(time.milliseconds()));

        // Wait until the request times out
        time.sleep(requestTimeoutMs);
        assertFalse(cache.hasAnyInflightRequest(time.milliseconds()));

        // Send another request and fail it