From 0967b6a49dcc1d9ee2697767b7f69b157236ae1a Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 25 Jun 2018 18:00:42 -0400 Subject: [PATCH] Use rspec-retry to retry this test up to 3 times. Looks like even a 2 second time delta is not always sufficient, thus instead of always accepting a huge delta insist on a small delta but run the test several times until it succeeds. --- Gemfile | 4 ++++ spec/mongo/client_spec.rb | 4 ++-- spec/spec_helper.rb | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 6c27dd1f91..878bddb243 100644 --- a/Gemfile +++ b/Gemfile @@ -25,6 +25,10 @@ group :development, :testing do end end +group :testing do + gem 'rspec-retry' +end + group :development do gem 'ruby-prof', :platforms => :mri gem 'pry-rescue' diff --git a/spec/mongo/client_spec.rb b/spec/mongo/client_spec.rb index 74e3805590..91810523e1 100644 --- a/spec/mongo/client_spec.rb +++ b/spec/mongo/client_spec.rb @@ -1604,8 +1604,8 @@ expect(session).to be_a(Mongo::Session) end - it 'sets the last use field to the current time' do - expect(session.instance_variable_get(:@server_session).last_use).to be_within(2).of(Time.now) + it 'sets the last use field to the current time', retry: 4 do + expect(session.instance_variable_get(:@server_session).last_use).to be_within(1).of(Time.now) end context 'when options are provided' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 775d43662b..84f444813d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -79,6 +79,7 @@ require 'support/authorization' require 'support/primary_socket' require 'support/constraints' +require 'rspec/retry' RSpec.configure do |config| config.include(Authorization)