Skip to content

Override Retry configuration for Unit Tests #380

@manstis

Description

@manstis

We have a Reconciler implementing ErrorStatusHandler. It uses DefaultRetryConfiguration by default.

We have a Unit Test for this Reconciler annotated to run within Quarkus's Open Shift Test Server. @QuarkusTest @WithOpenShiftTestServer. The Unit Test invokes the Reconciler by creating a suitable resource that the Reconciler handles: kubernetesClient.resources(X.class).createOrReplace(expected).

We'd like to test the ErrorStatusHandler side of things by making our Reconciler throw an exception and let the retry mechanism enter our ErrorStatusHandler. We can then make assertions based on the operation of the ErrorStatusHandler logic.

It is not possible to override DefaultRetryConfiguration retry configuration just for the test.

The jist of the code is:

Reconciler

@Inject
MyService service;

@Override
public UpdateControl<X> reconcile(X x, Context context) {
  service.doSomething();
}

@Override
public Optional<X> updateErrorStatus(X x, RetryInfo retryInfo, RuntimeException e) {
  if (retryInfo.isLastAttempt()) {
    service.error();
  }
}

Test

@QuarkusTest
@WithOpenShiftTestServer
public class XTest {

@Inject
KubernetesClient client;

@InjectMock
MyService service;

@Test
public void test() {
  when(service.doSomething()).thenThrow(new NullPointerException());

  client.resources(X.class).createOrReplace(expected);

  // wait a bit

  verify(service).error();

}

We'd like to override the retry so that the Reconciler can effectively fail fast.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions