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 ports read/write races in neg tests #1837

Merged
merged 1 commit into from
Oct 15, 2022

Conversation

panslava
Copy link
Contributor

In general, I want to make all unit tests pass with -race, this is 1 step towards

Current approach with ports variable in neg tests has race, cause we use global variable, and we modify it from different tests

/assign swetharepakula
/assign cezarygerard
/cc code-elinka
/cc aojea

@k8s-ci-robot
Copy link
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 14, 2022
@k8s-ci-robot
Copy link
Contributor

@panslava: GitHub didn't allow me to request PR reviews from the following users: code-elinka.

Note that only kubernetes members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

In general, I want to make all unit tests pass with -race, this is 1 step towards

Current approach with ports variable in neg tests has race, cause we use global variable, and we modify it from different tests

/assign swetharepakula
/assign cezarygerard
/cc code-elinka
/cc aojea

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.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Oct 14, 2022
@panslava panslava marked this pull request as ready for review October 14, 2022 14:03
@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Oct 14, 2022
@aojea
Copy link
Member

aojea commented Oct 14, 2022

why not removing t.Parallel() from the tests that share the variable?

@panslava
Copy link
Contributor Author

why not removing t.Parallel() from the tests that share the variable?

Do you think it is better? I feel like running tests in parallel can be good to find some weird errors (like these global variables, but not in real code), that we would never found if we ran everything single threaded

@aojea
Copy link
Member

aojea commented Oct 14, 2022

Do you think it is better? I feel like running tests in parallel can be good to find some weird errors (like these global variables, but not in real code), that we would never found if we ran everything single threaded

in this case is a design choice , if you have a global variable to share in multiple test is a conscious decision, what is important though is to run with -race , we should always enable the race detector, t.Parallel() is more an optimisation to me ... but I can be wrong on this, of course

@panslava
Copy link
Contributor Author

Do you think it is better? I feel like running tests in parallel can be good to find some weird errors (like these global variables, but not in real code), that we would never found if we ran everything single threaded

in this case is a design choice , if you have a global variable to share in multiple test is a conscious decision, what is important though is to run with -race , we should always enable the race detector, t.Parallel() is more an optimisation to me ... but I can be wrong on this, of course

Tbh this tests were written not by me, but this global variable is actually not intended to be shared between tests (in the way that there is no shared logic based on this variable), as I understand, this is just some useful “const”

@aojea
Copy link
Member

aojea commented Oct 14, 2022

And are the test modifying the variable?

@panslava
Copy link
Contributor Author

And are the test modifying the variable?

They do modify, but only for their own usage, like if they understand default const is not enough, they will append to it something extra

ports = append(

@aojea
Copy link
Member

aojea commented Oct 15, 2022

Oh, that is wrong thenz, it will pollute all the other tests

@panslava
Copy link
Contributor Author

Oh, that is wrong thenz, it will pollute all the other tests

So that’s what I am trying to fix in this PR, at first, I am taking a copy of this global ports, and then modify only copy

@aojea
Copy link
Member

aojea commented Oct 15, 2022

What do you think about using a function instead?
It is more intuitive and less error prone to avoid similar issues in the future

func servicePorts() []apiv1.ServicePort

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Oct 15, 2022
@panslava
Copy link
Contributor Author

What do you think about using a function instead? It is more intuitive and less error prone to avoid similar issues in the future

func servicePorts() []apiv1.ServicePort

thanks! good suggestion! changed

@aojea
Copy link
Member

aojea commented Oct 15, 2022

/lgtm

Thanks

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 15, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aojea, panslava

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

@k8s-ci-robot k8s-ci-robot merged commit e1a0fe4 into kubernetes:master Oct 15, 2022
@aojea
Copy link
Member

aojea commented Oct 15, 2022

why don't you send a PR enabling the race detector and adding a commit per fix?

this way is easier to review and to fix

@panslava
Copy link
Contributor Author

@aojea the problem is, there are other tests that are failing race detector, so I can not enable it yet... and other tests are harder to fix (at least not as obvious)

@panslava
Copy link
Contributor Author

or you suggesting something else? Maybe I didn't understand completely the suggestion

@aojea
Copy link
Member

aojea commented Oct 15, 2022

#1838

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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants