Merge pull request #535 from botandrose/fix_moped_race_condition

Fix race conditions in moped and mongo tests
This commit is contained in:
Ernesto Tagwerker 2018-04-24 16:44:45 -04:00 committed by GitHub
commit eeb56d7bf6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 3 deletions

View file

@ -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

View file

@ -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

View file

@ -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}")

View file

@ -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