diff options
-rw-r--r-- | spec/models/xapian_spec.rb | 23 | ||||
-rw-r--r-- | spec/spec_helper.rb | 19 |
2 files changed, 23 insertions, 19 deletions
diff --git a/spec/models/xapian_spec.rb b/spec/models/xapian_spec.rb index c7c21e3a0..3c9fff784 100644 --- a/spec/models/xapian_spec.rb +++ b/spec/models/xapian_spec.rb @@ -406,28 +406,13 @@ describe InfoRequestEvent, " when faced with a race condition during xapian_mark before(:each) do load_raw_emails_data get_fixtures_xapian_index - # Use the before create job hook to simulate a race condition with another process - # by creating an acts_as_xapian_job record for the same model - class InfoRequestEvent - def xapian_before_create_job_hook(action, model, model_id) - ActsAsXapian::ActsAsXapianJob.create!(:model => model, - :model_id => model_id, - :action => action) - end - end - end - - after(:each) do - # Reset the before create job hook - class InfoRequestEvent - def xapian_before_create_job_hook(action, model, model_id) - end - end end it 'should not raise an error but should fail silently' do - ir = info_requests(:naughty_chicken_request) - ir.reindex_request_events + with_duplicate_xapian_job_creation do + ir = info_requests(:naughty_chicken_request) + ir.reindex_request_events + end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0d8f8fac5..6e65018f1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -125,6 +125,25 @@ Spork.prefork do rebuild_xapian_index end + # Use the before create job hook to simulate a race condition with + # another process by creating an acts_as_xapian_job record for the + # same model: + def with_duplicate_xapian_job_creation + InfoRequestEvent.module_eval do + def xapian_before_create_job_hook(action, model, model_id) + ActsAsXapian::ActsAsXapianJob.create!(:model => model, + :model_id => model_id, + :action => action) + end + end + yield + ensure + InfoRequestEvent.module_eval do + def xapian_before_create_job_hook(action, model, model_id) + end + end + end + def with_env_tz(new_tz = 'US/Eastern') old_tz, ENV['TZ'] = ENV['TZ'], new_tz yield |