From 0e8eef6cdd4e2d59a6a9829e822e0ee95060e066 Mon Sep 17 00:00:00 2001 From: Tyler Brock Date: Wed, 21 Mar 2012 19:01:37 -0400 Subject: [PATCH] RUBY-420 enforce lower bound on refresh interval --- lib/mongo/repl_set_connection.rb | 5 ++++- test/unit/connection_test.rb | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/mongo/repl_set_connection.rb b/lib/mongo/repl_set_connection.rb index 4aa10b8..d818a07 100644 --- a/lib/mongo/repl_set_connection.rb +++ b/lib/mongo/repl_set_connection.rb @@ -476,7 +476,10 @@ module Mongo # Refresh @refresh_mode = opts.fetch(:refresh_mode, false) - @refresh_interval = opts[:refresh_interval] || 90 + @refresh_interval = opts.fetch(:refresh_interval, 90) + if @refresh_mode && @refresh_interval < 60 + @refresh_interval = 60 + end if @refresh_mode == :async warn ":async refresh mode has been deprecated. Refresh diff --git a/test/unit/connection_test.rb b/test/unit/connection_test.rb index 2db2e26..1572cb7 100644 --- a/test/unit/connection_test.rb +++ b/test/unit/connection_test.rb @@ -41,6 +41,12 @@ class ConnectionTest < Test::Unit::TestCase end context "given a replica set" do + should "enforce a minimum refresh_interval" do + @conn = ReplSetConnection.new(['localhost:27017'], + :connect => false, :refresh_mode => :sync, :refresh_interval => 10) + assert_equal 60, @conn.refresh_interval + end + should "warn if invalid options are specified" do conn = ReplSetConnection.allocate opts = {:connect => false}