Skip to content

Commit

Permalink
Add debugging feature which leaves integration test containers runnin…
Browse files Browse the repository at this point in the history
…g after test completes

- For debugging purposes, it is useful to have the ability to leave containers running.
  This mode can be activated by setting environment variable TESTCONTAINERS_RYUK_DISABLED=true

- TESTCONTAINERS_RYUK_DISABLED=true also disables TestContainers automatic container
  cleanup, https://www.testcontainers.org/features/configuration/#disabling-ryuk .
  - in this case, use this command afterwards to kill docker containers started
    by Testcontainers:
    docker ps -q --filter "label=org.testcontainers=true" | xargs -r docker kill
  • Loading branch information
lhotari committed Feb 19, 2021
1 parent cf63ae8 commit a0fd5d8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ public abstract class PulsarContainer<SelfT extends PulsarContainer<SelfT>> exte
public static final String PULSAR_2_1_IMAGE_NAME = "apachepulsar/pulsar:2.1.0";
public static final String PULSAR_2_0_IMAGE_NAME = "apachepulsar/pulsar:2.0.0";

/**
* For debugging purposes, it is useful to have the ability to leave containers running.
* This mode can be activated by setting environment variable TESTCONTAINERS_RYUK_DISABLED=true
* After debugging, one can use this command to kill containers started by Testcontainers:
* docker ps -q --filter "label=org.testcontainers=true" | xargs -r docker kill
*/
public static final boolean LEAVE_CONTAINERS_RUNNING =
Boolean.parseBoolean(System.getenv("TESTCONTAINERS_RYUK_DISABLED"));

private final String hostname;
private final String serviceName;
private final String serviceEntryPoint;
Expand Down Expand Up @@ -109,6 +118,15 @@ protected void beforeStop() {
}
}

@Override
public void stop() {
if (LEAVE_CONTAINERS_RUNNING) {
log.warn("Ignoring stop since TESTCONTAINERS_RYUK_DISABLED=true.");
return;
}
super.stop();
}

@Override
public String getContainerName() {
return clusterName + "-" + hostname;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static com.google.common.base.Preconditions.checkArgument;
import static org.apache.pulsar.tests.integration.containers.PulsarContainer.BROKER_HTTP_PORT;
import static org.apache.pulsar.tests.integration.containers.PulsarContainer.CS_PORT;
import static org.apache.pulsar.tests.integration.containers.PulsarContainer.LEAVE_CONTAINERS_RUNNING;
import static org.apache.pulsar.tests.integration.containers.PulsarContainer.ZK_PORT;

import com.google.common.collect.Lists;
Expand Down Expand Up @@ -309,6 +310,10 @@ public PrestoWorkerContainer getPrestoWorkerContainer() {
}

public synchronized void stop() {
if (LEAVE_CONTAINERS_RUNNING) {
log.warn("Ignoring stop since TESTCONTAINERS_RYUK_DISABLED=true.");
return;
}

List<GenericContainer> containers = new ArrayList<>();

Expand Down

0 comments on commit a0fd5d8

Please sign in to comment.