You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] RaftEngineReadIndexTest fails now and then with UnfinishedStubbingException: the alive-peers refresher can call the mocked raft node while a test stubs it #3384
RaftEngineReadIndexTest.testStoppedReadServiceClosureThatRunsFirstFailsAsNotLeader should pass every run. It failed once in three runs of the same commit on 2026-10-20, with Mockito's unfinished-stubbing error while the test stubs readIndex:
[ERROR] org.apache.hugegraph.pd.raft.RaftEngineReadIndexTest.testStoppedReadServiceClosureThatRunsFirstFailsAsNotLeader -- Time elapsed: 0.012 s <<< ERROR!
org.mockito.exceptions.misusing.UnfinishedStubbingException:
Unfinished stubbing detected here:
-> at org.apache.hugegraph.pd.raft.RaftEngineReadIndexTest.answerShutdown(RaftEngineReadIndexTest.java:377)
at org.apache.hugegraph.pd.raft.RaftEngineReadIndexTest.answerShutdown(RaftEngineReadIndexTest.java:382)
at org.apache.hugegraph.pd.raft.RaftEngineReadIndexTest.testStoppedReadServiceClosureThatRunsFirstFailsAsNotLeader(RaftEngineReadIndexTest.java:367)
The runs, all mvn -B -ntp test -pl hugegraph-pd/hg-pd-test -am -P pd-core-test on 171760d25:
Host
pd-core (run/failures/errors/skipped)
8 cores, JDK 17
227/0/1/2 (this error)
same host, again
227/0/0/2
12 cores, JDK 17
227/0/0/2
Likely cause, not proven: the test swaps a Mockito mock into the RaftEngine singleton (Whitebox.setInternalState(..., "raftNode", mockNode)) and stubs it, while the engine's pd-raft-alive-peers refresher thread (startAlivePeersRefresher, every ALIVE_PEERS_REFRESH_MS) calls node.listAlivePeers() on whatever node the singleton holds whenever its state machine reports leader. An earlier suite test can leave the singleton started and leading. A call on the mock from that thread while doAnswer(...).when(mockNode).readIndex(...) is in progress is the case Mockito reports as unfinished stubbing.
A fix could stop the refresher for these tests (or give the refresher a node snapshot taken under the same lock the tests use), or stub listAlivePeers on the mock before it is installed.
Activity