Skip to content

test: Fix user pagination sort order #1143

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 2 commits into from
Apr 25, 2022
Merged

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Apr 25, 2022

Sort by uuid in expected output to cover when times are equal
for 2 users. The database (fake & pg) use id as as second ordering
to cover this edge case. Should realistically never happen in
production.

Emyrk added 2 commits April 25, 2022 09:36
Sort by uuid in expected output to cover when times are equal
for 2 users. The database (fake & pg) use id as as second ordering
to cover this edge case. Should realistically never happen in
production.
@Emyrk Emyrk requested a review from kylecarbs April 25, 2022 14:39
Copy link
Member

@kylecarbs kylecarbs left a comment

Choose a reason for hiding this comment

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

nit: Since the title is prefixed with test:, there's slight duplication in it with the suffix.

LGTM

func sortUsers(users []codersdk.User) {
sort.Slice(users, func(i, j int) bool {
if users[i].CreatedAt.Equal(users[j].CreatedAt) {
return users[i].ID.String() < users[j].ID.String()
Copy link
Member

Choose a reason for hiding this comment

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

Could we always just sort by UUID?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, because created_at ensures new users are always at the end meaning if you paginate by after_user, you are guaranteed to never miss a user even if one is inserted as you paginate.

If our uuids were strictly increasing, then yes.

The only reason I sort by (created_at, uuid) is to cover this small edge case of 2 users being created with the same time. Within 1 ms for postgres, and for the fake db it's a little more nuanced. Since we marshal over the API, our user's time's are not monotonic.


But tl'dr this fixes things in that edge case. In production, users will be sorted by time. Which is a good consistent ordering.

Copy link
Member

Choose a reason for hiding this comment

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

Ahh. Thank you for the explanation!

@codecov
Copy link

codecov bot commented Apr 25, 2022

Codecov Report

Merging #1143 (d817adb) into main (548de7d) will decrease coverage by 0.17%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main    #1143      +/-   ##
==========================================
- Coverage   66.58%   66.41%   -0.18%     
==========================================
  Files         255      261       +6     
  Lines       15743    16237     +494     
  Branches      152      156       +4     
==========================================
+ Hits        10482    10783     +301     
- Misses       4194     4346     +152     
- Partials     1067     1108      +41     
Flag Coverage Δ
unittest-go-macos-latest 53.83% <ø> (+0.54%) ⬆️
unittest-go-postgres- 65.80% <ø> (-0.12%) ⬇️
unittest-go-ubuntu-latest 56.28% <ø> (+0.20%) ⬆️
unittest-go-windows-2022 53.22% <ø> (+0.27%) ⬆️
unittest-js 67.28% <ø> (+0.45%) ⬆️
Impacted Files Coverage Δ
cli/gitssh.go 44.44% <0.00%> (-9.91%) ⬇️
cli/cliui/agent.go 77.19% <0.00%> (-5.27%) ⬇️
coderd/httpmw/apikey.go 81.30% <0.00%> (-3.05%) ⬇️
coderd/workspaceagents.go 59.62% <0.00%> (-2.97%) ⬇️
cli/ssh.go 36.76% <0.00%> (-2.61%) ⬇️
cli/agent.go 80.00% <0.00%> (-2.18%) ⬇️
provisionerd/provisionerd.go 77.74% <0.00%> (-1.67%) ⬇️
coderd/database/queries.sql.go 81.79% <0.00%> (-1.44%) ⬇️
codersdk/users.go 65.67% <0.00%> (-1.00%) ⬇️
provisioner/terraform/provision.go 70.96% <0.00%> (-0.44%) ⬇️
... and 29 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 548de7d...d817adb. Read the comment docs.

@Emyrk Emyrk changed the title test: Fix user pagination unit test test: Fix user pagination sort order Apr 25, 2022
@Emyrk Emyrk merged commit 8b54ea8 into main Apr 25, 2022
@Emyrk Emyrk deleted the stevenmasley/fix_paged_user_test branch April 25, 2022 15:27
@misskniss misskniss added this to the V2 Beta milestone May 15, 2022
kylecarbs pushed a commit that referenced this pull request Jun 10, 2022
Sort by uuid in expected output to cover when times are equal
for 2 users. The database (fake & pg) use id as as second ordering
to cover this edge case. Should realistically never happen in
production.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants