ethanresnick opened a new pull request, #23910:
URL: https://github.com/apache/kafka/pull/23910

   `KafkaConsumerTest#testReturnRecordsDuringRebalance` (classic protocol)
   uses `new MockTime(1L)`, so every clock read, on any thread, advances
   time by 1 ms. While the group is stable after the first rebalance, the
   heartbeat thread can send a `HeartbeatRequest`. The test prepares no
   response for it, so it stays in flight.
   
   The test then answers the second rebalance with
   `client.respondFrom(response, coordinator)`. `respondFrom` answers the
   first request in flight to that node, of any type. If the heartbeat is
   still in flight, it gets the JoinGroup response, and the later SyncGroup
   response goes to the JoinGroup request. The rebalance never completes,
   and the test fails with:
   
   ```
   Condition not met within timeout 15000. Does not complete rebalance in time
   ```
   
   This change makes the test answer the JoinGroup and SyncGroup requests
   themselves, with `respondToRequest` and the existing `findRequest`
   helper. `findRequest` fails with a clear message if no request of that
   type is in flight. This is a test-only change.
   
   Whether a heartbeat comes due first depends on thread scheduling, so the
   failure is rare. We saw it on a slow, power-limited laptop CPU:
   - Six consumer test classes in one JVM failed in 2 of about 24 runs.
   - The same six classes at macOS background QoS (efficiency cores, low
     priority) failed in 1 of 24 runs.
   - At normal priority, the same six classes failed in 0 of 45 runs.
   - The test class alone at background QoS failed in 0 of 50 runs.
   
   Forced reproduction: add these lines just before `// subscription change`
   in the test. They let a heartbeat come due and wait until it is in
   flight:
   
   ```java
   time.sleep(heartbeatIntervalMs);
   TestUtils.waitForCondition(() -> client.requests().stream()
       .anyMatch(r -> r.apiKey() == ApiKeys.HEARTBEAT), "no heartbeat in 
flight");
   ```
   
   With these lines, the test fails in 5 of 5 runs without this change, with
   the message above. It passes in 5 of 5 runs with this change. Without
   the forced lines, `KafkaConsumerTest` passes (227 tests), and clients
   checkstyle and spotless pass.
   
   I ran the tests at trunk commit f568b7b, on JDK 21. There, `MockClient.java`
   and `AbstractCoordinator.java` are the same as on current trunk, and
   `KafkaConsumerTest.java` differs only by the KAFKA-20858 rename
   (`SubscriptionState` to `ConsumerSubscriptionState`).
   
   Co-Authored-By: Claude Opus 5.5 <[email protected]>
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to