Skip to content

Commit 678db6b

Browse files
authored
[fix][test] Fix flaky SubscriptionSeekTest.testSeekWillNotEncounteredFencedError by counting subscription is fenced only after seek (#24865)
1 parent 562d446 commit 678db6b

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;
@@ -1045,11 +1046,14 @@ public void testSeekWillNotEncounteredFencedError() throws Exception {
10451046
// Create a pulsar client with a subscription fenced counter.
10461047
ClientBuilderImpl clientBuilder = (ClientBuilderImpl) PulsarClient.builder().serviceUrl(lookupUrl.toString());
10471048
AtomicInteger receivedFencedErrorCounter = new AtomicInteger();
1049+
// Count switch: Default off, turn on again before seek starts.
1050+
final AtomicBoolean countAfterSeek = new AtomicBoolean(false);
10481051
@Cleanup
10491052
PulsarClient client = InjectedClientCnxClientBuilder.create(clientBuilder, (conf, eventLoopGroup) ->
10501053
new ClientCnx(InstrumentProvider.NOOP, conf, eventLoopGroup) {
10511054
protected void handleError(CommandError error) {
1052-
if (error.getMessage() != null && error.getMessage().contains("Subscription is fenced")) {
1055+
if (error.getMessage() != null && error.getMessage().contains("Subscription is fenced")
1056+
&& countAfterSeek.get()) {
10531057
receivedFencedErrorCounter.incrementAndGet();
10541058
}
10551059
super.handleError(error);
@@ -1086,10 +1090,9 @@ protected void handleError(CommandError error) {
10861090
assertNotNull(msg);
10871091
consumer.acknowledge(msg);
10881092
}
1093+
countAfterSeek.set(true);
10891094
consumer.seek(msgId1);
1090-
Awaitility.await().untilAsserted(() -> {
1091-
assertTrue(consumer.isConnected());
1092-
});
1095+
Awaitility.await().untilAsserted(() -> assertTrue(consumer.isConnected()));
10931096
assertEquals(receivedFencedErrorCounter.get(), 0);
10941097

10951098
// cleanup.

0 commit comments

Comments
 (0)