Repository navigation
Fix 2191. Is is not running all services of a docker-compose, when a … #2250
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
70bce69
Fix 2191. Is is not running all services of a docker-compose, when a …
mnafshin e0427fc
Fix 2191. removed not useful extend of BaseDockerComposeTest for Dock…
mnafshin c486f56
Fix 2191. missing test condition for making sure only those services …
mnafshin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
core/src/test/java/org/testcontainers/junit/DockerComposeContainerWithServicesTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package org.testcontainers.junit; | ||
|
|
||
| import com.github.dockerjava.api.model.Container; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.testcontainers.containers.DockerComposeContainer; | ||
|
|
||
| import java.io.File; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
|
|
||
| import static org.rnorth.visibleassertions.VisibleAssertions.assertEquals; | ||
|
|
||
|
|
||
| public class DockerComposeContainerWithServicesTest { | ||
|
|
||
| private static final String[] listOfServices = new String[]{"redis"/*, "db"*/}; | ||
|
|
||
| @Rule | ||
| public DockerComposeContainer environment = new DockerComposeContainer(new File("src/test/resources/compose-test.yml")) | ||
| .withServices(listOfServices); | ||
|
|
||
| @Test | ||
| public void testGivenDockerCompose_WhenSublistOfServicesSelected_ThenOnlyThoseServicesAreStarted() { | ||
| Set<String> runningList = new HashSet<>(); | ||
|
|
||
| List<Container> list = environment.listChildContainers(); | ||
| for (Container container : list) { | ||
| for (String service : listOfServices) | ||
| if (container.getNames()[0].contains(service)) { | ||
| runningList.add(service); | ||
| } | ||
| } | ||
| assertEquals("number of running services of docker-compose is the same as length of listOfServices", | ||
| listOfServices.length, environment.listChildContainers().size()); | ||
| assertEquals("Running services are the same as the requested listOfServices", | ||
| listOfServices.length, runningList.size()); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uh?
servicesWithScalingSettingsalready includesservices:Stream.concat(services.stream(), ...Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is a misunderstanding of how scaling works in docker-compose
if you want to scale some services you must specify their scaling exactly like what is done in servicesWithScalingSettings. For example, it would be something like:
docker-compose up --scale redis=2
the misunderstanding is here: the previous command is do nothing different as the
docker-compose up
that brings up all services (only redis will have 2 instances)
But, if you want to bring up only some of the services (not all) one must specify the name of services. For example:
docker-compose up --scale redis=2 redis
this command will only brings up 2 instance of redis
or
docker-compose up --scale redis=2 redis db
this command will set up 2 instances of redis and 1 instance of db
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Damn, I've been looking at this for ages and every time failing to understand the issue.
The current implementation fails to limit the running services. My misunderstanding was thinking that it was failing to launch any containers which are in
withServicesbut not inwithScaledServices.Actually that is and always has been fine, but we're getting services launched that we do no want.
e.g. with a docker-compose.yml file like:
and
(taken from the test)
... we'd expect on
redisto come up, but actuallydbis launched too.The same goes for:
... we get 2
redis, plus onedbthat wasn't asked for.We should absolutely fix this.
@mnafshin thanks for the PR. I'd just like to add to the tests to ensure that we have coverage for:
withServicesis used (this is your existing test)withServicesandwithScaledServiceare both used togetherwithScaledServiceis used on its ownIf I can push to your branch I will do so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm glad I extended the test cases to be more comprehensive, because I've discovered some more ways this can break with different combinations of inputs.
Slightly bigger commit incoming 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that I don't have permission to push to @mnafshin's fork, so I've created a new PR: #2922
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want I can add you, but I think it is a little late, and you have made your own repo