thin-async-test 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gemtest +0 -0
- data/History.txt +6 -0
- data/Manifest.txt +6 -0
- data/README.txt +96 -0
- data/Rakefile +21 -0
- data/lib/thin/async/test.rb +44 -0
- data/test/test_thin_async_test.rb +58 -0
- metadata +140 -0
data/.gemtest
ADDED
File without changes
|
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
= thin-async-test
|
2
|
+
|
3
|
+
* https://github.com/phiggins/thin-async-test
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Rack middleware to convince thin-async and rack-test to play nicely.
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* Allows async thin apps to be tested like regular synchronous ones.
|
12
|
+
* Doesn't interfere with regular synchronous apps.
|
13
|
+
* Stops and starts the eventmachine reactor for each test, so test speed suffers.
|
14
|
+
|
15
|
+
== SYNOPSIS:
|
16
|
+
|
17
|
+
require 'thin/async'
|
18
|
+
|
19
|
+
# Step 1: Make your rack app that uses thin and thin-async's AsyncResponse.
|
20
|
+
class MyRackApp
|
21
|
+
def call(env)
|
22
|
+
response = Thin::AsyncResponse.new(env)
|
23
|
+
|
24
|
+
response.headers["X-Foo"] = "bar"
|
25
|
+
|
26
|
+
response << "Here's some body..."
|
27
|
+
|
28
|
+
EM.add_timer(0.1) do
|
29
|
+
response << "long running action"
|
30
|
+
|
31
|
+
response.done
|
32
|
+
end
|
33
|
+
|
34
|
+
response.finish
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Step 2: Create your test class with rack-test.
|
39
|
+
class TestMyRackApp < MiniTest::Unit::TestCase
|
40
|
+
include Rack::Test::Methods
|
41
|
+
|
42
|
+
# Step 3: Define your app method, but wrap it with a Thin::Async::Test
|
43
|
+
def app
|
44
|
+
Thin::Async::Test.new(MyRackApp)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Step 4: You can test your async rack actions like syncronous ones.
|
48
|
+
def test_my_rack_app
|
49
|
+
get("/")
|
50
|
+
|
51
|
+
assert_equal 200, last_response.status
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
== REQUIREMENTS:
|
56
|
+
|
57
|
+
* Designed to work with thin and thin-async, but could potentially work with other stuff.
|
58
|
+
* Tested with eventmachine-1.0.0.beta.3 and ruby-1.9.2-p180.
|
59
|
+
|
60
|
+
== INSTALL:
|
61
|
+
|
62
|
+
Nothing special.
|
63
|
+
|
64
|
+
== DEVELOPERS:
|
65
|
+
|
66
|
+
After checking out the source, run:
|
67
|
+
|
68
|
+
$ rake newb
|
69
|
+
|
70
|
+
This task will install any missing dependencies, run the tests/specs,
|
71
|
+
and generate the RDoc.
|
72
|
+
|
73
|
+
== LICENSE:
|
74
|
+
|
75
|
+
(The MIT License)
|
76
|
+
|
77
|
+
Copyright (c) 2011 Pete Higgins
|
78
|
+
|
79
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
80
|
+
a copy of this software and associated documentation files (the
|
81
|
+
'Software'), to deal in the Software without restriction, including
|
82
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
83
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
84
|
+
permit persons to whom the Software is furnished to do so, subject to
|
85
|
+
the following conditions:
|
86
|
+
|
87
|
+
The above copyright notice and this permission notice shall be
|
88
|
+
included in all copies or substantial portions of the Software.
|
89
|
+
|
90
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
91
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
92
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
93
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
94
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
95
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
96
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
|
6
|
+
Hoe.plugin :minitest
|
7
|
+
Hoe.plugin :git
|
8
|
+
|
9
|
+
Hoe.spec 'thin-async-test' do
|
10
|
+
developer('pete higgins', 'pete@peterhiggins.org')
|
11
|
+
|
12
|
+
extra_dev_deps << ["eventmachine", "~> 1.0.0.beta.3"]
|
13
|
+
extra_dev_deps << ["rack", "~> 1.3.0"]
|
14
|
+
extra_dev_deps << ["thin_async", "~> 0.1.1"]
|
15
|
+
extra_dev_deps << ["thin", "~> 1.2.11"]
|
16
|
+
extra_dev_deps << ["rack-test", "~> 0.6.0"]
|
17
|
+
|
18
|
+
self.testlib = :minitest
|
19
|
+
end
|
20
|
+
|
21
|
+
# vim: syntax=ruby
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'eventmachine'
|
2
|
+
require 'thin/async'
|
3
|
+
|
4
|
+
module Thin
|
5
|
+
module Async
|
6
|
+
class Test
|
7
|
+
VERSION = '1.0.0'
|
8
|
+
|
9
|
+
class Callback
|
10
|
+
attr_reader :status, :headers, :body
|
11
|
+
|
12
|
+
def call args
|
13
|
+
@status, @headers, deferred_body = args
|
14
|
+
@body = ""
|
15
|
+
deferred_body.each {|s| @body << s }
|
16
|
+
|
17
|
+
deferred_body.callback { EM.stop }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(app, options={})
|
22
|
+
@app = app
|
23
|
+
end
|
24
|
+
|
25
|
+
def call(env)
|
26
|
+
callback = Callback.new
|
27
|
+
env.merge! 'async.callback' => callback
|
28
|
+
|
29
|
+
EM.run do
|
30
|
+
result = @app.call(env)
|
31
|
+
|
32
|
+
unless result == Thin::AsyncResponse::Marker
|
33
|
+
EM.next_tick do
|
34
|
+
EM.stop
|
35
|
+
return result
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
[callback.status, callback.headers, callback.body]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require "rack/test"
|
2
|
+
require "thin/async/test"
|
3
|
+
|
4
|
+
STATUS = 200
|
5
|
+
HEADERS = {"X-Foo" => "bar"}
|
6
|
+
BODY = "o hai!"
|
7
|
+
|
8
|
+
TestApp = lambda do |env|
|
9
|
+
case env['PATH_INFO']
|
10
|
+
when '/sync'
|
11
|
+
[STATUS, HEADERS, BODY]
|
12
|
+
when '/async'
|
13
|
+
response = Thin::AsyncResponse.new(env, STATUS, HEADERS)
|
14
|
+
|
15
|
+
response << BODY
|
16
|
+
|
17
|
+
EM.next_tick do
|
18
|
+
response << BODY
|
19
|
+
|
20
|
+
response.done
|
21
|
+
end
|
22
|
+
|
23
|
+
response.finish
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe Thin::Async::Test do
|
28
|
+
include Rack::Test::Methods
|
29
|
+
|
30
|
+
def app
|
31
|
+
Thin::Async::Test.new(TestApp)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "returns normal response for syncronous action" do
|
35
|
+
get "/sync"
|
36
|
+
|
37
|
+
assert_equal STATUS, last_response.status
|
38
|
+
assert_equal "bar", last_response.headers["X-Foo"]
|
39
|
+
assert_equal BODY, last_response.body
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns async response for asyncronous action" do
|
43
|
+
get "/async"
|
44
|
+
|
45
|
+
assert_equal STATUS, last_response.status
|
46
|
+
assert_equal "bar", last_response.headers["X-Foo"]
|
47
|
+
assert_equal BODY*2, last_response.body
|
48
|
+
end
|
49
|
+
|
50
|
+
it "doesn't hog the reactor's time" do
|
51
|
+
foo = nil
|
52
|
+
EM.next_tick { foo = "bar" }
|
53
|
+
|
54
|
+
get "/sync"
|
55
|
+
|
56
|
+
assert_equal "bar", foo
|
57
|
+
end
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: thin-async-test
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 1.0.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- pete higgins
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-07-12 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: minitest
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.6.0
|
24
|
+
type: :development
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: eventmachine
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.0.0.beta.3
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rack
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.3.0
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: thin_async
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ~>
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 0.1.1
|
57
|
+
type: :development
|
58
|
+
version_requirements: *id004
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: thin
|
61
|
+
prerelease: false
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ~>
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 1.2.11
|
68
|
+
type: :development
|
69
|
+
version_requirements: *id005
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rack-test
|
72
|
+
prerelease: false
|
73
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ~>
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 0.6.0
|
79
|
+
type: :development
|
80
|
+
version_requirements: *id006
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: hoe
|
83
|
+
prerelease: false
|
84
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.9.4
|
90
|
+
type: :development
|
91
|
+
version_requirements: *id007
|
92
|
+
description: Rack middleware to convince thin-async and rack-test to play nicely.
|
93
|
+
email:
|
94
|
+
- pete@peterhiggins.org
|
95
|
+
executables: []
|
96
|
+
|
97
|
+
extensions: []
|
98
|
+
|
99
|
+
extra_rdoc_files:
|
100
|
+
- History.txt
|
101
|
+
- Manifest.txt
|
102
|
+
- README.txt
|
103
|
+
files:
|
104
|
+
- History.txt
|
105
|
+
- Manifest.txt
|
106
|
+
- README.txt
|
107
|
+
- Rakefile
|
108
|
+
- lib/thin/async/test.rb
|
109
|
+
- test/test_thin_async_test.rb
|
110
|
+
- .gemtest
|
111
|
+
homepage: https://github.com/phiggins/thin-async-test
|
112
|
+
licenses: []
|
113
|
+
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options:
|
116
|
+
- --main
|
117
|
+
- README.txt
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: "0"
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: "0"
|
132
|
+
requirements: []
|
133
|
+
|
134
|
+
rubyforge_project: thin-async-test
|
135
|
+
rubygems_version: 1.8.2
|
136
|
+
signing_key:
|
137
|
+
specification_version: 3
|
138
|
+
summary: Rack middleware to convince thin-async and rack-test to play nicely.
|
139
|
+
test_files:
|
140
|
+
- test/test_thin_async_test.rb
|