-
Notifications
You must be signed in to change notification settings - Fork 244
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 flaky unit Test_getCompleteCustomPortPairs #6737
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ func Test_getCompleteCustomPortPairs(t *testing.T) { | |
args: args{ | ||
definedPorts: []api.ForwardedPort{ | ||
{ContainerName: "runtime", LocalPort: 8080, ContainerPort: 8000}, | ||
{ContainerName: "tools", LocalPort: 5000, ContainerPort: 5000}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously, there were 2 non-customized ports, and a random value was assigned to 5000 and 9000 from time to time, sometimes 20001 would be assigned to 5000 and 20002 to 9000 and vice versa. Adding 5000 to the definedPorts will help avoid this flake while also maintaining the test integrity. |
||
}, | ||
ceMapping: map[string][]v1alpha2.Endpoint{ | ||
"runtime": {{TargetPort: 8000}, {TargetPort: 9000}}, | ||
|
@@ -31,7 +32,7 @@ func Test_getCompleteCustomPortPairs(t *testing.T) { | |
}, | ||
wantPortPairs: map[string][]string{ | ||
"runtime": {"8080:8000", "20001:9000"}, | ||
"tools": {"20002:5000"}, | ||
"tools": {"5000:5000"}, | ||
}, | ||
}, | ||
{ | ||
|
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 noticed that all the test cases here are relying on opening actual ports and expecting exact ports. But if I already have some other apps listening on those ports, then the test would fail.
I ran into this issue because I had unrelated
odo dev
sessions running and taking ports 20001 through 20003, and the test is now failing:Ideally, the unit test should not have to open any actual port, but I understand this is exactly what we are trying to test here. So I'd suggest relaxing the checks, by just checking that the port pairs we are getting in response are just within the range we expect. What do you think?
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.
In the other hand, this solution will hide the problem raised in #6741: I think we want to have the same local ports every time we work on a Devfile with several ports to forward. Without fixing
#6741, local ports will differ from one run to another.
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.
We do, but that is why we are defining custom port mapping. For ports that we do not define a custom mapping, there will always be a chance that you get a different port number every time, so perhaps it does make sense that we only check the port range instead of the exact value. Although we still want to ensure it does not assign the same port number more than once, I can add an additional check for that.
Regardless of how we test, I agree that we can still loop over the containers in an orderly manner.
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 agree with ensuring we have the same local ports. As Parthvi said, that should be okay, I think, for custom ports.
Overall, my main concern is more on how those unit tests are depending on the ports opened on the system.. So I'd need to make sure I don't have any other unrelated application listening on the local ports expected..
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.
FYI, I reverted the entire commit (fb31c33), which means current files do not contain the relaxed checks. I shall revert it again once we have a consensus.
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.
Whoops, just noticed this PR got merged already. Alright, let's see if this becomes annoying on a daily basis..