kronk 1.7.8 → 1.8.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/History.rdoc +32 -0
- data/Manifest.txt +5 -5
- data/README.rdoc +5 -3
- data/Rakefile +3 -4
- data/TODO.rdoc +22 -6
- data/lib/kronk.rb +13 -7
- data/lib/kronk/buffered_io.rb +26 -0
- data/lib/kronk/cmd.rb +58 -44
- data/lib/kronk/constants.rb +5 -6
- data/lib/kronk/diff.rb +12 -13
- data/lib/kronk/diff/output.rb +1 -1
- data/lib/kronk/http.rb +105 -0
- data/lib/kronk/player.rb +74 -82
- data/lib/kronk/player/benchmark.rb +34 -35
- data/lib/kronk/player/stream.rb +6 -6
- data/lib/kronk/player/suite.rb +17 -16
- data/lib/kronk/player/tsv.rb +51 -0
- data/lib/kronk/queue_runner.rb +126 -102
- data/lib/kronk/request.rb +144 -82
- data/lib/kronk/response.rb +520 -202
- data/lib/kronk/test/helper_methods.rb +1 -1
- data/test/mocks/200_gzip.txt +0 -0
- data/test/mocks/200_inflate.txt +0 -0
- data/test/test_assertions.rb +1 -1
- data/test/test_cmd.rb +18 -11
- data/test/test_diff.rb +39 -0
- data/test/test_helper.rb +18 -14
- data/test/test_helper_methods.rb +5 -4
- data/test/test_kronk.rb +8 -11
- data/test/test_player.rb +67 -123
- data/test/test_request.rb +8 -14
- data/test/test_response.rb +228 -60
- metadata +20 -31
- data/lib/kronk/async.rb +0 -118
- data/lib/kronk/async/em_ext.rb +0 -34
- data/lib/kronk/async/request.rb +0 -73
- data/lib/kronk/async/response.rb +0 -70
- data/lib/kronk/player/output.rb +0 -49
Binary file
|
Binary file
|
data/test/test_assertions.rb
CHANGED
@@ -81,7 +81,7 @@ class TestAssertions < Test::Unit::TestCase
|
|
81
81
|
Kronk.expects(:request).
|
82
82
|
with("host2.com", :foo => "bar").returns mock_resp2
|
83
83
|
|
84
|
-
left = Kronk::DataString.new mock_resp1.
|
84
|
+
left = Kronk::DataString.new mock_resp1.data
|
85
85
|
right = mock_resp2.body
|
86
86
|
|
87
87
|
assert_not_equal left, right
|
data/test/test_cmd.rb
CHANGED
@@ -274,15 +274,15 @@ class TestCmd < Test::Unit::TestCase
|
|
274
274
|
opts = Kronk::Cmd.parse_args %w{uri -c 2 -n 100 -o}
|
275
275
|
assert_equal 2, opts[:player].concurrency
|
276
276
|
assert_equal 100, opts[:player].number
|
277
|
-
assert_equal Kronk::Player::Stream, opts[:player].
|
277
|
+
assert_equal Kronk::Player::Stream, opts[:player].class
|
278
278
|
|
279
279
|
opts = Kronk::Cmd.parse_args %w{uri -o benchmark}
|
280
|
-
assert_equal Kronk::Player::Benchmark, opts[:player].
|
280
|
+
assert_equal Kronk::Player::Benchmark, opts[:player].class
|
281
281
|
end
|
282
282
|
|
283
283
|
|
284
284
|
def test_parse_args_player_stdin
|
285
|
-
$stdin.expects(:tty?).returns(false).times(
|
285
|
+
$stdin.expects(:tty?).returns(false).times(7)
|
286
286
|
|
287
287
|
opts = Kronk::Cmd.parse_args %w{uri -p}
|
288
288
|
assert_equal $stdin, opts[:player].input.io
|
@@ -291,12 +291,12 @@ class TestCmd < Test::Unit::TestCase
|
|
291
291
|
opts = Kronk::Cmd.parse_args %w{uri --benchmark}
|
292
292
|
assert_equal $stdin, opts[:player].input.io
|
293
293
|
assert_equal %w{uri}, opts[:uris]
|
294
|
-
assert_equal Kronk::Player::Benchmark, opts[:player].
|
294
|
+
assert_equal Kronk::Player::Benchmark, opts[:player].class
|
295
295
|
|
296
296
|
opts = Kronk::Cmd.parse_args %w{uri --stream}
|
297
297
|
assert_equal $stdin, opts[:player].input.io
|
298
298
|
assert_equal %w{uri}, opts[:uris]
|
299
|
-
assert_equal Kronk::Player::Stream, opts[:player].
|
299
|
+
assert_equal Kronk::Player::Stream, opts[:player].class
|
300
300
|
end
|
301
301
|
|
302
302
|
|
@@ -309,11 +309,11 @@ class TestCmd < Test::Unit::TestCase
|
|
309
309
|
|
310
310
|
opts = Kronk::Cmd.parse_args %w{uri --benchmark mock_file}
|
311
311
|
assert_equal mock_file, opts[:player].input.io
|
312
|
-
assert_equal Kronk::Player::Benchmark, opts[:player].
|
312
|
+
assert_equal Kronk::Player::Benchmark, opts[:player].class
|
313
313
|
|
314
314
|
opts = Kronk::Cmd.parse_args %w{uri --stream mock_file}
|
315
315
|
assert_equal mock_file, opts[:player].input.io
|
316
|
-
assert_equal Kronk::Player::Stream, opts[:player].
|
316
|
+
assert_equal Kronk::Player::Stream, opts[:player].class
|
317
317
|
end
|
318
318
|
|
319
319
|
|
@@ -399,13 +399,20 @@ class TestCmd < Test::Unit::TestCase
|
|
399
399
|
|
400
400
|
def test_parse_args_uris_with_io
|
401
401
|
$stdin.expects(:tty?).returns(false)
|
402
|
-
|
402
|
+
|
403
|
+
if "1.9".respond_to?(:encoding)
|
404
|
+
$stdin.stubs(:read_nonblock).raises(EOFError)
|
405
|
+
$stdin.expects(:read_nonblock).returns("MOCK RESPONSE")
|
406
|
+
else
|
407
|
+
$stdin.stubs(:sysread).raises(EOFError)
|
408
|
+
$stdin.expects(:sysread).returns("MOCK RESPONSE")
|
409
|
+
end
|
403
410
|
|
404
411
|
opts = Kronk::Cmd.parse_args %w{uri1 uri2}
|
405
412
|
assert_equal 2, opts[:uris].length
|
406
413
|
assert_equal "uri1", opts[:uris][1]
|
407
|
-
assert_equal
|
408
|
-
assert_equal "MOCK RESPONSE", opts[:uris][0].
|
414
|
+
assert_equal Kronk::BufferedIO, opts[:uris][0].class
|
415
|
+
assert_equal "MOCK RESPONSE", opts[:uris][0].read_all
|
409
416
|
end
|
410
417
|
|
411
418
|
|
@@ -490,7 +497,7 @@ class TestCmd < Test::Unit::TestCase
|
|
490
497
|
|
491
498
|
def test_run_caught_errors
|
492
499
|
errs = {
|
493
|
-
Kronk::
|
500
|
+
Kronk::Error => "Kronk::Error",
|
494
501
|
Kronk::Response::MissingParser => "Kronk::Response::MissingParser",
|
495
502
|
Errno::ECONNRESET => "Connection reset by peer"
|
496
503
|
}
|
data/test/test_diff.rb
CHANGED
@@ -225,6 +225,45 @@ class TestDiff < Test::Unit::TestCase
|
|
225
225
|
end
|
226
226
|
|
227
227
|
|
228
|
+
def test_create_diff_duplicate_match_middle
|
229
|
+
str1 = "line2\nline3a\nline3\nline4\nline5\nline6\nline4\nline6\nline7"
|
230
|
+
str2 = "line2\nline3\nline4\nline5\nline6\nline7"
|
231
|
+
|
232
|
+
expected = [
|
233
|
+
"line2",
|
234
|
+
[["line3a"], []],
|
235
|
+
"line3",
|
236
|
+
"line4",
|
237
|
+
"line5",
|
238
|
+
"line6",
|
239
|
+
[["line4", "line6"], []],
|
240
|
+
"line7"
|
241
|
+
]
|
242
|
+
|
243
|
+
diff = Kronk::Diff.new str1, str2
|
244
|
+
assert_equal expected, diff.create_diff
|
245
|
+
end
|
246
|
+
|
247
|
+
|
248
|
+
def test_create_diff_duplicate_match_start
|
249
|
+
str1 = "line2\nline5\nline6\nline7\nline8\nline9"
|
250
|
+
str2 = "line2\nline5\nline6\nline7\nline5\nline6\nline7\nline8\nline9"
|
251
|
+
|
252
|
+
expected = [
|
253
|
+
"line2",
|
254
|
+
[[], ["line5", "line6", "line7"]],
|
255
|
+
"line5",
|
256
|
+
"line6",
|
257
|
+
"line7",
|
258
|
+
"line8",
|
259
|
+
"line9"
|
260
|
+
]
|
261
|
+
|
262
|
+
diff = Kronk::Diff.new str1, str2
|
263
|
+
assert_equal expected, diff.create_diff
|
264
|
+
end
|
265
|
+
|
266
|
+
|
228
267
|
def test_count
|
229
268
|
assert_equal 4, @diff.count
|
230
269
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "test/unit"
|
2
|
-
require "kronk/async"
|
3
2
|
require "mocha"
|
3
|
+
require "kronk"
|
4
4
|
|
5
5
|
Kronk.config[:context] = nil
|
6
6
|
|
@@ -148,18 +148,26 @@ ensure
|
|
148
148
|
end
|
149
149
|
|
150
150
|
|
151
|
+
def with_buffer_size size
|
152
|
+
old_size = Net::BufferedIO::BUFSIZE
|
153
|
+
Net::BufferedIO.send :remove_const, :BUFSIZE
|
154
|
+
Net::BufferedIO.const_set :BUFSIZE, size
|
155
|
+
yield
|
156
|
+
ensure
|
157
|
+
Net::BufferedIO.send :remove_const, :BUFSIZE
|
158
|
+
Net::BufferedIO.const_set :BUFSIZE, old_size
|
159
|
+
end
|
160
|
+
|
161
|
+
|
151
162
|
def expect_request req_method, url, options={}
|
152
163
|
uri = URI.parse url
|
153
164
|
|
154
165
|
resp = Kronk::Response.new(options[:returns] || mock_200_response)
|
155
166
|
resp.stubs(:code).returns(options[:status] || '200')
|
167
|
+
resp.stubs(:to_hash).returns Hash.new
|
156
168
|
|
157
169
|
http = mock 'http'
|
158
|
-
socket = mock 'socket'
|
159
170
|
req = mock 'req'
|
160
|
-
res = mock 'res'
|
161
|
-
|
162
|
-
res.stubs(:to_hash).returns Hash.new
|
163
171
|
|
164
172
|
data = options[:data]
|
165
173
|
data &&= Hash === data ? Kronk::Request.build_query(data) : data.to_s
|
@@ -167,20 +175,16 @@ def expect_request req_method, url, options={}
|
|
167
175
|
headers = options[:headers] || Hash.new
|
168
176
|
headers['User-Agent'] ||= Kronk::DEFAULT_USER_AGENT
|
169
177
|
|
170
|
-
req.expects(:start).yields(http).returns
|
171
|
-
|
172
|
-
http.expects(:instance_variable_get).with("@socket").returns socket
|
173
|
-
|
174
|
-
socket.expects(:debug_output=)
|
178
|
+
req.expects(:start).yields(http).returns resp
|
175
179
|
|
176
180
|
Kronk::Request::VanillaRequest.expects(:new).
|
177
181
|
with(req_method.to_s.upcase, uri.request_uri, headers).returns req
|
178
182
|
|
179
|
-
|
180
|
-
|
181
|
-
http.expects(:request).with(req, data).returns res
|
183
|
+
Kronk::HTTP.expects(:new).with(uri.host, uri.port).returns req
|
182
184
|
|
183
|
-
|
185
|
+
http.expects(:request).
|
186
|
+
with(req, data, has_entry(:request => instance_of(Kronk::Request))).
|
187
|
+
returns resp
|
184
188
|
|
185
189
|
yield http, req, resp if block_given?
|
186
190
|
|
data/test/test_helper_methods.rb
CHANGED
@@ -13,7 +13,8 @@ class TestHelperMethods < Test::Unit::TestCase
|
|
13
13
|
@mock_req = stub("mock_req", :retrieve => @mock_resp, :uri => "host.com")
|
14
14
|
@mock_req2 = stub("mock_req", :retrieve => @mock_resp2, :uri => "host.com")
|
15
15
|
|
16
|
-
@mock_thread = stub("mock_thread", :join =>
|
16
|
+
@mock_thread = stub("mock_thread", :join => true,
|
17
|
+
:abort_on_exception= => true)
|
17
18
|
|
18
19
|
Thread.stubs(:new).yields.returns @mock_thread
|
19
20
|
Kronk::Request.any_instance.stubs(:new).returns @mock_req
|
@@ -97,7 +98,7 @@ class TestHelperMethods < Test::Unit::TestCase
|
|
97
98
|
Kronk::Request.expects(:new).
|
98
99
|
with("host.com", :foo => "bar", :test => "thing").returns @mock_req
|
99
100
|
|
100
|
-
@mock_resp.expects(:
|
101
|
+
@mock_resp.expects(:data).with(:foo => "bar", :test => "thing").
|
101
102
|
returns @json
|
102
103
|
|
103
104
|
retrieve "host.com", {:foo => "bar"}, :test => "thing"
|
@@ -119,8 +120,8 @@ class TestHelperMethods < Test::Unit::TestCase
|
|
119
120
|
Kronk::Request.expects(:new).
|
120
121
|
with("host2.com", :foo => "bar").returns @mock_req2
|
121
122
|
|
122
|
-
@mock_resp.expects(:
|
123
|
-
@mock_resp2.expects(:
|
123
|
+
@mock_resp.expects(:data).twice.with(:foo => "bar").returns @json
|
124
|
+
@mock_resp2.expects(:data).twice.with(:foo => "bar").returns @json
|
124
125
|
|
125
126
|
retrieve "host1.com", "host2.com", :foo => "bar"
|
126
127
|
|
data/test/test_kronk.rb
CHANGED
@@ -4,7 +4,6 @@ class TestKronk < Test::Unit::TestCase
|
|
4
4
|
|
5
5
|
def test_default_config
|
6
6
|
expected = {
|
7
|
-
:async => 'auto',
|
8
7
|
:content_types => {
|
9
8
|
'js' => 'JSON',
|
10
9
|
'json' => 'JSON',
|
@@ -34,7 +33,6 @@ class TestKronk < Test::Unit::TestCase
|
|
34
33
|
def test_load_config
|
35
34
|
with_config do
|
36
35
|
mock_config = {
|
37
|
-
:async => false,
|
38
36
|
:content_types => {
|
39
37
|
'soap' => "SOAPParser",
|
40
38
|
'js' => "JsEngine"
|
@@ -64,7 +62,6 @@ class TestKronk < Test::Unit::TestCase
|
|
64
62
|
Kronk.load_config "foobar"
|
65
63
|
|
66
64
|
expected = {
|
67
|
-
:async => false,
|
68
65
|
:content_types => {
|
69
66
|
'soap' => "SOAPParser",
|
70
67
|
'js' => "JsEngine",
|
@@ -374,8 +371,8 @@ class TestKronk < Test::Unit::TestCase
|
|
374
371
|
:show_headers => true,
|
375
372
|
:raw => true
|
376
373
|
|
377
|
-
exp_diff = Kronk::Diff.new resp1.
|
378
|
-
resp2.
|
374
|
+
exp_diff = Kronk::Diff.new resp1.to_s,
|
375
|
+
resp2.to_s,
|
379
376
|
:labels => [
|
380
377
|
"test/mocks/200_response.json",
|
381
378
|
"test/mocks/200_response.xml"
|
@@ -453,8 +450,8 @@ class TestKronk < Test::Unit::TestCase
|
|
453
450
|
:show_headers => true
|
454
451
|
|
455
452
|
exp_diff = Kronk::Diff.new_from_data \
|
456
|
-
resp1.
|
457
|
-
resp2.
|
453
|
+
resp1.data(:show_headers => true),
|
454
|
+
resp2.data(:show_headers => true),
|
458
455
|
:labels => [
|
459
456
|
"test/mocks/200_response.json",
|
460
457
|
"test/mocks/200_response.xml"
|
@@ -502,7 +499,7 @@ class TestKronk < Test::Unit::TestCase
|
|
502
499
|
def test_follow_redirect_no_redirect
|
503
500
|
res = Kronk::Response.new mock_200_response
|
504
501
|
req = Kronk::Request.new "http://www.google.com/"
|
505
|
-
req.stubs(:
|
502
|
+
req.stubs(:retrieve).returns res
|
506
503
|
|
507
504
|
Kronk::Request.expects(:new).with("http://www.google.com/",{}).never
|
508
505
|
Kronk::Request.expects(:new).
|
@@ -515,7 +512,7 @@ class TestKronk < Test::Unit::TestCase
|
|
515
512
|
def test_do_not_follow_redirect
|
516
513
|
res = Kronk::Response.new mock_302_response
|
517
514
|
req = Kronk::Request.new "http://www.google.com/"
|
518
|
-
req.stubs(:
|
515
|
+
req.stubs(:retrieve).returns res
|
519
516
|
|
520
517
|
Kronk::Request.expects(:new).with("http://www.google.com/",{}).never
|
521
518
|
Kronk::Request.expects(:new).
|
@@ -548,8 +545,8 @@ class TestKronk < Test::Unit::TestCase
|
|
548
545
|
assert_equal nil, kronk.diff
|
549
546
|
|
550
547
|
exp_diff = Kronk::Diff.new_from_data \
|
551
|
-
resp2.
|
552
|
-
resp1.
|
548
|
+
resp2.data(:show_headers => true),
|
549
|
+
resp1.data(:show_headers => true),
|
553
550
|
:labels => [
|
554
551
|
"test/mocks/200_response.json",
|
555
552
|
"test/mocks/200_response.xml"
|
data/test/test_player.rb
CHANGED
@@ -4,19 +4,22 @@ class TestPlayer < Test::Unit::TestCase
|
|
4
4
|
|
5
5
|
class MockPipe < StringIO; end
|
6
6
|
|
7
|
-
class
|
7
|
+
class MockPlayer < Kronk::Player
|
8
8
|
attr_accessor :result_calls
|
9
9
|
|
10
|
-
def
|
10
|
+
def start
|
11
11
|
@result_calls = 0
|
12
|
-
super
|
13
12
|
end
|
14
13
|
|
15
|
-
def result kronk
|
16
|
-
mutex.synchronize do
|
14
|
+
def result kronk
|
15
|
+
@mutex.synchronize do
|
17
16
|
@result_calls += 1
|
18
17
|
end
|
19
18
|
end
|
19
|
+
|
20
|
+
def interrupt
|
21
|
+
raise "Interrupted"
|
22
|
+
end
|
20
23
|
end
|
21
24
|
|
22
25
|
class MockParser
|
@@ -27,20 +30,18 @@ class TestPlayer < Test::Unit::TestCase
|
|
27
30
|
|
28
31
|
|
29
32
|
def setup
|
30
|
-
Kronk::Player.async = false
|
31
|
-
|
32
33
|
@io = MockPipe.new
|
33
34
|
@parser = MockParser
|
34
|
-
@
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
@player = MockPlayer.new :io => @io,
|
36
|
+
:parser => @parser
|
37
|
+
|
38
|
+
@player.on(:result){|(kronk, err)| @player.trigger_result(kronk, err) }
|
38
39
|
end
|
39
40
|
|
40
41
|
|
41
42
|
def test_init_defaults
|
42
|
-
player = Kronk::Player.
|
43
|
-
assert_equal Kronk::Player::Suite, player.
|
43
|
+
player = Kronk::Player.new_type 'suite'
|
44
|
+
assert_equal Kronk::Player::Suite, player.class
|
44
45
|
assert_equal Kronk::Player::InputReader, player.input.class
|
45
46
|
assert_equal Mutex, player.mutex.class
|
46
47
|
assert_equal 1, player.concurrency
|
@@ -63,29 +64,30 @@ class TestPlayer < Test::Unit::TestCase
|
|
63
64
|
|
64
65
|
|
65
66
|
def test_init_opts
|
66
|
-
player = Kronk::Player.
|
67
|
-
|
68
|
-
|
67
|
+
player = Kronk::Player.new_type :stream,
|
68
|
+
:number => 1000,
|
69
|
+
:concurrency => 10
|
69
70
|
|
70
|
-
assert_equal Kronk::Player::Stream, player.
|
71
|
+
assert_equal Kronk::Player::Stream, player.class
|
71
72
|
assert_equal Kronk::Player::RequestParser, player.input.parser
|
72
73
|
assert_equal 10, player.concurrency
|
73
74
|
assert_equal 1000, player.number
|
74
75
|
end
|
75
76
|
|
76
77
|
|
77
|
-
def
|
78
|
-
@player.
|
79
|
-
assert_equal Kronk::Player::Benchmark, @player.
|
78
|
+
def test_new_type
|
79
|
+
@player = Kronk::Player.new_type :benchmark
|
80
|
+
assert_equal Kronk::Player::Benchmark, @player.class
|
80
81
|
|
81
|
-
@player.
|
82
|
-
assert_equal Kronk::Player::Stream, @player.
|
82
|
+
@player = Kronk::Player.new_type :stream
|
83
|
+
assert_equal Kronk::Player::Stream, @player.class
|
83
84
|
|
84
|
-
@player.
|
85
|
-
assert_equal Kronk::Player::Suite, @player.
|
85
|
+
@player = Kronk::Player.new_type :suite
|
86
|
+
assert_equal Kronk::Player::Suite, @player.class
|
86
87
|
|
87
|
-
|
88
|
-
|
88
|
+
assert_raises NameError do
|
89
|
+
@player = Kronk::Player.new_type :foo
|
90
|
+
end
|
89
91
|
end
|
90
92
|
|
91
93
|
|
@@ -164,10 +166,6 @@ class TestPlayer < Test::Unit::TestCase
|
|
164
166
|
|
165
167
|
|
166
168
|
def test_compare
|
167
|
-
@player.output.expects :start
|
168
|
-
@player.output.expects :completed
|
169
|
-
|
170
|
-
@player.concurrency = 3
|
171
169
|
@player.input.parser = Kronk::Player::RequestParser
|
172
170
|
@player.input.io << "/req3\n/req4\n/req5\n"
|
173
171
|
@player.input.io.rewind
|
@@ -192,7 +190,7 @@ class TestPlayer < Test::Unit::TestCase
|
|
192
190
|
|
193
191
|
@player.compare "example.com", "beta-example.com", :query => "foo=bar"
|
194
192
|
|
195
|
-
assert_equal 5, @player.
|
193
|
+
assert_equal 5, @player.result_calls
|
196
194
|
end
|
197
195
|
|
198
196
|
|
@@ -243,9 +241,7 @@ class TestPlayer < Test::Unit::TestCase
|
|
243
241
|
|
244
242
|
def test_run_interrupted
|
245
243
|
@player.concurrency = 0
|
246
|
-
|
247
|
-
@player.output.expects :start
|
248
|
-
@player.output.expects :completed
|
244
|
+
@player.instance_eval "undef interrupt"
|
249
245
|
|
250
246
|
thread = Thread.new do
|
251
247
|
@player.run do |item, mutex|
|
@@ -263,8 +259,7 @@ class TestPlayer < Test::Unit::TestCase
|
|
263
259
|
end
|
264
260
|
|
265
261
|
|
266
|
-
def
|
267
|
-
@player.concurrency = 10
|
262
|
+
def test_concurrently
|
268
263
|
requests = (1..20).map{|n| "request #{n}"}
|
269
264
|
@player.queue.concat requests.dup
|
270
265
|
@player.input.io.close
|
@@ -272,7 +267,7 @@ class TestPlayer < Test::Unit::TestCase
|
|
272
267
|
start = Time.now
|
273
268
|
processed = []
|
274
269
|
|
275
|
-
@player.
|
270
|
+
@player.concurrently 10 do |req|
|
276
271
|
processed << req
|
277
272
|
sleep 0.5
|
278
273
|
end
|
@@ -287,8 +282,7 @@ class TestPlayer < Test::Unit::TestCase
|
|
287
282
|
end
|
288
283
|
|
289
284
|
|
290
|
-
def
|
291
|
-
@player.concurrency = 10
|
285
|
+
def test_concurrently_from_io
|
292
286
|
@player.input.parser.stubs(:start_new?).returns true
|
293
287
|
@player.input.parser.stubs(:start_new?).with("").returns false
|
294
288
|
|
@@ -300,7 +294,7 @@ class TestPlayer < Test::Unit::TestCase
|
|
300
294
|
@player.from_io StringIO.new(requests.join)
|
301
295
|
|
302
296
|
start_time = Time.now
|
303
|
-
@player.
|
297
|
+
@player.concurrently 10 do |req|
|
304
298
|
processed << req
|
305
299
|
sleep 0.5
|
306
300
|
end
|
@@ -348,10 +342,9 @@ class TestPlayer < Test::Unit::TestCase
|
|
348
342
|
def test_start_input_from_input
|
349
343
|
@player.input.stubs(:get_next).returns "mock_request"
|
350
344
|
|
351
|
-
@player.
|
352
|
-
@player.number = 20
|
345
|
+
@player.number = 30
|
353
346
|
|
354
|
-
thread = @player.start_input!
|
347
|
+
thread = @player.start_input! 10
|
355
348
|
assert_equal Thread, thread.class
|
356
349
|
|
357
350
|
sleep 0.2
|
@@ -371,10 +364,9 @@ class TestPlayer < Test::Unit::TestCase
|
|
371
364
|
@player.input.stubs(:get_next).returns nil
|
372
365
|
@player.input.stubs(:eof?).returns false
|
373
366
|
|
374
|
-
@player.concurrency = 5
|
375
367
|
@player.queue << "mock_request"
|
376
368
|
|
377
|
-
thread = @player.start_input!
|
369
|
+
thread = @player.start_input! 10
|
378
370
|
assert_equal Thread, thread.class
|
379
371
|
|
380
372
|
sleep 0.2
|
@@ -427,11 +419,7 @@ class TestPlayer < Test::Unit::TestCase
|
|
427
419
|
end
|
428
420
|
|
429
421
|
|
430
|
-
def
|
431
|
-
mock_thread = "mock_thread"
|
432
|
-
Thread.expects(:new).twice.yields.returns mock_thread
|
433
|
-
mock_thread.expects(:join).twice
|
434
|
-
|
422
|
+
def test_run
|
435
423
|
resp1 = Kronk::Response.new mock_resp("200_response.json")
|
436
424
|
resp1.parser = JSON
|
437
425
|
resp2 = Kronk::Response.new mock_resp("200_response.txt")
|
@@ -447,112 +435,68 @@ class TestPlayer < Test::Unit::TestCase
|
|
447
435
|
|
448
436
|
@got_results = nil
|
449
437
|
|
450
|
-
@player.
|
438
|
+
@player.expects(:result).with do |kronk|
|
451
439
|
@got_results = true
|
452
|
-
assert_equal @player.mutex, mutex
|
453
440
|
assert_equal Kronk::Diff.new(resp1.stringify, resp2.stringify).formatted,
|
454
441
|
kronk.diff.formatted
|
455
442
|
true
|
456
443
|
end
|
457
444
|
|
458
445
|
opts = {:uri_suffix => "/test", :include_headers => true}
|
459
|
-
@player.
|
446
|
+
@player.number = 1
|
447
|
+
@player.concurrency = 1
|
448
|
+
@player.queue << opts
|
449
|
+
|
450
|
+
@player.run do |kronk|
|
451
|
+
kronk.compare "example.com", "beta-example.com"
|
452
|
+
end
|
460
453
|
|
461
|
-
assert @got_results, "Expected
|
454
|
+
assert @got_results, "Expected player to get results but didn't"
|
462
455
|
end
|
463
456
|
|
464
457
|
|
465
|
-
def
|
458
|
+
def test_run_error
|
466
459
|
@got_results = []
|
460
|
+
@player.number = 1
|
461
|
+
@player.concurrency = 1
|
467
462
|
|
468
|
-
@player.
|
463
|
+
@player.expects(:error).times(3).with do |error, kronk|
|
469
464
|
@got_results << error.class
|
470
|
-
assert_equal
|
471
|
-
assert_equal Kronk, kronk.class
|
465
|
+
assert_equal Kronk, kronk.class
|
472
466
|
true
|
473
467
|
end
|
474
468
|
|
475
|
-
errs = [Kronk::
|
469
|
+
errs = [Kronk::Error, Kronk::Response::MissingParser, Errno::ECONNRESET]
|
476
470
|
errs.each do |eklass|
|
477
471
|
Kronk.any_instance.expects(:compare).
|
478
472
|
with("example.com", "beta-example.com").
|
479
473
|
raises eklass
|
480
474
|
|
481
475
|
opts = {:uri_suffix => "/test", :include_headers => true}
|
482
|
-
@player.process_one opts, :compare, "example.com", "beta-example.com"
|
483
|
-
end
|
484
|
-
|
485
|
-
assert_equal errs, @got_results, "Expected output to get errors but didn't"
|
486
|
-
end
|
487
|
-
|
488
|
-
|
489
|
-
def test_process_one_compare_error_not_caught
|
490
|
-
Kronk.any_instance.expects(:compare).
|
491
|
-
with("example.com", "beta-example.com").
|
492
|
-
raises RuntimeError
|
493
|
-
|
494
|
-
assert_raises RuntimeError do
|
495
|
-
opts = {:uri_suffix => "/test", :include_headers => true}
|
496
|
-
@player.process_one opts, :compare, "example.com", "beta-example.com"
|
497
|
-
end
|
498
|
-
end
|
499
|
-
|
500
476
|
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
req = Kronk::Request.new "example.com"
|
506
|
-
req.expects(:retrieve).returns resp
|
507
|
-
|
508
|
-
Kronk::Request.expects(:new).returns req
|
509
|
-
|
510
|
-
@got_results = nil
|
511
|
-
|
512
|
-
@player.output.expects(:result).with do |kronk, mutex|
|
513
|
-
@got_results = true
|
514
|
-
assert_equal @player.mutex, mutex
|
515
|
-
assert_equal resp, kronk.response
|
516
|
-
true
|
477
|
+
@player.run opts do |kronk|
|
478
|
+
kronk.compare "example.com", "beta-example.com"
|
479
|
+
end
|
517
480
|
end
|
518
481
|
|
519
|
-
|
520
|
-
@player.process_one opts, :request, "example.com"
|
521
|
-
|
522
|
-
assert @got_results, "Expected output to get results but didn't"
|
482
|
+
assert_equal errs, @got_results, "Expected player to get errors but didn't"
|
523
483
|
end
|
524
484
|
|
525
485
|
|
526
|
-
def
|
527
|
-
@
|
528
|
-
|
529
|
-
@player.output.expects(:error).times(3).with do |error, kronk, mutex|
|
530
|
-
@got_results << error.class
|
531
|
-
assert_equal @player.mutex, mutex
|
532
|
-
assert_equal Kronk, kronk.class
|
533
|
-
true
|
534
|
-
end
|
486
|
+
def test_run_error_not_caught
|
487
|
+
@player.number = 1
|
488
|
+
@player.concurrency = 1
|
535
489
|
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
raises eklass
|
490
|
+
Kronk.any_instance.expects(:compare).
|
491
|
+
with("example.com", "beta-example.com").
|
492
|
+
raises ArgumentError
|
540
493
|
|
494
|
+
assert_raises ArgumentError do
|
541
495
|
opts = {:uri_suffix => "/test", :include_headers => true}
|
542
|
-
@player.process_one opts, :request, "example.com"
|
543
|
-
end
|
544
496
|
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
def test_process_one_request_error_not_caught
|
550
|
-
Kronk.any_instance.expects(:request).with("example.com").
|
551
|
-
raises RuntimeError
|
552
|
-
|
553
|
-
assert_raises RuntimeError do
|
554
|
-
opts = {:uri_suffix => "/test", :include_headers => true}
|
555
|
-
@player.process_one opts, :request, "example.com"
|
497
|
+
@player.run opts do |kronk|
|
498
|
+
kronk.compare "example.com", "beta-example.com"
|
499
|
+
end
|
556
500
|
end
|
557
501
|
end
|
558
502
|
|