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 kubeexec unit test case with env vars #5845

Conversation

rm3l
Copy link
Member

@rm3l rm3l commented Jun 20, 2022

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

What does this PR do / why we need it:
Unit tests in pkg/remotecmd/kubeexec_test.go expect an exact command-line string to be passed when running commands in containers. The problem is that the environment variables are stored in a map, the iteration order of which is not guaranteed.

Initially reported in #5823 (comment)

Which issue(s) this PR fixes:

==================
--- FAIL: TestKubeExecProcessHandler_StartProcessForCommand (10.00s)
    --- FAIL: TestKubeExecProcessHandler_StartProcessForCommand/command_with_all_fields_returned_no_error (10.00s)
        remotecmd.go:36: Unexpected call to *kclient.MockClientInterface.ExecCMDInContainer([my-container my-pod [/bin/sh -c echo $$ > /opt/odo/.odo_devfile_cmd_my-exec-cmd.pid && cd /path/to/working/dir && export ENV_VAR2='value2' ENV_VAR1='value1' && (tail -f /path/to/a/file) 1>>/proc/1/fd/1 2>>/proc/1/fd/2] 0xc00047a030 0xc00047a040 <nil> false]) at /workspace/dcb6538f-a4d0-4109-85f2-86d8f7960de8/pkg/remotecmd/remotecmd.go:36 because: 
            expected call at /workspace/dcb6538f-a4d0-4109-85f2-86d8f7960de8/pkg/remotecmd/kubexec_test.go:185 doesn't match the argument at index 2.
            Got: [/bin/sh -c echo $$ > /opt/odo/.odo_devfile_cmd_my-exec-cmd.pid && cd /path/to/working/dir && export ENV_VAR2='value2' ENV_VAR1='value1' && (tail -f /path/to/a/file) 1>>/proc/1/fd/1 2>>/proc/1/fd/2]
            Want: is equal to [/bin/sh -c echo $$ > /opt/odo/.odo_devfile_cmd_my-exec-cmd.pid && cd /path/to/working/dir && export ENV_VAR1='value1' ENV_VAR2='value2' && (tail -f /path/to/a/file) 1>>/proc/1/fd/1 2>>/proc/1/fd/2]
        kubexec_test.go:219: timeout waiting for output handler to get called
        controller.go:137: missing call(s) to *kclient.MockClientInterface.ExecCMDInContainer(is equal to my-container, is equal to my-pod, is equal to [/bin/sh -c echo $$ > /opt/odo/.odo_devfile_cmd_my-exec-cmd.pid && cd /path/to/working/dir && export ENV_VAR1='value1' ENV_VAR2='value2' && (tail -f /path/to/a/file) 1>>/proc/1/fd/1 2>>/proc/1/fd/2], is anything, is anything, is anything, is anything) /workspace/dcb6538f-a4d0-4109-85f2-86d8f7960de8/pkg/remotecmd/kubexec_test.go:185
        controller.go:137: aborting test due to missing call(s)
        testing.go:1092: race detected during execution of test
    testing.go:1092: race detected during execution of test
FAIL
FAIL	[github.com/redhat-developer/odo/pkg/remotecmd](http://github.com/redhat-developer/odo/pkg/remotecmd)	16.453s

PR acceptance criteria:

  • Unit test

  • Integration test

  • Documentation

How to test changes / Special notes to the reviewer:
All tests in kubeexec_test.go should pass.

cc @feloy

Using a map for storing such data does not guarantee
an iteration order.
As we are matching an exact command-line string in the test,
we need to use a type that guarantees the iteration order.
@netlify
Copy link

netlify bot commented Jun 20, 2022

Deploy Preview for odo-docusaurus-preview canceled.

Name Link
🔨 Latest commit 8d0cd85
🔍 Latest deploy log https://app.netlify.com/sites/odo-docusaurus-preview/deploys/62b07af68d145c00080213b5

@openshift-ci openshift-ci bot added kind/tests area/testing Issues or PRs related to testing, Quality Assurance or Quality Engineering labels Jun 20, 2022
@openshift-ci openshift-ci bot requested review from dharmit and feloy June 20, 2022 13:49
@odo-robot
Copy link

odo-robot bot commented Jun 20, 2022

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

@odo-robot
Copy link

odo-robot bot commented Jun 20, 2022

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

@odo-robot
Copy link

odo-robot bot commented Jun 20, 2022

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

@odo-robot
Copy link

odo-robot bot commented Jun 20, 2022

Windows Tests (OCP) on commit c3c899f finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Jun 20, 2022

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

@rm3l rm3l closed this Jun 20, 2022
@rm3l rm3l reopened this Jun 20, 2022
@rm3l rm3l closed this Jun 20, 2022
@rm3l rm3l reopened this Jun 20, 2022
@feloy
Copy link
Contributor

feloy commented Jun 20, 2022

/approve

@openshift-ci
Copy link

openshift-ci bot commented Jun 20, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: feloy

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. Required by Prow. label Jun 20, 2022
@feloy
Copy link
Contributor

feloy commented Jun 20, 2022

Thanks @rm3l for the quick fix

@rm3l rm3l closed this Jun 20, 2022
@rm3l rm3l reopened this Jun 20, 2022
@sonarqubecloud
Copy link

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 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@feloy
Copy link
Contributor

feloy commented Jun 20, 2022

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. Required by Prow. label Jun 20, 2022
@feloy
Copy link
Contributor

feloy commented Jun 20, 2022

/override ci/prow/v4.10-integration-e2e

@openshift-ci
Copy link

openshift-ci bot commented Jun 20, 2022

@feloy: Overrode contexts on behalf of feloy: ci/prow/v4.10-integration-e2e

In response to this:

/override ci/prow/v4.10-integration-e2e

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.

@openshift-ci openshift-ci bot merged commit 7493e97 into redhat-developer:main Jun 20, 2022
@rm3l rm3l deleted the fix_flaky_kubeexec_unit_test_by_using_different_structure_for_envvars branch June 20, 2022 20:18
cdrage pushed a commit to cdrage/odo that referenced this pull request Aug 31, 2022
…eloper#5845)

Using a map for storing such data does not guarantee
an iteration order.
As we are matching an exact command-line string in the test,
we need to use a type that guarantees the iteration order.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. Required by Prow. area/testing Issues or PRs related to testing, Quality Assurance or Quality Engineering 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.

2 participants