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

Serialize unit test to prevent flaky failures #2394

Merged
merged 1 commit into from
Jun 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion exp/api/v1beta1/azuremachinepool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func TestAzureMachinePool_Validate(t *testing.T) {
for _, c := range cases {
c := c
t.Run(c.Name, func(t *testing.T) {
t.Parallel()
// Don't add t.Parallel() here or the test will fail.
// NOTE: AzureMachinePool is behind MachinePool feature gate flag; the web hook
// must prevent creating new objects in case the feature flag is disabled.
defer utilfeature.SetFeatureGateDuringTest(t, feature.Gates, capifeature.MachinePool, true)()
Copy link
Contributor

Choose a reason for hiding this comment

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

could this defer be run before the test cases and not in the loop so it is set for all following runs? then removed when this set of cases are done?

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 tried that (the pattern used in azuremachinepool_webhook_test.go) but it still fails with t.Parallel() in the loop. So this PR represents the smallest change needed.

I think it is telling that none of our other uses of defer utilfeature.SetFeatureGateDuringTest use t.Parallel(), nor do the related unit tests in kubernetes/component-base.

Expand Down