spec/mongo/collection_spec.rb in mongo-2.18.0.beta1 vs spec/mongo/collection_spec.rb in mongo-2.18.0

- old
+ new

@@ -798,7 +798,39 @@ expect(change_doc['updateDescription']['updatedFields']['a']).to eq(2) end end end end + + context 'when the change stream is empty' do + require_wired_tiger + min_server_fcv '3.6' + require_topology :replica_set + + context 'when setting the max_await_time_ms' do + + let(:change_stream) do + authorized_collection.watch([], max_await_time_ms: 3000) + end + + let(:enum) { change_stream.to_enum } + + it 'sets the option correctly' do + expect(change_stream.instance_variable_get(:@cursor)).to receive(:get_more_operation).once.and_wrap_original do |m, *args, &block| + m.call(*args).tap do |op| + expect(op.max_time_ms).to eq(3000) + end + end + enum.next + end + + it "waits the appropriate amount of time" do + start_time = Time.now + enum.try_next + end_time = Time.now + + expect(end_time-start_time).to be >= 3 + end + end + end end end