spec/lib/flapjack/data/event_spec.rb in flapjack-1.2.0rc1 vs spec/lib/flapjack/data/event_spec.rb in flapjack-1.2.0rc2

- old
+ new

@@ -20,15 +20,22 @@ 'acknowledgement_id' => '1234', 'duration' => (60 * 60), 'tags' => ['dev'] } } + before(:each) do + Flapjack::Data::Event.instance_variable_set('@previous_base_time_str', nil) + end + context 'class' do it "returns the next event (blocking, archiving)" do expect(redis).to receive(:brpoplpush). with('events', /^events_archive:/, 0).and_return(event_data.to_json) + expect(Flapjack::Data::Migration).to receive(:purge_expired_archive_index).with(:redis => redis) + expect(redis).to receive(:sadd). + with('known_events_archive_keys', /^events_archive:/) expect(redis).to receive(:expire) result = Flapjack::Data::Event.next('events', :block => true, :archive_events => true, :redis => redis) expect(result).to be_an_instance_of(Flapjack::Data::Event) @@ -44,10 +51,13 @@ end it "returns the next event (non-blocking, archiving)" do expect(redis).to receive(:rpoplpush). with('events', /^events_archive:/).and_return(event_data.to_json) + expect(Flapjack::Data::Migration).to receive(:purge_expired_archive_index).with(:redis => redis) + expect(redis).to receive(:sadd). + with('known_events_archive_keys', /^events_archive:/) expect(redis).to receive(:expire) result = Flapjack::Data::Event.next('events', :block => false, :archive_events => true, :redis => redis) expect(result).to be_an_instance_of(Flapjack::Data::Event) @@ -64,10 +74,13 @@ it "rejects invalid event JSON (archiving)" do bad_event_json = '{{{' expect(redis).to receive(:brpoplpush). with('events', /^events_archive:/, 0).and_return(bad_event_json) + expect(Flapjack::Data::Migration).to receive(:purge_expired_archive_index).with(:redis => redis) + expect(redis).to receive(:sadd). + with('known_events_archive_keys', /^events_archive:/) expect(redis).to receive(:multi) expect(redis).to receive(:lrem).with(/^events_archive:/, 1, bad_event_json) expect(redis).to receive(:lpush).with(/^events_rejected:/, bad_event_json) expect(redis).to receive(:exec) expect(redis).to receive(:expire) @@ -94,10 +107,13 @@ bad_event_data = event_data.clone bad_event_data.delete(required_key) bad_event_json = bad_event_data.to_json expect(redis).to receive(:brpoplpush). with('events', /^events_archive:/, 0).and_return(bad_event_json) + expect(Flapjack::Data::Migration).to receive(:purge_expired_archive_index).with(:redis => redis) + expect(redis).to receive(:sadd). + with('known_events_archive_keys', /^events_archive:/) expect(redis).to receive(:multi) expect(redis).to receive(:lrem).with(/^events_archive:/, 1, bad_event_json) expect(redis).to receive(:lpush).with(/^events_rejected:/, bad_event_json) expect(redis).to receive(:exec) expect(redis).to receive(:expire) @@ -124,10 +140,13 @@ bad_event_data = event_data.clone bad_event_data[required_key] = {'hello' => 'there'} bad_event_json = bad_event_data.to_json expect(redis).to receive(:brpoplpush). with('events', /^events_archive:/, 0).and_return(bad_event_json) + expect(Flapjack::Data::Migration).to receive(:purge_expired_archive_index).with(:redis => redis) + expect(redis).to receive(:sadd). + with('known_events_archive_keys', /^events_archive:/) expect(redis).to receive(:multi) expect(redis).to receive(:lrem).with(/^events_archive:/, 1, bad_event_json) expect(redis).to receive(:lpush).with(/^events_rejected:/, bad_event_json) expect(redis).to receive(:exec) expect(redis).to receive(:expire) @@ -156,10 +175,13 @@ bad_event_data = event_data.clone bad_event_data[optional_key] = {'hello' => 'there'} bad_event_json = bad_event_data.to_json expect(redis).to receive(:brpoplpush). with('events', /^events_archive:/, 0).and_return(bad_event_json) + expect(Flapjack::Data::Migration).to receive(:purge_expired_archive_index).with(:redis => redis) + expect(redis).to receive(:sadd). + with('known_events_archive_keys', /^events_archive:/) expect(redis).to receive(:multi) expect(redis).to receive(:lrem).with(/^events_archive:/, 1, bad_event_json) expect(redis).to receive(:lpush).with(/^events_rejected:/, bad_event_json) expect(redis).to receive(:exec) expect(redis).to receive(:expire) @@ -188,10 +210,13 @@ it "it matches case-insensitively for #{key} (archiving)" do case_event_data = event_data.clone case_event_data[key] = event_data[key].upcase expect(redis).to receive(:brpoplpush). with('events', /^events_archive:/, 0).and_return(case_event_data.to_json) + expect(Flapjack::Data::Migration).to receive(:purge_expired_archive_index).with(:redis => redis) + expect(redis).to receive(:sadd). + with('known_events_archive_keys', /^events_archive:/) expect(redis).to receive(:expire) result = Flapjack::Data::Event.next('events', :block => true, :archive_events => true, :redis => redis) expect(result).to be_an_instance_of(Flapjack::Data::Event) @@ -214,10 +239,13 @@ it "it accepts an event with a numeric #{key} key (archiving)" do num_event_data = event_data.clone num_event_data[key] = event_data[key].to_i.to_s expect(redis).to receive(:brpoplpush). with('events', /^events_archive:/, 0).and_return(num_event_data.to_json) + expect(Flapjack::Data::Migration).to receive(:purge_expired_archive_index).with(:redis => redis) + expect(redis).to receive(:sadd). + with('known_events_archive_keys', /^events_archive:/) expect(redis).to receive(:expire) result = Flapjack::Data::Event.next('events', :block => true, :archive_events => true, :redis => redis) expect(result).to be_an_instance_of(Flapjack::Data::Event) @@ -238,9 +266,12 @@ bad_event_data = event_data.clone bad_event_data[key] = 'NaN' bad_event_json = bad_event_data.to_json expect(redis).to receive(:brpoplpush). with('events', /^events_archive:/, 0).and_return(bad_event_json) + expect(Flapjack::Data::Migration).to receive(:purge_expired_archive_index).with(:redis => redis) + expect(redis).to receive(:sadd). + with('known_events_archive_keys', /^events_archive:/) expect(redis).to receive(:multi) expect(redis).to receive(:lrem).with(/^events_archive:/, 1, bad_event_json) expect(redis).to receive(:lpush).with(/^events_rejected:/, bad_event_json) expect(redis).to receive(:exec) expect(redis).to receive(:expire)