Skip to content

fix: use database for user creation to prevent flake #10992

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

Merged
merged 5 commits into from
Dec 4, 2023

Conversation

f0ssel
Copy link
Contributor

@f0ssel f0ssel commented Dec 1, 2023

After speaking with @Emyrk I moved the user creation of these tests to use the database directly to speed things up and do less http requests in order to stay under the 50 second timeout.

Closes #10978

@f0ssel
Copy link
Contributor Author

f0ssel commented Dec 1, 2023

Talked with @Emyrk and I'm gonna take a stab at speeding this test up, he had some ideas here.

@f0ssel f0ssel marked this pull request as draft December 1, 2023 17:51
@f0ssel f0ssel changed the title fix: prevent flake by increasing context deadline fix: prevent flake by using database instead of api for user creation Dec 1, 2023
@f0ssel f0ssel changed the title fix: prevent flake by using database instead of api for user creation fix: use database for user creation to prevent flake Dec 1, 2023
@f0ssel f0ssel marked this pull request as ready for review December 1, 2023 19:28
@f0ssel f0ssel requested a review from Emyrk December 1, 2023 19:29
@f0ssel
Copy link
Contributor Author

f0ssel commented Dec 1, 2023

I looked at the test data in CI and interestingly this test averages very fast, despite the comments in the code saying otherwise.
image

That being said, I still think if we are timing out at 50 seconds something on the CI box is running out of resources, and moving this to the database will still reduce the test startup burden for this test.

Copy link
Member

@Emyrk Emyrk left a comment

Choose a reason for hiding this comment

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

This is probably a good amount faster 👍

Comment on lines 1816 to 1818
for i := range allUsers[:limit] {
require.Equalf(t, page.Users[i].Username, allUsers[i].Username, "first page, limit=%d", limit)
}
Copy link
Member

Choose a reason for hiding this comment

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

I think the original comparisons are better since the new comparisons fail at the first instance, and do not show the lists and the list lengths in the failure output. Switching to assert feels like it might be spammy.

Can we just make a test helper func like:

func onlyUsernames[U codersdk.User | database.User](users []U) []string {
	var out []string
	for _, u := range users {
		switch u := (any(u)).(type) {
		case codersdk.User:
			out = append(out, u.Username)
		case database.User:
			out = append(out, u.Username)
		}
	}
	return out
}

Then we can bring back the old requires.

require.Equalf(t, onlyUsernames(page.Users), onlyUsernames(allUsers[:limit]), "first page, limit=%d", limit)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good to me, good idea. I have yet to really use generics, this will be fun.

Copy link
Member

Choose a reason for hiding this comment

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

It's a bit of a hack since I cast to any in the function 😄

It just gives type safety on the call arguments.

@f0ssel f0ssel requested a review from Emyrk December 4, 2023 14:03
@Emyrk
Copy link
Member

Emyrk commented Dec 4, 2023

I looked at the test data in CI and interestingly this test averages very fast, despite the comments in the code saying otherwise.

This is definitely subjective, but I think >100ms is on the slower side for our tests. Is it something to be concerned about? Idk, probably not.

@f0ssel f0ssel merged commit ccd5e1a into main Dec 4, 2023
@f0ssel f0ssel deleted the f0ssel/flake-test-paginated-users branch December 4, 2023 16:05
@github-actions github-actions bot locked and limited conversation to collaborators Dec 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

flake: TestPaginatedUsers
2 participants