Commits

Anonymous committed 57779e9

update test case

Comments (0)

Files changed (1)

ruby/test/msgpack_rpc_test.rb

 	end
 
 
-	def test_call
+	def next_port
 		port = $port += 1
+	end
+
+	def start_server
+		port = next_port
 
 		svr = MessagePack::RPC::Server.new
 		svr.listen("0.0.0.0", port, MyServer.new(svr))
 		cli = MessagePack::RPC::Client.new("127.0.0.1", port)
 		cli.timeout = 10
 
+		return svr, cli
+	end
+
+
+	def test_call
+		svr, cli = start_server
+
 		result = cli.call(:hello)
 		assert_equal(result, "ok")
 
 
 
 	def test_callback
-		port = $port += 1
-
-		svr = MessagePack::RPC::Server.new
-		svr.listen("0.0.0.0", port, MyServer.new(svr))
-		Thread.start do
-			svr.run
-		end
+		svr, cli = start_server
 
 		count = 0
 
-		cli = MessagePack::RPC::Client.new("127.0.0.1", port)
-		cli.timeout = 10
-
 		cli.callback(:hello) do |error, result|
 			assert_equal(result, "ok")
 			assert_nil(error)
 
 
 	def test_hidden
-		port = $port += 1
-
-		svr = MessagePack::RPC::Server.new
-		svr.listen("0.0.0.0", port, MyServer.new(svr))
-		Thread.start do
-			svr.run
-		end
+		svr, cli = start_server
 
 		count = 0
 
-		cli = MessagePack::RPC::Client.new("127.0.0.1", port)
-		cli.timeout = 10
-
 		rejected = false
 		begin
 			cli.call(:hidden)
 
 
 	def test_exception
-		port = $port += 1
-
-		svr = MessagePack::RPC::Server.new
-		svr.listen("0.0.0.0", port, MyServer.new(svr))
-		Thread.start do
-			svr.run
-		end
-
-		cli = MessagePack::RPC::Client.new("127.0.0.1", port)
-		cli.timeout = 10
+		svr, cli = start_server
 
 		raised = false
 		begin
 
 
 	def test_async
-		port = $port += 1
-
-		svr = MessagePack::RPC::Server.new
-		svr.listen("0.0.0.0", port, MyServer.new(svr))
-		Thread.start do
-			svr.run
-		end
-
-		cli = MessagePack::RPC::Client.new("127.0.0.1", port)
-		cli.timeout = 10
+		svr, cli = start_server
 
 		result = cli.call(:async)
 		assert_equal(result, "async")
 
 
 	def test_async_exception
-		port = $port += 1
-
-		svr = MessagePack::RPC::Server.new
-		svr.listen("0.0.0.0", port, MyServer.new(svr))
-		Thread.start do
-			svr.run
-		end
-
-		cli = MessagePack::RPC::Client.new("127.0.0.1", port)
-		cli.timeout = 10
+		svr, cli = start_server
 
 		raised = false
 		begin
 
 
 	def test_loop
-		port = $port += 1
+		port = next_port
 
 		loop = MessagePack::RPC::Loop.new
 
 
 
 	def test_timeout
-		port = $port += 1
+		port = next_port
 
 		lsock = TCPServer.new("0.0.0.0", port)