|
11 | 11 | import org.junit.jupiter.api.BeforeEach;
|
12 | 12 | import org.junit.jupiter.api.Test;
|
13 | 13 | import org.mockito.ArgumentCaptor;
|
| 14 | +import org.mockito.ArgumentMatcher; |
14 | 15 | import org.mockito.ArgumentMatchers;
|
15 | 16 | import org.mockito.stubbing.Answer;
|
16 | 17 |
|
@@ -110,7 +111,10 @@ private <R extends HasMetadata> ReconciliationDispatcher<R> init(R customResourc
|
110 | 111 | when(configuration.getFinalizerName()).thenReturn(DEFAULT_FINALIZER);
|
111 | 112 | when(configuration.getName()).thenReturn("EventDispatcherTestController");
|
112 | 113 | when(configuration.getResourceClass()).thenReturn(resourceClass);
|
113 |
| - when(configuration.getRetry()).thenReturn(new GenericRetry()); |
| 114 | + // needed so the retry can be predefined |
| 115 | + if (configuration.getRetry() == null) { |
| 116 | + when(configuration.getRetry()).thenReturn(new GenericRetry()); |
| 117 | + } |
114 | 118 | when(configuration.maxReconciliationInterval())
|
115 | 119 | .thenReturn(Optional.of(Duration.ofHours(RECONCILIATION_MAX_INTERVAL)));
|
116 | 120 |
|
@@ -600,6 +604,34 @@ void errorStatusHandlerCanPatchResource() {
|
600 | 604 | any(), any());
|
601 | 605 | }
|
602 | 606 |
|
| 607 | + @Test |
| 608 | + void ifRetryLimitedToZeroMaxAttemptsErrorHandlerGetsCorrectLastAttempt() { |
| 609 | + var configuration = |
| 610 | + MockControllerConfiguration |
| 611 | + .forResource((Class<TestCustomResource>) testCustomResource.getClass()); |
| 612 | + when(configuration.getRetry()).thenReturn(new GenericRetry().setMaxAttempts(0)); |
| 613 | + reconciliationDispatcher = |
| 614 | + init(testCustomResource, reconciler, configuration, customResourceFacade, false); |
| 615 | + |
| 616 | + reconciler.reconcile = (r, c) -> { |
| 617 | + throw new IllegalStateException("Error Status Test"); |
| 618 | + }; |
| 619 | + var mockErrorHandler = mock(ErrorStatusHandler.class); |
| 620 | + when(mockErrorHandler.updateErrorStatus(any(), any(), any())) |
| 621 | + .thenReturn(ErrorStatusUpdateControl.noStatusUpdate()); |
| 622 | + reconciler.errorHandler = mockErrorHandler; |
| 623 | + |
| 624 | + reconciliationDispatcher.handleExecution( |
| 625 | + new ExecutionScope( |
| 626 | + testCustomResource, null)); |
| 627 | + |
| 628 | + verify(mockErrorHandler, times(1)).updateErrorStatus(any(), |
| 629 | + ArgumentMatchers.argThat((ArgumentMatcher<Context<TestCustomResource>>) context -> { |
| 630 | + var retryInfo = context.getRetryInfo().orElseThrow(); |
| 631 | + return retryInfo.isLastAttempt(); |
| 632 | + }), any()); |
| 633 | + } |
| 634 | + |
603 | 635 | @Test
|
604 | 636 | void canSkipSchedulingMaxDelayIf() {
|
605 | 637 | testCustomResource.addFinalizer(DEFAULT_FINALIZER);
|
|
0 commit comments