Skip to content

Commit 82e4977

Browse files
Denovo1998srinath-ctds
authored andcommitted
[fix][test] Fix flaky SubscriptionSeekTest.testSeekWillNotEncounteredFencedError by counting subscription is fenced only after seek (apache#24865)
(cherry picked from commit 678db6b) (cherry picked from commit 37c024c)
1 parent a246fd3 commit 82e4977

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

pulsar-broker/src/test/java/org/apache/pulsar/broker/service/SubscriptionSeekTest.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import java.util.concurrent.CompletableFuture;
3939
import java.util.concurrent.ExecutionException;
4040
import java.util.concurrent.TimeUnit;
41+
import java.util.concurrent.atomic.AtomicBoolean;
4142
import java.util.concurrent.atomic.AtomicInteger;
4243
import java.util.function.Function;
4344
import lombok.Cleanup;
@@ -1035,11 +1036,14 @@ public void testSeekWillNotEncounteredFencedError() throws Exception {
10351036
// Create a pulsar client with a subscription fenced counter.
10361037
ClientBuilderImpl clientBuilder = (ClientBuilderImpl) PulsarClient.builder().serviceUrl(lookupUrl.toString());
10371038
AtomicInteger receivedFencedErrorCounter = new AtomicInteger();
1039+
// Count switch: Default off, turn on again before seek starts.
1040+
final AtomicBoolean countAfterSeek = new AtomicBoolean(false);
10381041
@Cleanup
10391042
PulsarClient client = InjectedClientCnxClientBuilder.create(clientBuilder, (conf, eventLoopGroup) ->
10401043
new ClientCnx(conf, eventLoopGroup) {
10411044
protected void handleError(CommandError error) {
1042-
if (error.getMessage() != null && error.getMessage().contains("Subscription is fenced")) {
1045+
if (error.getMessage() != null && error.getMessage().contains("Subscription is fenced")
1046+
&& countAfterSeek.get()) {
10431047
receivedFencedErrorCounter.incrementAndGet();
10441048
}
10451049
super.handleError(error);
@@ -1076,10 +1080,9 @@ protected void handleError(CommandError error) {
10761080
assertNotNull(msg);
10771081
consumer.acknowledge(msg);
10781082
}
1083+
countAfterSeek.set(true);
10791084
consumer.seek(msgId1);
1080-
Awaitility.await().untilAsserted(() -> {
1081-
assertTrue(consumer.isConnected());
1082-
});
1085+
Awaitility.await().untilAsserted(() -> assertTrue(consumer.isConnected()));
10831086
assertEquals(receivedFencedErrorCounter.get(), 0);
10841087

10851088
// cleanup.

0 commit comments

Comments
 (0)