libnetwork/iptables: Fix test panic when execute only one test#43384
Conversation
|
Thank you for contributing! It appears your commit message is missing a DCO sign-off, We require all commit messages to have a There is no need to open a new pull request, but to fix this (and make CI pass), You can find some instructions in the output of the DCO check (which can be found Steps to do so "roughly" come down to:
Sorry for the hassle; let me know if you need help or more detailed instructions! |
4d12217 to
eddedb8
Compare
|
Hi @thaJeztah sorry for that, I updated. |
corhere
left a comment
There was a problem hiding this comment.
Thank you so much for fixing up these tests! I just have one question before approving.
| 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) | ||
| } |
There was a problem hiding this comment.
How come the chains have to be programmed a second time? Why aren't the ProgramChain calls inside createNewChain sufficient?
There was a problem hiding this comment.
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.
6f1d6f3 to
3a88a02
Compare
Codecov Report
@@ 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 |
| iptable, natChain, _, err := createNewChain() | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } |
There was a problem hiding this comment.
Perhaps we can make createNewChain() a t.Helper() then we can skip all the "per test" error handling.
There was a problem hiding this comment.
Thanks @thaJeztah , that looks a lot cleaner in the code!
bfd78ed to
1e8e0c6
Compare
- use local variables for chains instead of sharing global variables - make createNewChain a t.Helper Signed-off-by: Chee Hau Lim <[email protected]>
1e8e0c6 to
a2cea99
Compare
thaJeztah
left a comment
There was a problem hiding this comment.
LGTM!
Thanks so much (was about to ask if you needed help with squashing, but I see you managed to do so ❤️)
fixes #42696
- What I did
The test paniced when executing individually is because they are sharing some same variables (
natChain,filterChain, andbridgeName), 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:
- Description for the changelog
Fix iptables tests