diff --git a/lib/mongo/util/uri_parser.rb b/lib/mongo/util/uri_parser.rb index 1fb331f..624be9c 100644 --- a/lib/mongo/util/uri_parser.rb +++ b/lib/mongo/util/uri_parser.rb @@ -32,7 +32,7 @@ module Mongo PATH_REGEX = /(?:\/(?[-\w]+))?/ MONGODB_URI_MATCHER = /#{AUTH_REGEX}#{NODE_REGEX}#{PATH_REGEX}/ - MONGODB_URI_SPEC = "mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/database]" + MONGODB_URI_SPEC = "mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]" SPEC_ATTRS = [:nodes, :auths] OPT_ATTRS = [:connect, :replicaset, :slaveok, :safe, :w, :wtimeout, :fsync, :journal, :connectTimeoutMS, :socketTimeoutMS, :wtimeoutMS] @@ -58,9 +58,9 @@ module Mongo :wtimeout => "must be an integer specifying milliseconds", :fsync => "must be 'true' or 'false'", :journal => "must be 'true' or 'false'", - :connectTimeoutMS => "must be an integer specifying milliseconds a connection can take to be opened before timing out", - :socketTimeoutMS => "must be an integer specifying milliseconds a send or receive on a socket can take before timing out", - :wtimeoutMS => "must be an integer specifying milliseconds a send or receive on a socket can take before timing out" + :connectTimeoutMS => "must be an integer specifying milliseconds", + :socketTimeoutMS => "must be an integer specifying milliseconds", + :wtimeoutMS => "must be an integer specifying milliseconds" } OPT_CONV = {:connect => lambda {|arg| arg}, @@ -71,8 +71,8 @@ module Mongo :wtimeout => lambda {|arg| arg.to_i}, :fsync => lambda {|arg| arg == 'true' ? true : false}, :journal => lambda {|arg| arg == 'true' ? true : false}, - :connectTimeoutMS => lambda {|arg| arg.to_i }, - :socketTimeoutMS => lambda {|arg| arg.to_i }, + :connectTimeoutMS => lambda {|arg| arg.to_f / 1000 }, # stored as seconds + :socketTimeoutMS => lambda {|arg| arg.to_f / 1000 }, # stored as seconds :wtimeoutMS => lambda {|arg| arg.to_i } } @@ -116,7 +116,7 @@ module Mongo end if @wtimeoutMS - safe_opts[:wtimeout] = @wtimeoutMS / 1000 + safe_opts[:wtimeout] = @wtimeoutMS end safe_opts[:fsync] = @fsync if @fsync @@ -128,11 +128,11 @@ module Mongo end if @connectTimeoutMS - opts[:connect_timeout] = @connectTimeoutMS / 1000 + opts[:connect_timeout] = @connectTimeoutMS end if @socketTimeoutMS - opts[:op_timeout] = @socketTimeoutMS / 1000 + opts[:op_timeout] = @socketTimeoutMS end if @slaveok diff --git a/test/unit/connection_test.rb b/test/unit/connection_test.rb index 324bfc5..00b97f7 100644 --- a/test/unit/connection_test.rb +++ b/test/unit/connection_test.rb @@ -48,16 +48,16 @@ class ConnectionTest < Test::Unit::TestCase should "set safe options on connection" do host_name = "localhost" - opts = "safe=true&w=2&wtimeoutMS=10000&fsync=true&journal=true" + opts = "safe=true&w=2&wtimeoutMS=1000&fsync=true&journal=true" @conn = Connection.from_uri("mongodb://#{host_name}/foo?#{opts}", :connect => false) - assert_equal({:w => 2, :wtimeout => 10, :fsync => true, :j => true}, @conn.safe) + assert_equal({:w => 2, :wtimeout => 1000, :fsync => true, :j => true}, @conn.safe) end should "have wtimeoutMS take precidence over the depricated wtimeout" do host_name = "localhost" - opts = "safe=true&wtimeout=10&wtimeoutMS=2000" + opts = "safe=true&wtimeout=100&wtimeoutMS=500" @conn = Connection.from_uri("mongodb://#{host_name}/foo?#{opts}", :connect => false) - assert_equal({:wtimeout => 2}, @conn.safe) + assert_equal({:wtimeout => 500}, @conn.safe) end should "set timeout options on connection" do diff --git a/test/uri_test.rb b/test/uri_test.rb index 1167986..f493229 100644 --- a/test/uri_test.rb +++ b/test/uri_test.rb @@ -87,10 +87,10 @@ class TestThreading < Test::Unit::TestCase assert_equal 200, parser.wtimeoutMS end - def test_opts_unsafe_timeout - parser = Mongo::URIParser.new('mongodb://localhost:27018?connectTimeoutMS=5000&socketTimeoutMS=10000') - assert_equal 5000, parser.connectTimeoutMS - assert_equal 10000, parser.socketTimeoutMS + def test_opts_nonsafe_timeout + parser = Mongo::URIParser.new('mongodb://localhost:27018?connectTimeoutMS=5500&socketTimeoutMS=500') + assert_equal 5.5, parser.connectTimeoutMS + assert_equal 0.5, parser.socketTimeoutMS end def test_opts_replica_set