Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

appliance: fix test flakiness when container env vars are specified#62732

Merged
craigfurman merged 1 commit into
mainfrom
appliance-fix-deterministic-tests
May 16, 2024
Merged

appliance: fix test flakiness when container env vars are specified#62732
craigfurman merged 1 commit into
mainfrom
appliance-fix-deterministic-tests

Conversation

@craigfurman

Copy link
Copy Markdown
Contributor

Since introducing the standard feature for container env vars in https://github.com/sourcegraph/sourcegraph/pull/62624, some test flakiness has been introduced. This is because container.go was iterating through an unsorted map, which made golden file assertions non-deterministic. This is fixed by sorting the map keys when appending user-provided env vars.

Test plan

Ran go test -count=10 -failfast ./internal/appliance and it passed. Before this commit, 10 runs would reliably tease out the flake.

Since introducing the standard feature for container env vars in
https://github.com/sourcegraph/sourcegraph/pull/62624, some test
flakiness has been introduced. This is because container.go was
iterating through an unsorted map, which made golden file assertions
non-deterministic. This is fixed by sorting the map keys when appending
user-provided env vars.
@craigfurman craigfurman requested review from a team and jdpleiness May 16, 2024 15:26
@cla-bot cla-bot Bot added the cla-signed label May 16, 2024
for k, v := range ctrConfig.EnvVars {
ctr.Env = append(ctr.Env, corev1.EnvVar{Name: k, Value: v})
}
ctr.Env = append(ctr.Env, newSortedEnvVars(ctrConfig.EnvVars)...)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I thought about replacing this with something that generically returns sorted map entries from the maps package, but erred on the side of quick-and-simple here. We'd have to write a generic sort.Interface implementation to accomplish that, and since we're only ever operating on string keys in this package, sort.Strings() was sitting right there...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I ran into something similar to this in the POC as well but handled it in the resource level: https://github.com/sourcegraph/sourcegraph-operator/blob/main/internal/controller/resource/container/container.go#L87

@craigfurman craigfurman enabled auto-merge (squash) May 16, 2024 15:35

@jdpleiness jdpleiness left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good, just comments 😄

for k, v := range ctrConfig.EnvVars {
ctr.Env = append(ctr.Env, corev1.EnvVar{Name: k, Value: v})
}
ctr.Env = append(ctr.Env, newSortedEnvVars(ctrConfig.EnvVars)...)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I ran into something similar to this in the POC as well but handled it in the resource level: https://github.com/sourcegraph/sourcegraph-operator/blob/main/internal/controller/resource/container/container.go#L87

@craigfurman craigfurman merged commit 072a84b into main May 16, 2024
@craigfurman craigfurman deleted the appliance-fix-deterministic-tests branch May 16, 2024 17:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants