Skip to content

Conversation

@danhalson
Copy link
Contributor

Status

Ready to review

What's changed?

Fix to resolve the flakey seed test by ensuring different ids are used

Steps to perform after deploying to production

N/A

@cla-bot cla-bot bot added the cla-signed label Oct 1, 2025
@danhalson danhalson self-assigned this Oct 1, 2025
Comment on lines 8 to 12
let(:creator_id) { 'f83ba872-b16e-46e1-9f7d-df89d267550d' }
let(:teacher_id) { 'ccc9b8fd-f357-4238-983d-6f87b99bdbb2' }
let(:student_1) { 'e52de409-9210-4e94-b08c-dd11439e07d9' } # jane.smith from SeedsHelper
let(:student_2) { '0d488bec-b10d-46d3-b6f3-4cddf5d90c71' } # john.smith from SeedsHelper
let(:school_id) { 'e52de409-9210-4e94-b08c-dd11439e07d9' } # Use TEST_SCHOOL value so destroy works
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I fully follow why changing the id fixes the flakiness?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah good spot...I did this ages ago, but I'm pretty sure it was another attempt to ensure the data between runs doesn't bleed

Comment on lines +28 to +30
ClimateControl.modify SEEDING_CREATOR_ID: creator_id, SEEDING_TEACHER_ID: teacher_id do
task.invoke
end
Copy link
Contributor

@loiswells97 loiswells97 Oct 27, 2025

Choose a reason for hiding this comment

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

Does this mean these values weren't getting picked up before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

they were getting picked up, but state was bleeding between tests

Copy link
Contributor

Choose a reason for hiding this comment

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

not sure I understand how this fixes the bleed in that case 🤔

let(:school) { School.find_by(creator_id:) }

before do
Rake::Task['for_education:destroy_seed_data'].invoke
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this no longer needed? Or was it never needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it shouldn't have been needed, given DatabaseCleaner cleans the db between runs...but I think the concurrency was the prob...using unique ids fixes that

@adrian-rpf adrian-rpf requested a review from Copilot October 29, 2025 15:00
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the education rake task specs to improve test isolation and prevent test conflicts by using unique school IDs and properly managing environment variables.

  • Introduces ClimateControl to manage environment variables (SEEDING_CREATOR_ID, SEEDING_TEACHER_ID) in test isolation
  • Changes test data to use dynamically generated unique school IDs via SecureRandom.uuid instead of hardcoded values
  • Updates test IDs and improves code quality by using .count instead of .length for ActiveRecord queries

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +9 to +12
before do
# Ensure the school id is unique, to avoid conflicts
stub_const('SeedsHelper::TEST_SCHOOL', school_id)
end
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

The before hook at the top level will execute for all test contexts, but school_id is defined using let which is lazily evaluated. This can cause issues with RSpec's evaluation order. Consider using let! for school_id to ensure it's evaluated before the before hook, or move the stub_const into individual test contexts where school_id is actually used.

Copilot uses AI. Check for mistakes.
Comment on lines +14 to +15
let(:creator_id) { 'f83ba872-b16e-46e1-9f7d-df89d267550d' }
let(:teacher_id) { 'ccc9b8fd-f357-4238-983d-6f87b99bdbb2' }
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

The hardcoded UUIDs for creator_id and teacher_id do not match the actual TEST_USERS values from SeedsHelper (which uses 583ba872-b16e-46e1-9f7d-df89d267550d for jane_doe and bbb9b8fd-f357-4238-983d-6f87b99bdbb2 for john_doe). Consider using the actual SeedsHelper::TEST_USERS values or documenting why different UUIDs are being used for testing.

Suggested change
let(:creator_id) { 'f83ba872-b16e-46e1-9f7d-df89d267550d' }
let(:teacher_id) { 'ccc9b8fd-f357-4238-983d-6f87b99bdbb2' }
let(:creator_id) { '583ba872-b16e-46e1-9f7d-df89d267550d' } # jane_doe from SeedsHelper
let(:teacher_id) { 'bbb9b8fd-f357-4238-983d-6f87b99bdbb2' } # john_doe from SeedsHelper

Copilot uses AI. Check for mistakes.
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.

3 participants