spec/integration/heartbeat_events_spec.rb in mongo-2.10.5 vs spec/integration/heartbeat_events_spec.rb in mongo-2.11.0.rc0

- old
+ new

@@ -23,39 +23,40 @@ end describe 'Heartbeat events' do class HeartbeatEventsSpecTestException < StandardError; end + clean_slate_for_all + let(:subscriber) { TestHeartbeatSubscriber.new } - before(:all) do - ClientRegistry.instance.close_all_clients - end - before do Mongo::Monitoring::Global.subscribe(Mongo::Monitoring::SERVER_HEARTBEAT, subscriber) end after do Mongo::Monitoring::Global.unsubscribe(Mongo::Monitoring::SERVER_HEARTBEAT, subscriber) end - let(:client) { new_local_client([SpecConfig.instance.addresses.first], - authorized_client.options.merge(server_selection_timeout: 0.1, connect: :direct)) } + let(:address_str) { ClusterConfig.instance.primary_address_str } + let(:client) { new_local_client([address_str], + SpecConfig.instance.all_test_options.merge( + server_selection_timeout: 0.1, connect: :direct)) } + it 'notifies on successful heartbeats' do client.database.command(ismaster: 1) started_event = subscriber.started_events.first expect(started_event).not_to be nil expect(started_event.address).to be_a(Mongo::Address) - expect(started_event.address.seed).to eq(SpecConfig.instance.addresses.first) + expect(started_event.address.seed).to eq(address_str) succeeded_event = subscriber.succeeded_events.first expect(succeeded_event).not_to be nil expect(succeeded_event.address).to be_a(Mongo::Address) - expect(succeeded_event.address.seed).to eq(SpecConfig.instance.addresses.first) + expect(succeeded_event.address.seed).to eq(address_str) failed_event = subscriber.failed_events.first expect(failed_event).to be nil end @@ -68,27 +69,27 @@ end.to raise_error(Mongo::Error::NoServerAvailable) started_event = subscriber.started_events.first expect(started_event).not_to be nil expect(started_event.address).to be_a(Mongo::Address) - expect(started_event.address.seed).to eq(SpecConfig.instance.addresses.first) + expect(started_event.address.seed).to eq(address_str) succeeded_event = subscriber.succeeded_events.first expect(succeeded_event).to be nil failed_event = subscriber.failed_events.first expect(failed_event).not_to be nil expect(failed_event.error).to be exc expect(failed_event.failure).to be exc expect(failed_event.address).to be_a(Mongo::Address) - expect(failed_event.address.seed).to eq(SpecConfig.instance.addresses.first) + expect(failed_event.address.seed).to eq(address_str) end context 'when monitoring option is false' do - let(:client) { new_local_client([SpecConfig.instance.addresses.first], - authorized_client.options.merge(server_selection_timeout: 0.1, connect: :direct, - monitoring: false)) } + let(:client) { new_local_client([address_str], + SpecConfig.instance.all_test_options.merge( + server_selection_timeout: 0.1, connect: :direct, monitoring: false)) } shared_examples_for 'does not notify on heartbeats' do it 'does not notify on heartbeats' do client.database.command(ismaster: 1) @@ -103,11 +104,12 @@ let(:client) do sdam_proc = Proc.new do |client| client.subscribe(Mongo::Monitoring::SERVER_HEARTBEAT, subscriber) end - new_local_client([SpecConfig.instance.addresses.first], - authorized_client.options.merge(server_selection_timeout: 0.1, connect: :direct, + new_local_client([address_str], + SpecConfig.instance.all_test_options.merge( + server_selection_timeout: 0.1, connect: :direct, monitoring: false, sdam_proc: sdam_proc)) end it_behaves_like 'does not notify on heartbeats' end