Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Metadata ZKSessionTest less Flaky #10955

Merged
merged 1 commit into from Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion pulsar-metadata/pom.xml
Expand Up @@ -31,7 +31,6 @@

<artifactId>pulsar-metadata</artifactId>
<name>Pulsar Metadata</name>

<dependencies>
<dependency>
<groupId>org.apache.pulsar</groupId>
Expand All @@ -58,6 +57,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.bookkeeper</groupId>
<artifactId>bookkeeper-server</artifactId>
Expand Down
Expand Up @@ -26,7 +26,6 @@
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;

import lombok.Cleanup;

Expand All @@ -40,6 +39,7 @@
import org.apache.pulsar.metadata.api.extended.SessionEvent;
import org.apache.pulsar.metadata.coordination.impl.CoordinationServiceImpl;
import org.apache.pulsar.metadata.impl.ZKMetadataStore;
import org.awaitility.Awaitility;
import org.testng.annotations.Test;

public class ZKSessionTest extends BaseMetadataStoreTest {
Expand All @@ -61,10 +61,10 @@ public void testDisconnection() throws Exception {
assertEquals(e, SessionEvent.ConnectionLost);

zks.start();
e = sessionEvents.poll(10, TimeUnit.SECONDS);
e = sessionEvents.poll(20, TimeUnit.SECONDS);
assertEquals(e, SessionEvent.Reconnected);

e = sessionEvents.poll(1, TimeUnit.SECONDS);
e = sessionEvents.poll(5, TimeUnit.SECONDS);
assertNull(e);
}

Expand Down Expand Up @@ -130,9 +130,9 @@ public void testReacquireLocksAfterSessionLost() throws Exception {
e = sessionEvents.poll(10, TimeUnit.SECONDS);
assertEquals(e, SessionEvent.SessionReestablished);

Thread.sleep(2_000);

assertFalse(lock.getLockExpiredFuture().isDone());
Awaitility.await().untilAsserted(() -> {
assertFalse(lock.getLockExpiredFuture().isDone());
});

assertTrue(store.get(path).join().isPresent());
}
Expand Down Expand Up @@ -171,7 +171,10 @@ public void testReacquireLeadershipAfterSessionLost() throws Exception {
e = sessionEvents.poll(10, TimeUnit.SECONDS);
assertEquals(e, SessionEvent.SessionLost);

assertEquals(le1.getState(), LeaderElectionState.Leading);
Awaitility.await().untilAsserted(() -> {
assertEquals(le1.getState(), LeaderElectionState.Leading);
});

les = leaderElectionEvents.poll();
assertNull(les);

Expand All @@ -180,9 +183,9 @@ public void testReacquireLeadershipAfterSessionLost() throws Exception {
e = sessionEvents.poll(10, TimeUnit.SECONDS);
assertEquals(e, SessionEvent.SessionReestablished);

Thread.sleep(2_000);

assertEquals(le1.getState(), LeaderElectionState.Leading);
Awaitility.await().untilAsserted(() -> {
assertEquals(le1.getState(), LeaderElectionState.Leading);
});
les = leaderElectionEvents.poll();
assertNull(les);

Expand Down