Skip to content

libnetwork/iptables: Fix test panic when execute only one test#43384

Merged
corhere merged 1 commit into
moby:masterfrom
ch33hau:42696-panic-test
Nov 17, 2022
Merged

libnetwork/iptables: Fix test panic when execute only one test#43384
corhere merged 1 commit into
moby:masterfrom
ch33hau:42696-panic-test

Conversation

@ch33hau
Copy link
Copy Markdown
Contributor

@ch33hau ch33hau commented Mar 15, 2022

fixes #42696

- What I did
The test paniced when executing individually is because they are sharing some same variables (natChain, filterChain, and bridgeName), these variables only initiated on the first test.

- How I did it
This PR moves the shared variables to local variables and initiates them within every test.

- How to verify it
Run a single test:

go test -run TestConcurrencyWithWait github.com/docker/docker/libnetwork/iptables

- Description for the changelog
Fix iptables tests

@thaJeztah
Copy link
Copy Markdown
Member

Thank you for contributing! It appears your commit message is missing a DCO sign-off,
causing the DCO check to fail.

We require all commit messages to have a Signed-off-by line with your name
and e-mail (see "Sign your work" in the CONTRIBUTING.md in this repository),
which looks something like:

Signed-off-by: YourFirsName YourLastName <[email protected]>

There is no need to open a new pull request, but to fix this (and make CI pass),
you need to amend the commit(s) in this pull request, and "force push" the amended
commit.

You can find some instructions in the output of the DCO check (which can be found
in the "checks" tab on this pull request), as well as in the Moby contributing guide.

Steps to do so "roughly" come down to:

  1. Set your name and e-mail in git's configuration:

    git config --global user.name "YourFirstName YourLastName"
    git config --global user.email "[email protected]"

    (Make sure to use your real name (not your GitHub username/handle) and e-mail)

  2. Clone your fork locally

  3. Check out the branch associated with this pull request

  4. Sign-off and amend the existing commit(s)

    git commit --amend --no-edit --signoff

    If your pull request contains multiple commits, either squash the commits (if
    needed) or sign-off each individual commit.

  5. Force push your branch to GitHub (using the --force or --force-with-lease flags) to update the pull request.

Sorry for the hassle; let me know if you need help or more detailed instructions!

@thaJeztah thaJeztah added status/2-code-review dco/no Automatically set by a bot when one of the commits lacks proper signature area/networking Networking area/testing labels Mar 15, 2022
@ch33hau
Copy link
Copy Markdown
Contributor Author

ch33hau commented Mar 16, 2022

Hi @thaJeztah sorry for that, I updated.

@corhere corhere removed the dco/no Automatically set by a bot when one of the commits lacks proper signature label Oct 27, 2022
Copy link
Copy Markdown
Contributor

@corhere corhere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for fixing up these tests! I just have one question before approving.

Comment thread libnetwork/iptables/iptables_test.go Outdated
Comment on lines +218 to +226
err = iptable.ProgramChain(natChain, bridgeName, false, true)
if err != nil {
t.Fatal(err)
}

err = iptable.ProgramChain(filterChain, bridgeName, false, true)
if err != nil {
t.Fatal(err)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come the chains have to be programmed a second time? Why aren't the ProgramChain calls inside createNewChain sufficient?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @corhere , thanks for reviewing!

Thanks for catching this, I can't see any reasons why they are needed, it should be my mistake. I have removed them.

@corhere corhere changed the title Fix test panic when execute only one test libnetwork/iptables: Fix test panic when execute only one test Nov 10, 2022
@ch33hau ch33hau force-pushed the 42696-panic-test branch 2 times, most recently from 6f1d6f3 to 3a88a02 Compare November 14, 2022 02:26
Copy link
Copy Markdown
Contributor

@corhere corhere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 14, 2022

Codecov Report

Merging #43384 (3a88a02) into master (ef5b279) will increase coverage by 0.00%.
The diff coverage is n/a.

❗ Current head 3a88a02 differs from pull request most recent head a2cea99. Consider uploading reports for the commit a2cea99 to get more accurate results

@@           Coverage Diff            @@
##           master   #43384    +/-   ##
========================================
  Coverage   31.07%   31.08%            
========================================
  Files         642      645     +3     
  Lines       65708    65579   -129     
========================================
- Hits        20421    20383    -38     
+ Misses      43387    43299    -88     
+ Partials     1900     1897     -3     

Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left one suggestion; I was writing along, and opened a PR against your branch with my suggestions; ch33hau#1

Comment thread libnetwork/iptables/iptables_test.go Outdated
Comment on lines +150 to +153
iptable, natChain, _, err := createNewChain()
if err != nil {
t.Fatal(err)
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we can make createNewChain() a t.Helper() then we can skip all the "per test" error handling.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @thaJeztah , that looks a lot cleaner in the code!

@ch33hau ch33hau force-pushed the 42696-panic-test branch 2 times, most recently from bfd78ed to 1e8e0c6 Compare November 15, 2022 13:06
- use local variables for chains instead of sharing global variables
- make createNewChain a t.Helper

Signed-off-by: Chee Hau Lim <[email protected]>
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Thanks so much (was about to ask if you needed help with squashing, but I see you managed to do so ❤️)

@corhere corhere merged commit 4651269 into moby:master Nov 17, 2022
@thaJeztah thaJeztah added this to the v-next milestone Nov 17, 2022
@ch33hau ch33hau deleted the 42696-panic-test branch November 18, 2022 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

panic in TestConcurrencyWithWait

3 participants