test(assessments): fix flaky title-sort tests via DB collation - #1378
Draft
RichDom2185 wants to merge 1 commit into
Draft
test(assessments): fix flaky title-sort tests via DB collation#1378RichDom2185 wants to merge 1 commit into
RichDom2185 wants to merge 1 commit into
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
RichDom2185
marked this pull request as draft
August 1, 2026 12:42
sayomaki
force-pushed
the
fix-flaky-submission-sort-test
branch
from
August 11, 2026 05:27
7b04348 to
98c4498
Compare
The submissions_by_grader_for_index title-sort tests re-checked ordering with Elixir's binary string comparison, but the query sorts by `upper(title)` using PostgreSQL's locale collation. The two disagree on how spaces and punctuation sort relative to letters, so the randomly generated Hamlet-quote titles intermittently failed the assertion (e.g. "I will speak daggers to her, but use none." vs "In my mind's eye."). Assert the returned order against the database's own sort of the same titles instead, comparing `upper(title)` on both sides so the check is deterministic and consistent with the query under any collation.
sayomaki
force-pushed
the
fix-flaky-submission-sort-test
branch
from
August 11, 2026 13:32
98c4498 to
14fb7d1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
submissions_by_grader_for_indextitle-sort tests are flaky. On PR #1377's CI they failed with:Root cause
The query sorts by
upper(title)in the database, which uses PostgreSQL's locale collation:The tests then re-checked the returned order with Elixir's binary string comparison (
assert x.title >= y.title). The two disagree on how spaces and punctuation sort relative to letters — e.g. PostgreSQL's collation orders"In my mind's eye."before"I will speak daggers to her, but use none."(ignoring the space), whereas Elixir's binary comparison does the opposite (space0x20<n).Assessment titles are randomly generated Hamlet quotes (
Faker.Lorem.Shakespeare.En.hamlet()), and Faker is not seeded, so whenever a run happened to produce two titles straddling this boundary, the test failed. Only the title sort tests are affected (type/xp sort by integers).String.upcase/1alone would not fix it — the failing pair are both already uppercase-initial.Fix
Assert the returned order against the database's own sort of the same titles, comparing
upper(title)on both sides. This makes the check deterministic and consistent with the query under any collation, and it now verifies the full ordering rather than only that the first element is the extremum.Verified locally: the helper passes for the DB-correct order (which the old binary check would have wrongly rejected) and fails for a reversed order. Ran the two tests across multiple random seeds and the full
assessments_test.exs(90 tests) — all green.Note
Stacked on #1377 (
fix-course-creation-500) since it is unrelated to that course-creation fix. GitHub will retarget this PR tomasteronce #1377 merges.🤖 Generated with Claude Code