Skip to content

Commit

Permalink
[fix][flaky-test]ProxyConnectionThrottlingTest.testInboundConnection (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
poorbarcode authored Sep 29, 2022
1 parent 0f53c79 commit 3de690d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 6 additions & 0 deletions pulsar-proxy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@
<scope>test</scope>
</dependency>

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

<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.pulsar.client.api.Schema;
import org.apache.pulsar.common.configuration.PulsarConfigurationLoader;
import org.apache.pulsar.metadata.impl.ZKMetadataStore;
import org.awaitility.Awaitility;
import org.mockito.Mockito;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
Expand Down Expand Up @@ -108,7 +109,9 @@ public void testInboundConnection() throws Exception {
} catch (Exception ex) {
// OK
}
Assert.assertEquals(ConnectionController.DefaultConnectionController.getTotalConnectionNum(), 4);
Awaitility.await().untilAsserted(() ->{
Assert.assertEquals(ConnectionController.DefaultConnectionController.getTotalConnectionNum(), 4);
});
Assert.assertEquals(ConnectionController.DefaultConnectionController.getConnections().size(), 1);
Set<String> keys = ConnectionController.DefaultConnectionController.getConnections().keySet();
for (String key : keys) {
Expand All @@ -119,7 +122,9 @@ public void testInboundConnection() throws Exception {

client1.close();

Assert.assertEquals(ConnectionController.DefaultConnectionController.getTotalConnectionNum(), 2);
Awaitility.await().untilAsserted(() ->{
Assert.assertEquals(ConnectionController.DefaultConnectionController.getTotalConnectionNum(), 2);
});
Assert.assertEquals(ConnectionController.DefaultConnectionController.getConnections().size(), 1);
keys = ConnectionController.DefaultConnectionController.getConnections().keySet();
for (String key : keys) {
Expand All @@ -129,8 +134,9 @@ public void testInboundConnection() throws Exception {
Assert.assertEquals(ProxyService.ACTIVE_CONNECTIONS.get(), 2.0d);

client2.close();

Assert.assertEquals(ConnectionController.DefaultConnectionController.getTotalConnectionNum(), 0);
Awaitility.await().untilAsserted(() ->{
Assert.assertEquals(ConnectionController.DefaultConnectionController.getTotalConnectionNum(), 0);
});
Assert.assertEquals(ConnectionController.DefaultConnectionController.getConnections().size(), 0);
Assert.assertEquals(ProxyService.ACTIVE_CONNECTIONS.get(), 0.0d);
}
Expand Down

0 comments on commit 3de690d

Please sign in to comment.