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 flaky unit Test_getCompleteCustomPortPairs #6737

Conversation

valaparthvi
Copy link
Contributor

@valaparthvi valaparthvi commented Apr 13, 2023

What type of PR is this:
/area testing
/kind flake

What does this PR do / why we need it:
This fixes flaky test.

Which issue(s) this PR fixes:

Fixes part of #6479
Fixes #6741

PR acceptance criteria:

  • Unit test

  • Integration test

  • Documentation

How to test changes / Special notes to the reviewer:

Signed-off-by: Parthvi Vala <pvala@redhat.com>
@netlify
Copy link

netlify bot commented Apr 13, 2023

Deploy Preview for odo-docusaurus-preview canceled.

Name Link
🔨 Latest commit 5afb86b
🔍 Latest deploy log https://app.netlify.com/sites/odo-docusaurus-preview/deploys/643d6174784ffe000837cf01

@openshift-ci openshift-ci bot added area/testing Issues or PRs related to testing, Quality Assurance or Quality Engineering flake Categorizes issue or PR as related to a flaky test. labels Apr 13, 2023
@openshift-ci openshift-ci bot requested review from anandrkskd and rm3l April 13, 2023 17:10
@odo-robot
Copy link

odo-robot bot commented Apr 13, 2023

OpenShift Unauthenticated Tests on commit f21b63a finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Apr 13, 2023

NoCluster Tests on commit f21b63a finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Apr 13, 2023

Unit Tests on commit f21b63a finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Apr 13, 2023

Validate Tests on commit f21b63a finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Apr 13, 2023

Kubernetes Tests on commit f21b63a finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Apr 13, 2023

Windows Tests (OCP) on commit f21b63a finished with errors.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Apr 13, 2023

Kubernetes Docs Tests on commit 7a72134 finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Apr 13, 2023

OpenShift Tests on commit f21b63a finished successfully.
View logs: TXT HTML

@valaparthvi valaparthvi reopened this Apr 14, 2023
@@ -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},
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

@valaparthvi
Copy link
Contributor Author

OC Failure:

  [FAILED] Timed out after 180.000s.
  Expected process to exit.  It did not.
  In [AfterEach] at: /go/odo_1/tests/helper/helper_dev.go:211 @ 04/14/23 05:41:57.43
------------------------------

Summarizing 1 Failure:
  [FAIL] odo dev command tests when Starting a PostgreSQL service when creating local files and dir and running odo dev - without metadata.name [AfterEach] when deleting local files and dir and waiting for sync should not list deleted dir and file in container
  /go/odo_1/tests/helper/helper_dev.go:211

Windows Failure:

  [FAILED] No future change is possible.  Bailing out early after 1.332s.
  Running oc.exe with args [oc get pods -n interactive-add-binding-test577amu -o jsonpath='{range .items[*]}{.metadata.name}'] and odo env: []
  Expected
      <int>: 1
  to match exit code:
      <int>: 0

  [FAILED] No future change is possible.  Bailing out early after 1.192s.
  Running oc.exe with args [oc exec nxbmst-app-7b69cff74b-9m7wl --namespace cmd-dev-test1738lfs -- ls -lai /projects/webapp] and odo env: []
  Expected
      <int>: 1
  to match exit code:
      <int>: 0

  [FAILED] No future change is possible.  Bailing out early after 21.166s.
  Running oc.exe with args [oc create configmap config-map-for-cleanup --from-literal type=testing --from-literal team=odo -n cmd-delete-test625lsx] and odo env: []
  Expected
      <int>: 1
  to match exit code:
      <int>: 0
  In [BeforeEach] at: C:/Users/Administrator.ANSIBLE-TEST-VS/3699/tests/helper/helper_cmd_wrapper.go:101 @ 04/14/23 00:19:16.65


Summarizing 3 Failures:
  [FAIL] odo delete command tests [BeforeEach] when a component is bootstrapped when the component is running in both DEV and DEPLOY mode and dev mode is killed when the component is deleted while having access to the devfile.yaml should delete the appropriate resources
  C:/Users/Administrator.ANSIBLE-TEST-VS/3699/tests/helper/helper_cmd_wrapper.go:101
  [FAIL] odo add binding interactive command tests [BeforeEach] when running a deployment when binding to a service in a different namespace should error out if service is not found in the namespace selected
  C:/Users/Administrator.ANSIBLE-TEST-VS/3699/tests/helper/helper_generic.go:58
  [FAIL] odo dev command tests when multiple projects are present - with metadata.name [It] should sync to the correct dir in container
  C:/Users/Administrator.ANSIBLE-TEST-VS/3699/tests/helper/helper_cmd_wrapper.go:101

Ran 437 of 805 Specs in 1189.646 seconds
FAIL! -- 434 Passed | 3 Failed | 0 Pending | 368 Skipped

@valaparthvi valaparthvi reopened this Apr 14, 2023
Copy link
Member

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:

--- FAIL: Test_getCompleteCustomPortPairs (0.00s)                                                                                                                                                                   
    --- FAIL: Test_getCompleteCustomPortPairs/ports_are_provided_with_container_name (0.00s)                                                                                                                        
        portForward_test.go:78: getCompleteCustomPortPairs() (got vs want) diff =   map[string][]string{                                                                                                            
                "runtime": {                                                                                                                                                                                        
                        "8080:8000",                                                                                                                                                                                
            -           "20004:9000",                                                                                                                                                                               
            +           "20001:9000",                                                                                                                                                                               
                },                                                                                                                                                                                                  
                "tools": {"5000:5000"},                                                                                                                                                                             
              }                                                                                                                                                                                                     
    --- FAIL: Test_getCompleteCustomPortPairs/ports_are_provided_without_container_name (0.00s)                                                                                                                     
        portForward_test.go:78: getCompleteCustomPortPairs() (got vs want) diff =   map[string][]string{                                                                                                            
                "runtime": {                                                                                                                                                                                        
                        "8080:8000",                                                                                                                                                                                
            -           "20004:9000",                                                                                                                                                                               
            +           "20001:9000",
                },
                "tools": {"5000:5000"},
              }
    --- FAIL: Test_getCompleteCustomPortPairs/local_ports_in_range_[20001-30001]_are_provided_as_custom_forward_ports (0.00s)
        portForward_test.go:78: getCompleteCustomPortPairs() (got vs want) diff =   map[string][]string{
                "runtime": {"20001:8000", "20002:9000"},
                "tools": {
                        "5000:5000",
            -           "20004:8080",
            +           "20003:8080",
                },
              }

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?

Copy link
Contributor

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:

--- FAIL: Test_getCompleteCustomPortPairs (0.00s)                                                                                                                                                                   
    --- FAIL: Test_getCompleteCustomPortPairs/ports_are_provided_with_container_name (0.00s)                                                                                                                        
        portForward_test.go:78: getCompleteCustomPortPairs() (got vs want) diff =   map[string][]string{                                                                                                            
                "runtime": {                                                                                                                                                                                        
                        "8080:8000",                                                                                                                                                                                
            -           "20004:9000",                                                                                                                                                                               
            +           "20001:9000",                                                                                                                                                                               
                },                                                                                                                                                                                                  
                "tools": {"5000:5000"},                                                                                                                                                                             
              }                                                                                                                                                                                                     
    --- FAIL: Test_getCompleteCustomPortPairs/ports_are_provided_without_container_name (0.00s)                                                                                                                     
        portForward_test.go:78: getCompleteCustomPortPairs() (got vs want) diff =   map[string][]string{                                                                                                            
                "runtime": {                                                                                                                                                                                        
                        "8080:8000",                                                                                                                                                                                
            -           "20004:9000",                                                                                                                                                                               
            +           "20001:9000",
                },
                "tools": {"5000:5000"},
              }
    --- FAIL: Test_getCompleteCustomPortPairs/local_ports_in_range_[20001-30001]_are_provided_as_custom_forward_ports (0.00s)
        portForward_test.go:78: getCompleteCustomPortPairs() (got vs want) diff =   map[string][]string{
                "runtime": {"20001:8000", "20002:9000"},
                "tools": {
                        "5000:5000",
            -           "20004:8080",
            +           "20003:8080",
                },
              }

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?

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we want to have the same local ports every time we work on a Devfile with several ports to forward.

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.

Copy link
Member

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.

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..

Copy link
Contributor Author

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.

Copy link
Member

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..

@rm3l rm3l added this to the v3.10.0 🚀 milestone Apr 17, 2023
Signed-off-by: Parthvi Vala <pvala@redhat.com>
This reverts commit 1bcbacf.
Signed-off-by: Parthvi Vala <pvala@redhat.com>
@valaparthvi valaparthvi reopened this Apr 18, 2023
@sonarcloud
Copy link

sonarcloud bot commented Apr 18, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.3% 0.3% Duplication

@valaparthvi
Copy link
Contributor Author

/override windows-integration-test/Windows-test

@openshift-ci
Copy link

openshift-ci bot commented Apr 18, 2023

@valaparthvi: Overrode contexts on behalf of valaparthvi: windows-integration-test/Windows-test

In response to this:

/override windows-integration-test/Windows-test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@valaparthvi valaparthvi requested review from rm3l and feloy April 18, 2023 13:20
@feloy
Copy link
Contributor

feloy commented Apr 18, 2023

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. Required by Prow. label Apr 18, 2023
@openshift-merge-robot openshift-merge-robot merged commit 912f6d1 into redhat-developer:main Apr 18, 2023
@rm3l rm3l removed this from the v3.10.0 🚀 milestone May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/testing Issues or PRs related to testing, Quality Assurance or Quality Engineering flake Categorizes issue or PR as related to a flaky test. lgtm Indicates that a PR is ready to be merged. Required by Prow.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Flaky unit test
4 participants