Skip to content

Commit 956c56c

Browse files
fix: test adjustments
Signed-off-by: Matt Peterson <matt.peterson@swirldslabs.com>
1 parent 3bc17f3 commit 956c56c

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

server/src/test/java/com/hedera/block/server/BlockStreamServiceIT.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,13 @@ public void testPublishBlockStreamRegistrationAndExecution()
141141
}
142142

143143
@Test
144-
public void testSubscribeBlockStream() {
144+
public void testSubscribeBlockStream() throws IOException {
145145

146146
final ServiceStatus serviceStatus = new ServiceStatusImpl();
147147
serviceStatus.setWebServer(webServer);
148148

149149
final var streamMediator =
150-
new LiveStreamMediatorImpl(new HashMap<>(), blockWriter, serviceStatus);
150+
new LiveStreamMediatorImpl(new ConcurrentHashMap<>(), blockWriter, serviceStatus);
151151

152152
// Build the BlockStreamService
153153
final BlockStreamService blockStreamService =
@@ -171,6 +171,8 @@ public void testSubscribeBlockStream() {
171171
// Calling onNext() with a BlockItem
172172
streamObserver.onNext(publishStreamRequest);
173173

174+
verify(blockWriter, timeout(testTimeout).times(1)).write(blockItems.getFirst());
175+
174176
final SubscribeStreamResponse subscribeStreamResponse =
175177
SubscribeStreamResponse.newBuilder().setBlockItem(blockItems.getFirst()).build();
176178

server/src/test/java/com/hedera/block/server/mediator/LiveStreamMediatorImplTest.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public class LiveStreamMediatorImplTest {
5656
private final long TIMEOUT_THRESHOLD_MILLIS = 100L;
5757
private final long TEST_TIME = 1_719_427_664_950L;
5858

59+
private static final int testTimeout = 200;
60+
5961
@Test
6062
public void testUnsubscribeEach() throws InterruptedException {
6163

@@ -76,7 +78,7 @@ public void testUnsubscribeEach() throws InterruptedException {
7678
streamMediator.isSubscribed(observer3),
7779
"Expected the mediator to have observer3 subscribed");
7880

79-
Thread.sleep(50L);
81+
Thread.sleep(testTimeout);
8082

8183
streamMediator.unsubscribe(observer1);
8284
assertFalse(
@@ -152,9 +154,9 @@ public void testMediatorPublishEventToSubscribers() throws IOException, Interrup
152154
streamMediator.publish(blockItem);
153155

154156
// Confirm each subscriber was notified of the new block
155-
verify(streamObserver1, timeout(50).times(1)).onNext(subscribeStreamResponse);
156-
verify(streamObserver2, timeout(50).times(1)).onNext(subscribeStreamResponse);
157-
verify(streamObserver3, timeout(50).times(1)).onNext(subscribeStreamResponse);
157+
verify(streamObserver1, timeout(testTimeout).times(1)).onNext(subscribeStreamResponse);
158+
verify(streamObserver2, timeout(testTimeout).times(1)).onNext(subscribeStreamResponse);
159+
verify(streamObserver3, timeout(testTimeout).times(1)).onNext(subscribeStreamResponse);
158160

159161
// Confirm the BlockStorage write method was called
160162
verify(blockWriter).write(blockItem);
@@ -213,7 +215,7 @@ public void testOnCancelSubscriptionHandling() throws IOException {
213215
testConsumerBlockItemObserver.getOnCancel().run();
214216

215217
// Verify the event made it to the consumer
216-
verify(serverCallStreamObserver, timeout(50).times(1)).setOnCancelHandler(any());
218+
verify(serverCallStreamObserver, timeout(testTimeout).times(1)).setOnCancelHandler(any());
217219

218220
// Confirm the mediator unsubscribed the consumer
219221
assertFalse(streamMediator.isSubscribed(testConsumerBlockItemObserver));
@@ -245,7 +247,7 @@ public void testOnCloseSubscriptionHandling() throws IOException {
245247
testConsumerBlockItemObserver.getOnClose().run();
246248

247249
// Verify the event made it to the consumer
248-
verify(serverCallStreamObserver, timeout(50).times(1)).setOnCancelHandler(any());
250+
verify(serverCallStreamObserver, timeout(testTimeout).times(1)).setOnCancelHandler(any());
249251

250252
// Confirm the mediator unsubscribed the consumer
251253
assertFalse(streamMediator.isSubscribed(testConsumerBlockItemObserver));
@@ -274,7 +276,7 @@ public void testMediatorBlocksPublishAfterException() throws IOException, Interr
274276

275277
// Confirm the BlockPersistenceHandler write method was only called
276278
// once despite the second block being published.
277-
verify(blockWriter, timeout(50).times(1)).write(firstBlockItem);
279+
verify(blockWriter, timeout(testTimeout).times(1)).write(firstBlockItem);
278280
}
279281
}
280282

0 commit comments

Comments
 (0)