Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
[PAN-2367] Fix race condition in WebSocket AT (#1002)
Browse files Browse the repository at this point in the history
* [PAN-2367] Fix race condition in WebSocket AT

* Removing unecessary check

* Update test

* Spotless
  • Loading branch information
lucassaldanha authored Feb 28, 2019
1 parent 54aea82 commit 71ae2d6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package tech.pegasys.pantheon.tests.acceptance.dsl.pubsub;

import static org.assertj.core.api.Assertions.assertThat;
import static tech.pegasys.pantheon.tests.acceptance.dsl.WaitUtils.waitFor;

import tech.pegasys.pantheon.ethereum.core.Hash;

Expand Down Expand Up @@ -44,19 +45,22 @@ public void verifyEventReceived(final Hash expectedTransaction) {
}

public void verifyEventReceived(final Hash expectedTransaction, final int expectedOccurrences) {
final List<SubscriptionEvent> events = connection.getSubscriptionEvents();
assertThat(events).isNotNull();
int occurrences = 0;

for (final SubscriptionEvent event : events) {
if (matches(expectedTransaction, event)) {
occurrences++;
}
}

assertThat(occurrences)
.as("Expecting: %s occurrences, but found: %s", expectedOccurrences, occurrences)
.isEqualTo(expectedOccurrences);
waitFor(
() -> {
assertThat(connection.getSubscriptionEvents()).isNotEmpty();
final List<SubscriptionEvent> events = connection.getSubscriptionEvents();

int occurrences = 0;
for (final SubscriptionEvent event : events) {
if (matches(expectedTransaction, event)) {
occurrences++;
}
}

assertThat(occurrences)
.as("Expecting: %s occurrences, but found: %s", expectedOccurrences, occurrences)
.isEqualTo(expectedOccurrences);
});
}

private boolean matches(final Hash expectedTransaction, final SubscriptionEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
package tech.pegasys.pantheon.tests.acceptance.dsl.pubsub;

import static org.assertj.core.api.Assertions.assertThat;
import static tech.pegasys.pantheon.tests.acceptance.dsl.WaitUtils.waitFor;

import tech.pegasys.pantheon.tests.acceptance.dsl.node.NodeConfiguration;

import java.util.List;

import io.vertx.core.Vertx;

public class WebSocket {
Expand Down Expand Up @@ -51,8 +50,6 @@ public void unsubscribe(final Subscription subscription) {
}

public void verifyTotalEventsReceived(final int expectedTotalEventCount) {
final List<SubscriptionEvent> events = connection.getSubscriptionEvents();
assertThat(events).isNotNull();
assertThat(events.size()).isEqualTo(expectedTotalEventCount);
waitFor(() -> assertThat(connection.getSubscriptionEvents()).hasSize(expectedTotalEventCount));
}
}

0 comments on commit 71ae2d6

Please sign in to comment.