Skip to content

Conversation

@zetter-rpf
Copy link

This attempts to fix an intermittent test failures in https://app.circleci.com/pipelines/github/RaspberryPiFoundation/editor-api/2939/workflows/789aa8a3-0910-4101-817d-a908c8fbcfa3/jobs/5584

Related unmerged attempt to fix: #600
Related previous attempt to fix: #579

I can't see anything in the code I think would cause the missing or additional records which makes me think it's likely to be a transactional/test cleanup issue.

What's changed?

  • Added logging to tell use the state of the database if test fails again
  • Changed database cleaner strategy to see if transactions are causing the issue

See commits for more details

Logs

The failing tests:

  1) for_education :seed_a_school_with_lessons_and_students adds two projects
     Failure/Error: expect(Project.where(lesson_id: lesson.pluck(:id)).length).to eq(2)
     
       expected: 2
            got: 4
     
       (compared using ==)
     # ./spec/lib/tasks/for_education_spec.rb:80:in `block (3 levels) in <top (required)>'
     # ./spec/rails_helper.rb:108:in `block (3 levels) in <top (required)>'
     # ./spec/rails_helper.rb:106:in `block (2 levels) in <top (required)>'

  2) test_seeds :seed_a_school_with_lessons_and_students creates a class teacher association for the teacher
     Failure/Error: expect(ClassTeacher.where(teacher_id:).length).to eq(1)
     
       expected: 1
            got: 0
     
       (compared using ==)
     # ./spec/lib/test_seeds_spec.rb:82:in `block (3 levels) in <top (required)>'
     # ./spec/rails_helper.rb:108:in `block (3 levels) in <top (required)>'
     # ./spec/rails_helper.rb:106:in `block (2 levels) in <top (required)>'

@cla-bot cla-bot bot added the cla-signed label Jan 19, 2026
@zetter-rpf zetter-rpf force-pushed the intermittent-seed-tests branch 2 times, most recently from e8f426c to 497f30a Compare January 19, 2026 16:03
@zetter-rpf zetter-rpf marked this pull request as ready for review January 20, 2026 10:00
This test has been intermittently failing. I want to see the details of the lessons in the database to see if there are clues as to where they might come from.
The database cleaner documentation warns that using a different database connection breaks the ability to use the transaction strategy. I thought it's possible this might be the cause for the intermittent test if rake tasks use a different process or connection.

I've also added logging in the previous commit so even if this doesn't fix the issue we may have other clues next time.
@zetter-rpf zetter-rpf force-pushed the intermittent-seed-tests branch from 497f30a to f9bd20c Compare January 20, 2026 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants