@Override
    public void terminate() throws Exception {
        isRunning = false;
        // wait for all containers to stop
        trackerOfReleasedResources.register();
        trackerOfReleasedResources.arriveAndAwaitAdvance();

        // shut down all components
        Exception exception = null;

        if (resourceManagerClient != null) {
            try {
                resourceManagerClient.stop();
            } catch (Exception e) {
                exception = e;
            }
        }

        if (nodeManagerClient != null) {
            try {
                nodeManagerClient.stop();
            } catch (Exception e) {
                exception = ExceptionUtils.firstOrSuppressed(e, exception);
            }
        }

        if (exception != null) {
            throw exception;
        }
    }
@Test
    void testOnErrorAfterTerminationIgnored() throws Exception {
        new Context() {
            {
                final CompletableFuture<Throwable> throwableCompletableFuture =
                        new CompletableFuture<>();
                resourceEventHandlerBuilder.setOnErrorConsumer(
                        throwableCompletableFuture::complete);

                Throwable expectedThrowable = new Exception("test");
                runTest(
                        () -> {
                            getDriver().terminate();
                            resourceManagerClientCallbackHandler.onError(expectedThrowable);

                            assertThatThrownBy(
                                            () ->
                                                    throwableCompletableFuture.get(
                                                            TIMEOUT_SHOULD_NOT_HAPPEN_MS,
                                                            TimeUnit.MILLISECONDS))
                                    .isInstanceOf(TimeoutException.class);
                        });
            }
        };
    }