aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2015-11-09 17:26:55 +0900
committerKazuki Yamaguchi <k@rhe.jp>2015-11-09 17:26:55 +0900
commit9bf2c8a0b1c1bf1010de5dea0c37627f7abd4944 (patch)
treefdfce7386d63c39ba6d98088629a7f34dc00f53a
parent0d379e8d343df0e21ed93ebd52bf608dc9a4aa46 (diff)
downloadplum-9bf2c8a0b1c1bf1010de5dea0c37627f7abd4944.tar.gz
client: rename #wait to #resume
-rw-r--r--lib/plum/client.rb29
-rw-r--r--test/plum/client/test_client.rb28
2 files changed, 21 insertions, 36 deletions
diff --git a/lib/plum/client.rb b/lib/plum/client.rb
index a4fe243..233ad4b 100644
--- a/lib/plum/client.rb
+++ b/lib/plum/client.rb
@@ -45,7 +45,7 @@ module Plum
if block_given?
begin
ret = yield(self)
- wait
+ resume
return ret
ensure
close
@@ -57,7 +57,7 @@ module Plum
# Resume communication with the server, until the specified (or all running) requests are complete.
# @param response [Response] if specified, waits only for the response
# @return [Response] if parameter response is specified
- def wait(response = nil)
+ def resume(response = nil)
if response
@session.succ until response.failed? || response.finished?
response
@@ -66,12 +66,6 @@ module Plum
end
end
- # Resume communication with the server until the response headers are sent.
- # @param response [Response] the incomplete response.
- def wait_headers(response)
- @session.succ while !response.failed? && !response.headers
- end
-
# Closes the connection immediately.
def close
@session.close if @session
@@ -84,25 +78,17 @@ module Plum
# @param body [String] the request body
# @param options [Hash<Symbol, Object>] request options
# @param block [Proc] if passed, it will be called when received response headers.
- def request_async(headers, body, options = {}, &block)
+ def request(headers, body, options = {}, &block)
raise ArgumentError, ":method and :path headers are required" unless headers[":method"] && headers[":path"]
@session.request(headers, body, options, &block)
end
- # Creates a new HTTP request and waits for the response
- # @param headers [Hash<String, String>] the request headers
- # @param body [String] the request body
- # @param options [Hash<Symbol, Object>] the request options
- # @param block [Proc] if passed, it will be called when received response headers.
- def request(headers, body, options = {}, &block)
- wait request_async(headers, body, options, &block)
- end
-
# @!method get
# @!method head
# @!method delete
# @param path [String] the absolute path to request (translated into :path header)
# @param options [Hash<Symbol, Object>] the request options
+ # @param block [Proc] if specified, calls the block when finished
# Shorthand method for `#request`
# @!method get_async
@@ -114,7 +100,7 @@ module Plum
# Shorthand method for `#request_async`
%w(GET HEAD DELETE).each { |method|
define_method(:"#{method.downcase}") do |path, options = {}, &block|
- wait _request_helper(method, path, nil, options, &block)
+ resume _request_helper(method, path, nil, options, &block)
end
define_method(:"#{method.downcase}_async") do |path, options = {}, &block|
_request_helper(method, path, nil, options, &block)
@@ -125,6 +111,7 @@ module Plum
# @param path [String] the absolute path to request (translated into :path header)
# @param body [String] the request body
# @param options [Hash<Symbol, Object>] the request options
+ # @param block [Proc] if specified, calls the block when finished
# Shorthand method for `#request`
# @!method post_async
@@ -136,7 +123,7 @@ module Plum
# Shorthand method for `#request_async`
%w(POST PUT).each { |method|
define_method(:"#{method.downcase}") do |path, body, options = {}, &block|
- wait _request_helper(method, path, body, options, &block)
+ resume _request_helper(method, path, body, options, &block)
end
define_method(:"#{method.downcase}_async") do |path, body, options = {}, &block|
_request_helper(method, path, body, options, &block)
@@ -201,7 +188,7 @@ module Plum
":path" => path,
"user-agent" => @config[:user_agent] }
base.merge!(options[:headers]) if options[:headers]
- request_async(base, body, options, &block)
+ request(base, body, options, &block)
end
end
end
diff --git a/test/plum/client/test_client.rb b/test/plum/client/test_client.rb
index c9514cf..8806052 100644
--- a/test/plum/client/test_client.rb
+++ b/test/plum/client/test_client.rb
@@ -2,16 +2,14 @@ require "test_helper"
using Plum::BinaryString
class ClientTest < Minitest::Test
- def test_request
+ def test_request_sync
server_thread = start_tls_server
client = Client.start("127.0.0.1", LISTEN_PORT, https: true, verify_mode: OpenSSL::SSL::VERIFY_NONE)
- res1 = client.request({ ":path" => "/", ":method" => "POST", ":scheme" => "https", "header" => "ccc" }, "abc")
- assert_equal("POSTcccabc", res1.body)
- res2 = client.put("/", "aaa", headers: { "header" => "ccc" })
- assert_equal("PUTcccaaa", res2.body)
+ res1 = client.put("/", "aaa", headers: { "header" => "ccc" })
+ assert_equal("PUTcccaaa", res1.body)
client.close
ensure
- server_thread.join
+ server_thread.join if server_thread
end
def test_request_async
@@ -20,7 +18,7 @@ class ClientTest < Minitest::Test
server_thread = start_tls_server
Client.start("127.0.0.1", LISTEN_PORT, https: true, verify_mode: OpenSSL::SSL::VERIFY_NONE) { |c|
client = c
- res1 = client.request_async({ ":path" => "/", ":method" => "GET", ":scheme" => "https", "header" => "ccc" }, nil) { |res1|
+ res1 = client.request({ ":path" => "/", ":method" => "GET", ":scheme" => "https", "header" => "ccc" }, nil) { |res1|
assert(res1.headers)
}
assert_nil(res1.headers)
@@ -30,7 +28,7 @@ class ClientTest < Minitest::Test
assert(res2.headers)
assert_equal("GETccc", res2.body)
ensure
- server_thread.join
+ server_thread.join if server_thread
end
def test_verify
@@ -40,7 +38,7 @@ class ClientTest < Minitest::Test
client = Client.start("127.0.0.1", LISTEN_PORT, https: true, verify_mode: OpenSSL::SSL::VERIFY_PEER)
}
ensure
- server_thread.join
+ server_thread.join if server_thread
end
def test_raise_error_sync
@@ -53,19 +51,19 @@ class ClientTest < Minitest::Test
}
}
ensure
- server_thread.join
+ server_thread.join if server_thread
end
- def test_raise_error_async_seq_wait
+ def test_raise_error_async_seq_resume
server_thread = start_tls_server
client = Client.start("127.0.0.1", LISTEN_PORT, https: true, verify_mode: OpenSSL::SSL::VERIFY_NONE)
res = client.get_async("/error_in_data")
assert_raises(LocalConnectionError) {
- client.wait(res)
+ client.resume(res)
}
client.close
ensure
- server_thread.join
+ server_thread.join if server_thread
end
def test_raise_error_async_block
@@ -75,10 +73,10 @@ class ClientTest < Minitest::Test
Client.start("127.0.0.1", LISTEN_PORT, https: true, verify_mode: OpenSSL::SSL::VERIFY_NONE) { |c|
client = c
client.get_async("/connection_error") { |res| flunk "success??" }
- } # wait
+ } # resume
}
ensure
- server_thread.join
+ server_thread.join if server_thread
end
private