-
-
Notifications
You must be signed in to change notification settings - Fork 503
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
refactor: change item seeding removal strategy #4264
refactor: change item seeding removal strategy #4264
Conversation
475a741
to
b60abd4
Compare
08a811d
to
e045c2f
Compare
e045c2f
to
d8c40f7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only real file with changes worth looking at, all the rest is adding tags to spec files.
As discussed here rubyforgood#4264, some tests modify global variables and expect them to be reset before each test. This makes it more difficult to move forward with removal of pre-seeding. This commit refactors certain tests to be less brittle to changes in global state and to rely less on assumptions on global state. Ex: not assuming that there are 0 records of a certain type when a test starts, etc.
As discussed here rubyforgood#4264, some tests modify global variables and expect them to be reset before each test. This makes it more difficult to move forward with removal of pre-seeding. This commit refactors certain tests to be less brittle to changes in global state and to rely less on assumptions on global state. Ex: not assuming that there are 0 records of a certain type when a test starts, etc.
d8c40f7
to
33c8895
Compare
4ed91bc
to
3829473
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this PR is trying to do too much at once... can we land on the seed strategy first and then start changing the specs?
96f10fc
to
bdc2a74
Compare
* fix: remove more test order dependence As discussed here #4264, some tests modify global variables and expect them to be reset before each test. This makes it more difficult to move forward with removal of pre-seeding. This commit refactors certain tests to be less brittle to changes in global state and to rely less on assumptions on global state. Ex: not assuming that there are 0 records of a certain type when a test starts, etc. * fix: minor cleanup / lint
2089c64
to
b4af1bf
Compare
has 1 failing test but that is unrelated and fixed here: #4305 |
f5a2730
to
8613397
Compare
Thread.current[:skipped_last_seeding] = true | ||
unless self.class.metadata[:skip_seed] | ||
if seeded_last && seed_current | ||
define_global_variables |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can reorganize this a bit like so:
if seeded_last && !seed_current
DatabaseCleaner.clean_with(:truncation) # remove previously seeded data
end
if seed_current
seed_base_data_for_tests if !seeded_last # need to re-seed data
define_global_variables
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was doing it the other way do be explicit about all the cases, also why I added the comment about the !seeded && !seeded case. You think this is better?
All specs tagged with seed_db will get seeded. This happens on a group level, so it will happen before the whole group. Ex: if the outer most Rspec.describe is tagged with seed_db: true the seeding will run once before the entire spec file and once after. Tracks the previous execution group. - seed or not seed base on flag on current group - truncate if the previous group seeded
Previously we were truncating if prev run had been seed and seeding if current run needed seeding. The more correct approach is: if seeded_last && seed_this => only define global vars if seeded_last && !seed_this => truncate if !seeded_last && seed_this => seed + define globals if !seed_last && !seed_this => do nothing
8613397
to
129e150
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meh, it's a nit. I think this is fine.
@dorner ill rebase the other existing PRs off this. You think its possible if I get the refactors in early enough to get this done before the event? |
Can't hurt to try! 🎉 |
@elasticspoon: Your PR |
New change in item seeding strategy:
All specs are seeded by default except specs tagged with
skip_seed: true
.Thread.current[:seeded_last]
stores if the last run seeded data or not.Cost of the Change (based on how long it takes me to run the full specs)
before(:all)
with lots ofseed_db: true
: 12:56before(:all)
with a fewskip_seed: true
: 12:36