mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
Merge pull request #535 from botandrose/fix_moped_race_condition
Fix race conditions in moped and mongo tests
This commit is contained in:
commit
eeb56d7bf6
4 changed files with 11 additions and 3 deletions
|
@ -13,6 +13,7 @@ module DatabaseCleaner
|
|||
else
|
||||
collections.each { |c| session[c].find.remove_all unless @tables_to_exclude.include?(c) }
|
||||
end
|
||||
wait_for_removals_to_finish
|
||||
true
|
||||
end
|
||||
|
||||
|
@ -35,6 +36,9 @@ module DatabaseCleaner
|
|||
end
|
||||
end
|
||||
|
||||
def wait_for_removals_to_finish
|
||||
session.command(getlasterror: 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,7 +24,8 @@ module DatabaseCleaner
|
|||
# I had to add this sanity_check garbage because I was getting non-determinisc results from mongo at times..
|
||||
# very odd and disconcerting...
|
||||
expected_counts.each do |model_class, expected_count|
|
||||
model_class.count.should eq(expected_count), "#{model_class} expected to have a count of #{expected_count} but was #{model_class.count}"
|
||||
actual_count = model_class.count
|
||||
actual_count.should eq(expected_count), "#{model_class} expected to have a count of #{expected_count} but was #{actual_count}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -25,7 +25,8 @@ module DatabaseCleaner
|
|||
sanity_check = expected_counts.delete(:sanity_check)
|
||||
begin
|
||||
expected_counts.each do |model_class, expected_count|
|
||||
model_class.count.should eq(expected_count), "#{model_class} expected to have a count of #{expected_count} but was #{model_class.count}"
|
||||
actual_count = model_class.count
|
||||
actual_count.should eq(expected_count), "#{model_class} expected to have a count of #{expected_count} but was #{actual_count}"
|
||||
end
|
||||
rescue RSpec::Expectations::ExpectationNotMetError => e
|
||||
raise !sanity_check ? e : RSpec::ExpectationNotMetError::ExpectationNotMetError.new("SANITY CHECK FAILURE! This should never happen here: #{e.message}")
|
||||
|
|
|
@ -21,13 +21,15 @@ module DatabaseCleaner
|
|||
|
||||
after(:each) do
|
||||
@session.drop
|
||||
@session.command(getlasterror: 1)
|
||||
end
|
||||
|
||||
def ensure_counts(expected_counts)
|
||||
# I had to add this sanity_check garbage because I was getting non-determinisc results from mongo at times..
|
||||
# very odd and disconcerting...
|
||||
expected_counts.each do |model_class, expected_count|
|
||||
model_class.count.should eq(expected_count), "#{model_class} expected to have a count of #{expected_count} but was #{model_class.count}"
|
||||
actual_count = model_class.count
|
||||
actual_count.should eq(expected_count), "#{model_class} expected to have a count of #{expected_count} but was #{actual_count}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue