Fix flaky restartAfterRequestTimerExpires tests (#1084)
Add wait to allow subscriptions to start. This eliminates flakiness of tests restartAfterRequestTimerExpiresWhenNotGettingRecordsAfterInitialization() and restartAfterRequestTimerExpiresWhenInitialTaskExecutionIsRejected().
This commit is contained in:
parent
10cdf43b9d
commit
b8d3390bf3
1 changed files with 24 additions and 33 deletions
|
|
@ -79,6 +79,8 @@ public class ShardConsumerSubscriberTest {
|
||||||
|
|
||||||
private static final String TERMINAL_MARKER = "Terminal";
|
private static final String TERMINAL_MARKER = "Terminal";
|
||||||
|
|
||||||
|
private static final long DEFAULT_NOTIFIER_TIMEOUT = 5000L;
|
||||||
|
|
||||||
private final RequestDetails lastSuccessfulRequestDetails = new RequestDetails();
|
private final RequestDetails lastSuccessfulRequestDetails = new RequestDetails();
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
|
|
@ -125,10 +127,7 @@ public class ShardConsumerSubscriberTest {
|
||||||
|
|
||||||
setupNotifierAnswer(1);
|
setupNotifierAnswer(1);
|
||||||
|
|
||||||
synchronized (processedNotifier) {
|
startSubscriptionsAndWait();
|
||||||
subscriber.startSubscriptions();
|
|
||||||
processedNotifier.wait(5000);
|
|
||||||
}
|
|
||||||
|
|
||||||
verify(shardConsumer).handleInput(argThat(eqProcessRecordsInput(processRecordsInput)), any(Subscription.class));
|
verify(shardConsumer).handleInput(argThat(eqProcessRecordsInput(processRecordsInput)), any(Subscription.class));
|
||||||
}
|
}
|
||||||
|
|
@ -139,10 +138,7 @@ public class ShardConsumerSubscriberTest {
|
||||||
|
|
||||||
setupNotifierAnswer(recordsPublisher.responses.size());
|
setupNotifierAnswer(recordsPublisher.responses.size());
|
||||||
|
|
||||||
synchronized (processedNotifier) {
|
startSubscriptionsAndWait();
|
||||||
subscriber.startSubscriptions();
|
|
||||||
processedNotifier.wait(5000);
|
|
||||||
}
|
|
||||||
|
|
||||||
verify(shardConsumer, times(100)).handleInput(argThat(eqProcessRecordsInput(processRecordsInput)), any(Subscription.class));
|
verify(shardConsumer, times(100)).handleInput(argThat(eqProcessRecordsInput(processRecordsInput)), any(Subscription.class));
|
||||||
}
|
}
|
||||||
|
|
@ -171,10 +167,7 @@ public class ShardConsumerSubscriberTest {
|
||||||
}
|
}
|
||||||
}).when(shardConsumer).handleInput(any(ProcessRecordsInput.class), any(Subscription.class));
|
}).when(shardConsumer).handleInput(any(ProcessRecordsInput.class), any(Subscription.class));
|
||||||
|
|
||||||
synchronized (processedNotifier) {
|
startSubscriptionsAndWait();
|
||||||
subscriber.startSubscriptions();
|
|
||||||
processedNotifier.wait(5000);
|
|
||||||
}
|
|
||||||
|
|
||||||
assertThat(subscriber.getAndResetDispatchFailure(), equalTo(testException));
|
assertThat(subscriber.getAndResetDispatchFailure(), equalTo(testException));
|
||||||
assertThat(subscriber.getAndResetDispatchFailure(), nullValue());
|
assertThat(subscriber.getAndResetDispatchFailure(), nullValue());
|
||||||
|
|
@ -192,10 +185,7 @@ public class ShardConsumerSubscriberTest {
|
||||||
|
|
||||||
setupNotifierAnswer(10);
|
setupNotifierAnswer(10);
|
||||||
|
|
||||||
synchronized (processedNotifier) {
|
startSubscriptionsAndWait();
|
||||||
subscriber.startSubscriptions();
|
|
||||||
processedNotifier.wait(5000);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int attempts = 0; attempts < 10; attempts++) {
|
for (int attempts = 0; attempts < 10; attempts++) {
|
||||||
if (subscriber.retrievalFailure() != null) {
|
if (subscriber.retrievalFailure() != null) {
|
||||||
|
|
@ -220,10 +210,7 @@ public class ShardConsumerSubscriberTest {
|
||||||
|
|
||||||
setupNotifierAnswer(10);
|
setupNotifierAnswer(10);
|
||||||
|
|
||||||
synchronized (processedNotifier) {
|
startSubscriptionsAndWait();
|
||||||
subscriber.startSubscriptions();
|
|
||||||
processedNotifier.wait(5000);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int attempts = 0; attempts < 10; attempts++) {
|
for (int attempts = 0; attempts < 10; attempts++) {
|
||||||
if (subscriber.retrievalFailure() != null) {
|
if (subscriber.retrievalFailure() != null) {
|
||||||
|
|
@ -236,7 +223,7 @@ public class ShardConsumerSubscriberTest {
|
||||||
|
|
||||||
synchronized (processedNotifier) {
|
synchronized (processedNotifier) {
|
||||||
assertThat(subscriber.healthCheck(100000), equalTo(expected));
|
assertThat(subscriber.healthCheck(100000), equalTo(expected));
|
||||||
processedNotifier.wait(5000);
|
processedNotifier.wait(DEFAULT_NOTIFIER_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
assertThat(recordsPublisher.restartedFrom, equalTo(edgeRecord));
|
assertThat(recordsPublisher.restartedFrom, equalTo(edgeRecord));
|
||||||
|
|
@ -267,10 +254,7 @@ public class ShardConsumerSubscriberTest {
|
||||||
return null;
|
return null;
|
||||||
}).when(shardConsumer).handleInput(any(ProcessRecordsInput.class), any(Subscription.class));
|
}).when(shardConsumer).handleInput(any(ProcessRecordsInput.class), any(Subscription.class));
|
||||||
|
|
||||||
synchronized (processedNotifier) {
|
startSubscriptionsAndWait();
|
||||||
subscriber.startSubscriptions();
|
|
||||||
processedNotifier.wait(5000);
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (processedNotifier) {
|
synchronized (processedNotifier) {
|
||||||
executorService.execute(() -> {
|
executorService.execute(() -> {
|
||||||
|
|
@ -290,7 +274,7 @@ public class ShardConsumerSubscriberTest {
|
||||||
//
|
//
|
||||||
// Wait for our blocking thread to control the thread in the executor.
|
// Wait for our blocking thread to control the thread in the executor.
|
||||||
//
|
//
|
||||||
processedNotifier.wait(5000);
|
processedNotifier.wait(DEFAULT_NOTIFIER_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
Stream.iterate(2, i -> i + 1).limit(97).forEach(this::addUniqueItem);
|
Stream.iterate(2, i -> i + 1).limit(97).forEach(this::addUniqueItem);
|
||||||
|
|
@ -301,7 +285,7 @@ public class ShardConsumerSubscriberTest {
|
||||||
assertThat(subscriber.healthCheck(1), nullValue());
|
assertThat(subscriber.healthCheck(1), nullValue());
|
||||||
barrier.await(500, TimeUnit.MILLISECONDS);
|
barrier.await(500, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
processedNotifier.wait(5000);
|
processedNotifier.wait(DEFAULT_NOTIFIER_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
verify(shardConsumer, times(100)).handleInput(argThat(eqProcessRecordsInput(processRecordsInput)), any(Subscription.class));
|
verify(shardConsumer, times(100)).handleInput(argThat(eqProcessRecordsInput(processRecordsInput)), any(Subscription.class));
|
||||||
|
|
@ -337,9 +321,7 @@ public class ShardConsumerSubscriberTest {
|
||||||
}).when(shardConsumer).handleInput(any(ProcessRecordsInput.class), any(Subscription.class));
|
}).when(shardConsumer).handleInput(any(ProcessRecordsInput.class), any(Subscription.class));
|
||||||
|
|
||||||
// First try to start subscriptions.
|
// First try to start subscriptions.
|
||||||
synchronized (processedNotifier) {
|
startSubscriptionsAndWait(100);
|
||||||
subscriber.startSubscriptions();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verifying that there are no interactions with shardConsumer mock indicating no records were sent back and
|
// Verifying that there are no interactions with shardConsumer mock indicating no records were sent back and
|
||||||
// subscription has not started correctly.
|
// subscription has not started correctly.
|
||||||
|
|
@ -397,9 +379,7 @@ public class ShardConsumerSubscriberTest {
|
||||||
}).when(shardConsumer).handleInput(any(ProcessRecordsInput.class), any(Subscription.class));
|
}).when(shardConsumer).handleInput(any(ProcessRecordsInput.class), any(Subscription.class));
|
||||||
|
|
||||||
// First try to start subscriptions.
|
// First try to start subscriptions.
|
||||||
synchronized (processedNotifier) {
|
startSubscriptionsAndWait(100);
|
||||||
subscriber.startSubscriptions();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verifying that there are no interactions with shardConsumer mock indicating no records were sent back and
|
// Verifying that there are no interactions with shardConsumer mock indicating no records were sent back and
|
||||||
// subscription has not started correctly.
|
// subscription has not started correctly.
|
||||||
|
|
@ -478,6 +458,17 @@ public class ShardConsumerSubscriberTest {
|
||||||
}).when(shardConsumer).handleInput(any(ProcessRecordsInput.class), any(Subscription.class));
|
}).when(shardConsumer).handleInput(any(ProcessRecordsInput.class), any(Subscription.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void startSubscriptionsAndWait() throws InterruptedException {
|
||||||
|
startSubscriptionsAndWait(DEFAULT_NOTIFIER_TIMEOUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startSubscriptionsAndWait(long timeout) throws InterruptedException {
|
||||||
|
synchronized (processedNotifier) {
|
||||||
|
subscriber.startSubscriptions();
|
||||||
|
processedNotifier.wait(timeout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class ResponseItem {
|
private class ResponseItem {
|
||||||
private final RecordsRetrieved recordsRetrieved;
|
private final RecordsRetrieved recordsRetrieved;
|
||||||
private final Throwable throwable;
|
private final Throwable throwable;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue