Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when running multiple junit test classes, getting error "A docker instance is starting or already started" #101

Open
assafcoh opened this issue Mar 22, 2023 · 0 comments

Comments

@assafcoh
Copy link

assafcoh commented Mar 22, 2023

To test our opensearch cluster functionality we have many Junit 5 tests using localstack-utils annotations as below.

@ExtendWith(LocalstackDockerExtension.class)
@LocalstackDockerProperties(portEdge = "3000", portElasticSearch = "3100", services = { ServiceName.S3, ServiceName.ELASTICSEARCH_SERVICE })
@ExtendWith(SpringExtension.class)
public class MyOpenSearchTest {
...
}

Everything works fine when running the junit tests one by one.
However, since we have many test classes and it takes ~1 minute for the docker container to startup, we tried to speed up overall test duration by doing the following:

  1. use a different portEdge and portElasticSearch in @LocalstackDockerProperties for each junit test class
  2. we enabled parralel junit tets execution by adding the lines below to file /resources/junit-platform.properties
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.config.dynamic.factor = 1

With the above chganges, the junit tests are started in parallel but we get this error:

java.lang.IllegalStateException: A docker instance is starting or already started.

	at cloud.localstack.Localstack.startup(Localstack.java:67)
	at cloud.localstack.docker.LocalstackDockerExtension$StartedLocalStack.<init>(LocalstackDockerExtension.java:57)
	at cloud.localstack.docker.LocalstackDockerExtension.beforeAll(LocalstackDockerExtension.java:42)
	at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$invokeBeforeAllCallbacks$7(ClassTestDescriptor.java:358)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
	at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.invokeBeforeAllCallbacks(ClassTestDescriptor.java:358)
	at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.before(ClassTestDescriptor.java:197)
	at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.before(ClassTestDescriptor.java:74)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:102)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:95)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:71)
	at org.junit.platform.engine.support.hierarchical.ForkJoinPoolHierarchicalTestExecutorService$ExclusiveTask.compute(ForkJoinPoolHierarchicalTestExecutorService.java:169)
	at java.base/java.util.concurrent.RecursiveAction.exec(RecursiveAction.java:194)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:387)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1311)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1840)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1806)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:177)

we are using this dependency:

<dependency>
  <groupId>cloud.localstack</groupId>
  <artifactId>localstack-utils</artifactId>
  <version>0.2.22</version>
  <scope>test</scope>
</dependency>

How can we run these Junit tests in parallel without getting this error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant