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

Fix internal port check when other ports are opened as well on the target container #2363

Merged
merged 9 commits into from Mar 10, 2020

Conversation

codablock
Copy link
Contributor

This PR contains 2 commits. The first one is a trivial cleanup of a redundant execCreateCmd call. The second commit contains the actual fix. Description from the second commit:

Allow leading zeros in /proc/net/tcp* when doing internal port listen check

When at least one process is listening for a port that is significantly
higher then the port we're checking, this check will fail as the checked
port will contain leading zeros in the output of "cat /proc/net/tcp".

This commit fixes this by changing the grep to ":0*XXX".

@bsideup
Copy link
Member

bsideup commented Feb 18, 2020

Hi @codablock,

Could you please add tests for it?

@codablock
Copy link
Contributor Author

@bsideup I added 3 commits to this PR.

  1. A fix for the initial fix (I can later squash it into the original commit if you want)
  2. A refactoring of existing tests for InternalCommandPortListeningCheck
  3. A new test to test the fix. You can verify that it fails by reverting fix commit.

@codablock
Copy link
Contributor Author

Handled review comments. I also noticed that I forgot to commit an important change in nginx_on_8080.conf (port 100), which I fixed now and squashed into the original commit

@codablock
Copy link
Contributor Author

Test failures are not reproducible locally. And it's unfortunately the new test that fails, so it's likely related. It's also strange that they succeed on circleci. Any ideas?

@bsideup
Copy link
Member

bsideup commented Feb 19, 2020

@codablock I just triggered a re-run, let's see how it goes

@codablock
Copy link
Contributor Author

Tests failed again. But I think I found it: The check.call() is probably done slightly before nginx has started up, resulting in the test to fail. I added a commit that waits for up to 5 seconds for the check to pass.

@codablock
Copy link
Contributor Author

The port check tests are green now. Other test failures on Azure Pipelines are unrelated (Check failed: Docker environment should have more than 2GB free disk space)

@bsideup
Copy link
Member

bsideup commented Feb 24, 2020

@codablock it seems there was an issue with the disk space on Azure, I've submitted #2376 to fix it. Let's update your PR and do another run once that PR is merged to ensure that this change does not bring any side effects 👍

This one is never used and probably causes some garbage on the docker side.
… check

When at least one process is listening for a port that is significantly
higher then the port we're checking, this check will fail as the checked
port will contain leading zeros in the output of "cat /proc/net/tcp".

This commit fixes this by changing the grep to ":0*XXX".
Otherwise unnecessary shell expansion is tried
…ssible checks

This commit refactors InternalCommandPortListeningCheckTest to work with
3 different nginx based containers, each being able to only succeed one of
the 3 tests performed in InternalCommandPortListeningCheck. Each test is
now executed agains all 3 containers to ensure that all tests work as
expected.
This test should fail without the leading zeros fix found a few commits
before this one.
It's not only port 8080 anymore, so better not have it in the name.
@codablock
Copy link
Contributor Author

@bsideup rebased and force pushed to bring in #2376

@bsideup bsideup added this to the next milestone Feb 24, 2020
@bsideup bsideup merged commit b437227 into testcontainers:master Mar 10, 2020
@bsideup
Copy link
Member

bsideup commented Mar 10, 2020

@codablock merged, thanks! 🎉

@codablock codablock deleted the pr_fixes branch March 10, 2020 07:25
@rnorth
Copy link
Member

rnorth commented Apr 13, 2020

This was released in https://github.com/testcontainers/testcontainers-java/releases/tag/1.14.0 🎉

Thanks for the contribution!

quincy pushed a commit to quincy/testcontainers-java that referenced this pull request May 28, 2020
…rget container (testcontainers#2363)

* Remove redundant execCreateCmd call

This one is never used and probably causes some garbage on the docker side.

* Allow leading zeros in /proc/net/tcp* when doing internal port listen check

When at least one process is listening for a port that is significantly
higher then the port we're checking, this check will fail as the checked
port will contain leading zeros in the output of "cat /proc/net/tcp".

This commit fixes this by changing the grep to ":0*XXX".

* Surround grep parameter with '

Otherwise unnecessary shell expansion is tried

* Refactor/Rewrite InternalCommandPortListeningCheckTest to test all possible checks

This commit refactors InternalCommandPortListeningCheckTest to work with
3 different nginx based containers, each being able to only succeed one of
the 3 tests performed in InternalCommandPortListeningCheck. Each test is
now executed agains all 3 containers to ensure that all tests work as
expected.

* Add test for low+high ports

This test should fail without the leading zeros fix found a few commits
before this one.

* Check for bash existence instead of only mentioning it in a comment

* Rename nginx_on_8080.conf to nginx.conf

It's not only port 8080 anymore, so better not have it in the name.

* Make container a @rule again by moving initialization into contructor

* Wait a few seconds for InternalCommandPortListeningCheck to pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants