[PAN-2529] subscribing to sync events should receive false when in sync (#1240)

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
Chris Mckay 6 years ago committed by GitHub
parent 6bcece14bd
commit d994cb820d
  1. 4
      ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/SyncStatus.java
  2. 9
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/syncing/SyncingSubscriptionService.java
  3. 15
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/syncing/SyncingSubscriptionServiceTest.java

@ -38,6 +38,10 @@ public final class SyncStatus {
return highestBlock;
}
public boolean inSync() {
return currentBlock == highestBlock;
}
@Override
public boolean equals(final Object o) {
if (this == o) {

@ -35,7 +35,12 @@ public class SyncingSubscriptionService {
final List<Subscription> syncingSubscriptions =
subscriptionManager.subscriptionsOfType(SubscriptionType.SYNCING, Subscription.class);
syncingSubscriptions.forEach(
s -> subscriptionManager.sendMessage(s.getId(), new SyncingResult(syncStatus)));
if (syncStatus.inSync()) {
syncingSubscriptions.forEach(
s -> subscriptionManager.sendMessage(s.getId(), new NotSynchronisingResult()));
} else {
syncingSubscriptions.forEach(
s -> subscriptionManager.sendMessage(s.getId(), new SyncingResult(syncStatus)));
}
}
}

@ -53,11 +53,24 @@ public class SyncingSubscriptionServiceTest {
final SyncingSubscription subscription = new SyncingSubscription(9L, SubscriptionType.SYNCING);
when(subscriptionManager.subscriptionsOfType(any(), any()))
.thenReturn(Lists.newArrayList(subscription));
final SyncStatus syncStatus = new SyncStatus(0L, 1L, 1L);
final SyncStatus syncStatus = new SyncStatus(0L, 1L, 3L);
final SyncingResult expectedSyncingResult = new SyncingResult(syncStatus);
syncStatusListener.onSyncStatus(syncStatus);
verify(subscriptionManager).sendMessage(eq(subscription.getId()), eq(expectedSyncingResult));
}
@Test
public void shouldSendNotSyncingStatusWhenReceiveSyncStatusAtHead() {
final SyncingSubscription subscription = new SyncingSubscription(9L, SubscriptionType.SYNCING);
when(subscriptionManager.subscriptionsOfType(any(), any()))
.thenReturn(Lists.newArrayList(subscription));
final SyncStatus syncStatus = new SyncStatus(0L, 1L, 1L);
syncStatusListener.onSyncStatus(syncStatus);
verify(subscriptionManager)
.sendMessage(eq(subscription.getId()), any(NotSynchronisingResult.class));
}
}

Loading…
Cancel
Save