mirror of https://github.com/apache/kafka.git
KAFKA-18771: fix Flaky test KRaftClusterTest .testDescribeQuorumRequestToControllers (#18859)
The case testDescribeQuorumRequestToControllers shutdowns raft client but not the controller. This makes client has chance to send a request to the controller and get NOT_LEADER_OR_FOLLOWER error. However, if the raft client finishes shutdown before handling the request, the request will not be handled. Shutdown the controller before doing KafkaFuture#get for the client request, so we can make sure the request is handled by another controller eventually. Signed-off-by: PoAn Yang <payang@apache.org> Reviewers: Luke Chen <showuon@gmail.com>
This commit is contained in:
parent
400363b7e2
commit
63fc9b3cb8
|
@ -962,11 +962,16 @@ class KRaftClusterTest {
|
|||
s"Leader ID ${quorumInfo.leaderId} was not a controller ID.")
|
||||
|
||||
// Try to bring down the raft client in the active controller node to force the leader election.
|
||||
// Stop raft client but not the controller, because we would like to get NOT_LEADER_OR_FOLLOWER error first.
|
||||
// If the controller is shutdown, the client can't send request to the original leader.
|
||||
cluster.controllers().get(quorumInfo.leaderId).sharedServer.raftManager.client.shutdown(1000)
|
||||
// Send another describe metadata quorum request, it'll get NOT_LEADER_OR_FOLLOWER error first and then re-retrieve the metadata update
|
||||
// and send to the correct active controller.
|
||||
val quorumInfo2 = admin.describeMetadataQuorum(new DescribeMetadataQuorumOptions)
|
||||
.quorumInfo().get()
|
||||
val quorumInfo2Future = admin.describeMetadataQuorum(new DescribeMetadataQuorumOptions).quorumInfo
|
||||
// If raft client finishes shutdown before returning NOT_LEADER_OR_FOLLOWER error, the request will not be handled.
|
||||
// This makes test fail. Shutdown the controller to make sure the request is handled by another controller.
|
||||
cluster.controllers.get(quorumInfo.leaderId).shutdown()
|
||||
val quorumInfo2 = quorumInfo2Future.get
|
||||
// Make sure the leader has changed
|
||||
assertTrue(quorumInfo.leaderId() != quorumInfo2.leaderId())
|
||||
|
||||
|
|
Loading…
Reference in New Issue