[ https://issues.apache.org/jira/browse/HIVE-26411?focusedWorklogId=794082&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-794082 ]
ASF GitHub Bot logged work on HIVE-26411: ----------------------------------------- Author: ASF GitHub Bot Created on: 22/Jul/22 06:46 Start Date: 22/Jul/22 06:46 Worklog Time Spent: 10m Work Description: ghanko commented on code in PR #3458: URL: https://github.com/apache/hive/pull/3458#discussion_r927340981 ########## ql/src/test/org/apache/hadoop/hive/ql/parse/repl/metric/TestReplicationMetricCollector.java: ########## @@ -75,6 +84,12 @@ public void setup() throws Exception { MetricCollector.getInstance().init(conf); Mockito.when(fmd.getFailoverEventId()).thenReturn(10L); Mockito.when(fmd.getFilePath()).thenReturn("dummyDir"); + disableBackgroundThreads(); + } + + private void disableBackgroundThreads() { + PowerMockito.mockStatic(MetricSink.class); + Mockito.when(MetricSink.getInstance()).thenReturn(metricSinkInstance); Review Comment: Yes, this is the main idea and I verified locally with the debugger that the background threads are not started. Precisely what happens is that whenever MetricSink.getInstance() is called, it returns the mock metricSinkInstance and even if its init() is called, it does nothing because it's an empty method provided by the mock framework. Issue Time Tracking ------------------- Worklog Id: (was: 794082) Time Spent: 0.5h (was: 20m) > Fix TestReplicationMetricCollector flakiness > -------------------------------------------- > > Key: HIVE-26411 > URL: https://issues.apache.org/jira/browse/HIVE-26411 > Project: Hive > Issue Type: Bug > Components: Tests > Reporter: Hankó Gergely > Assignee: Hankó Gergely > Priority: Minor > Labels: pull-request-available > Time Spent: 0.5h > Remaining Estimate: 0h > > TestReplicationMetricCollector tests can fail intermittently because > ReplicationMetricCollector schedules a MetrikSink thread that consumes the > MetricCollector's > metricMap regularly and if this happens at the wrong time, the tests, that > use the MetricCollector.getInstance().getMetrics() method, can fail. > Example stack trace: > {code:java} > java.lang.AssertionError: expected:<1> but was:<0> at > org.junit.Assert.fail(Assert.java:88) at > org.junit.Assert.failNotEquals(Assert.java:743) at > org.junit.Assert.assertEquals(Assert.java:118) at > org.junit.Assert.assertEquals(Assert.java:555) at > org.junit.Assert.assertEquals(Assert.java:542) at > org.apache.hadoop.hive.ql.parse.repl.metric.TestReplicationMetricCollector.testFailoverReadyDumpMetrics(TestReplicationMetricCollector.java:227){code} -- This message was sent by Atlassian Jira (v8.20.10#820010)