pulsar icon indicating copy to clipboard operation
pulsar copied to clipboard

Flaky-test: OneWayReplicatorDeduplicationTest.testDeduplication

Open Dream95 opened this issue 10 months ago • 3 comments

Search before reporting

  • [x] I searched in the issues and found nothing similar.

Example failure

Adding Thread.sleep in the MessageDeduplication.takeSnapshot method can improve the trigger probability.

Exception stacktrace

org.awaitility.core.ConditionTimeoutException: Assertion condition expected [true] but found [false] within 10 seconds.

	at org.awaitility.core.ConditionAwaiter.await(ConditionAwaiter.java:167)
	at org.awaitility.core.AssertionCondition.await(AssertionCondition.java:119)
	at org.awaitility.core.AssertionCondition.await(AssertionCondition.java:31)
	at org.awaitility.core.ConditionFactory.until(ConditionFactory.java:985)
	at org.awaitility.core.ConditionFactory.untilAsserted(ConditionFactory.java:769)
	at org.apache.pulsar.broker.service.OneWayReplicatorDeduplicationTest.testDeduplication(OneWayReplicatorDeduplicationTest.java:521)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
	at java.base/java.lang.reflect.Method.invoke(Method.java:565)
	at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:139)
	at org.testng.internal.invokers.InvokeMethodRunnable.runOne(InvokeMethodRunnable.java:47)
	at org.testng.internal.invokers.InvokeMethodRunnable.call(InvokeMethodRunnable.java:76)
	at org.testng.internal.invokers.InvokeMethodRunnable.call(InvokeMethodRunnable.java:11)
	at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:328)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java)
	at --- Async.Stack.Trace --- (captured by IntelliJ IDEA debugger)
	at java.base/java.util.concurrent.FutureTask.<init>(FutureTask.java:134)
	at java.base/java.util.concurrent.AbstractExecutorService.newTaskFor(AbstractExecutorService.java:113)
	at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:147)
	at org.testng.internal.invokers.MethodInvocationHelper.invokeWithTimeoutWithNewExecutor(MethodInvocationHelper.java:385)
	at org.testng.internal.invokers.MethodInvocationHelper.invokeWithTimeout(MethodInvocationHelper.java:303)
	at org.testng.internal.invokers.TestInvoker.invokeMethod(TestInvoker.java:686)
	at org.testng.internal.invokers.TestInvoker.invokeTestMethod(TestInvoker.java:221)
	at org.testng.internal.invokers.MethodRunner.runInSequence(MethodRunner.java:50)
	at org.testng.internal.invokers.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:969)
	at org.testng.internal.invokers.TestInvoker.invokeTestMethods(TestInvoker.java:194)
	at org.testng.internal.invokers.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:148)
	at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:128)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1604)
	at org.testng.TestRunner.privateRun(TestRunner.java:829)
	at org.testng.TestRunner.run(TestRunner.java:602)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:437)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:431)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:391)
	at org.testng.SuiteRunner.run(SuiteRunner.java:330)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:95)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1256)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1176)
	at org.testng.TestNG.runSuites(TestNG.java:1099)
	at org.testng.TestNG.run(TestNG.java:1067)
	at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:65)
	at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:105)
Caused by: java.lang.AssertionError: expected [true] but found [false]
	at org.testng.Assert.fail(Assert.java:110)
	at org.testng.Assert.failNotEquals(Assert.java:1577)
	at org.testng.Assert.assertTrue(Assert.java:56)
	at org.testng.Assert.assertTrue(Assert.java:66)
	at org.apache.pulsar.broker.service.OneWayReplicatorDeduplicationTest.lambda$testDeduplication$3(OneWayReplicatorDeduplicationTest.java:529)
	at org.awaitility.core.AssertionCondition.lambda$new$0(AssertionCondition.java:53)
	at org.awaitility.core.ConditionAwaiter$ConditionPoller.call(ConditionAwaiter.java:248)
	at org.awaitility.core.ConditionAwaiter$ConditionPoller.call(ConditionAwaiter.java:235)

Are you willing to submit a PR?

  • [x] I'm willing to submit a PR!

Dream95 avatar Jan 14 '26 13:01 Dream95

The issue is caused by the takeSnapshot operation being in a pending state. Should add a mechanism to ensure takeSnapshot?

 if (!snapshotTaking.compareAndSet(false, true)) {
            log.warn("[{}] There is a pending snapshot when taking snapshot for {}", topic.getName(), position);
            return CompletableFuture.completedFuture(null);
        }

Dream95 avatar Jan 14 '26 13:01 Dream95

Currently, if a snapshot is already in progress, the new takeSnapshot call is skipped due to the compareAndSet, which can cause the test to miss the expected state and timeout. I was using Thread.sleep to increase the probability, but I see that it's not a reliable one

Praveenkumar76 avatar May 03 '26 18:05 Praveenkumar76

I’ll look into adding a mechanism to ensure the snapshot eventually completes (e.g., waiting, retrying, or exposing a way to observe completion) instead of being skipped.

Praveenkumar76 avatar May 03 '26 18:05 Praveenkumar76