Skip to content

fix: flaky test #1044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -364,4 +364,8 @@ public String toString() {
return controllerName + " -> " + executionScope;
}
}

public synchronized boolean isUnderProcessing(ResourceID resourceID) {
return underProcessing.contains(resourceID);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.javaoperatorsdk.operator.processing.event;

import java.time.Duration;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
Expand All @@ -24,6 +25,7 @@

import static io.javaoperatorsdk.operator.TestUtils.testCustomResource;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -152,16 +154,20 @@ void successfulExecutionResetsTheRetry() {
eventProcessorWithRetry.handleEvent(event);
verify(reconciliationDispatcherMock, timeout(SEPARATE_EXECUTION_TIMEOUT).times(1))
.handleExecution(any());
waitUntilProcessingFinished(eventProcessorWithRetry, event.getRelatedCustomResourceID());

eventProcessorWithRetry.handleEvent(event);
verify(reconciliationDispatcherMock, timeout(SEPARATE_EXECUTION_TIMEOUT).times(2))
.handleExecution(any());
waitUntilProcessingFinished(eventProcessorWithRetry, event.getRelatedCustomResourceID());

eventProcessorWithRetry.handleEvent(event);
verify(reconciliationDispatcherMock, timeout(SEPARATE_EXECUTION_TIMEOUT).times(3))
.handleExecution(executionScopeArgumentCaptor.capture());
waitUntilProcessingFinished(eventProcessorWithRetry, event.getRelatedCustomResourceID());
log.info("Finished successfulExecutionResetsTheRetry");


List<ExecutionScope> executionScopes = executionScopeArgumentCaptor.getAllValues();

assertThat(executionScopes).hasSize(3);
Expand All @@ -171,6 +177,12 @@ void successfulExecutionResetsTheRetry() {
assertThat(executionScopes.get(1).getRetryInfo().isLastAttempt()).isEqualTo(false);
}

private void waitUntilProcessingFinished(EventProcessor eventProcessor,
ResourceID relatedCustomResourceID) {
await().atMost(Duration.ofSeconds(3))
.until(() -> !eventProcessor.isUnderProcessing(relatedCustomResourceID));
}

@Test
void scheduleTimedEventIfInstructedByPostExecutionControl() {
var testDelay = 10000L;
Expand Down