[
https://issues.apache.org/jira/browse/RATIS-1621?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17565094#comment-17565094
]
Benjamin Horowitz commented on RATIS-1621:
------------------------------------------
It looks like the intention of the test is to ensure that after
{{leaderElectionMetrics.onNewLeaderElectionCompletion()}}
is called, {{LeaderElectionMetrics.lastElectionTime}} is updated such that the
latency returned by the gauge is reflective of the last election. One thing I
am not sure about is the meaning of the latency returned by the gauge -- does
the latency represent the duration between the start of the OS process/JVM and
the last leader election?
The gauge will return -1 if {{LeaderElectionMetrics.lastElectionTime}} not
updated during {{{}leaderElectionMetrics.onNewLeaderElectionCompletion(){}}}.
In this case, {{{}LeaderElectionMetrics.lastElectionTime == null{}}}, and the
gauge uses the value of -1L from its definition:
{code:java}
Optional.ofNullable(lastElectionTime).map(Timestamp::elapsedTimeMs).orElse(-1L)))
{code}
So I think a reasonable approach would be to change the assertion to
{code:java}
assertTrue("leaderElectionLatency = " + leaderElectionLatency,
leaderElectionLatency >= 0L) {code}
This would catch any regression where
{{leaderElectionMetrics.onNewLeaderElectionCompletion()}} does not update
{{{}LeaderElectionMetrics.lastElectionTime{}}}.
> TestLeaderElectionMetrics.testOnLeaderElectionCompletion fails sometimes
> ------------------------------------------------------------------------
>
> Key: RATIS-1621
> URL: https://issues.apache.org/jira/browse/RATIS-1621
> Project: Ratis
> Issue Type: Bug
> Components: test
> Reporter: Benjamin Horowitz
> Priority: Major
>
> When running unit tests I encountered the following failure:
> {noformat}
> java.lang.AssertionError: leaderElectionLatency = 0
> at org.junit.Assert.fail(Assert.java:89)
> at org.junit.Assert.assertTrue(Assert.java:42)
> at
> org.apache.ratis.server.metrics.TestLeaderElectionMetrics.testOnLeaderElectionCompletion(TestLeaderElectionMetrics.java:61)
> {noformat}
> It seems like the assertion {{assertTrue("leaderElectionLatency = " +
> leaderElectionLatency, leaderElectionLatency > 0L)}} may be too strict.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)