Skip to content

Multiple tests cannot stop and restart the injected operator #388

@rsynek

Description

@rsynek

The reconciler tests in samples show that the injected operator could be started at the beginning of the test method [1].

When there are multiple test methods of a reconciler, such an approach fails in the second test method, as the operator was already started in the first one.

A possible solution would be to start and stop the operator in @BeforeEach and @AfterEach methods [2]. However, restarting the operator fails due to:
java.lang.IllegalStateException: Cannot restart a stopped informer

Workaround:
The workaround just starts the operator once, without trying to stop it. As constructor injection does not seem to work (the operator instance is null), I found the following, rather cumbersome way of making it work:

@Inject
private Operator operator;

public void onStart(@Observes StartupEvent startupEvent) {
    operator.start();
}

Proposal:
Make the operator restartable to enable the @BeforeEach / @AfterEach approach, which is more natural for a test setup.

[1] https://github.com/quarkiverse/quarkus-operator-sdk/blob/main/samples/exposedapp/src/test/java/io/halkyon/ExposedAppReconcilerTest.java#L32
[2] #387

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