1
1
require 'abstract_unit'
2
- require 'action_view/body_parts/concurrent_block'
3
2
4
3
class BodyPartsTest < ActionController ::TestCase
5
4
RENDERINGS = [ Object . new , Object . new , Object . new ]
@@ -21,82 +20,3 @@ def test_body_parts
21
20
assert_equal RENDERINGS . join , @response . body
22
21
end
23
22
end
24
-
25
- class ConcurrentBlockPartTest < ActionController ::TestCase
26
- class TestController < ActionController ::Base
27
- def index
28
- append_thread_id = lambda do |parts |
29
- parts << Thread . current . object_id
30
- parts << '::'
31
- parts << Time . now . to_i
32
- sleep 0.1
33
- end
34
-
35
- future_render &append_thread_id
36
- response . body_parts << '-'
37
-
38
- future_render &append_thread_id
39
- response . body_parts << '-'
40
-
41
- future_render do |parts |
42
- parts << ActionView ::BodyParts ::ConcurrentBlock . new ( &append_thread_id )
43
- parts << '-'
44
- parts << ActionView ::BodyParts ::ConcurrentBlock . new ( &append_thread_id )
45
- end
46
-
47
- @performed_render = true
48
- end
49
-
50
- def future_render ( &block )
51
- response . template . punctuate_body! ActionView ::BodyParts ::ConcurrentBlock . new ( &block )
52
- end
53
- end
54
-
55
- tests TestController
56
-
57
- def test_concurrent_threaded_parts
58
- get :index
59
-
60
- elapsed = Benchmark . ms do
61
- thread_ids = @response . body . split ( '-' ) . map { |part | part . split ( '::' ) . first . to_i }
62
- assert_equal thread_ids . size , thread_ids . uniq . size
63
- end
64
- assert ( elapsed - 100 ) . abs < 10 , elapsed
65
- end
66
- end
67
-
68
-
69
- class OpenUriPartTest < ActionController ::TestCase
70
- class OpenUriPart < ActionView ::BodyParts ::ConcurrentBlock
71
- def initialize ( url )
72
- url = URI ::Generic === url ? url : URI . parse ( url )
73
- super ( ) { |body | body << url . read }
74
- end
75
- end
76
-
77
- class TestController < ActionController ::Base
78
- def index
79
- render_url 'http://localhost/foo'
80
- render_url 'http://localhost/bar'
81
- render_url 'http://localhost/baz'
82
- @performed_render = true
83
- end
84
-
85
- def render_url ( url )
86
- url = URI . parse ( url )
87
- def url . read ; sleep 0.1 ; path end
88
- response . template . punctuate_body! OpenUriPart . new ( url )
89
- end
90
- end
91
-
92
- tests TestController
93
-
94
- def test_concurrent_open_uri_parts
95
- get :index
96
-
97
- elapsed = Benchmark . ms do
98
- assert_equal '/foo/bar/baz' , @response . body
99
- end
100
- assert ( elapsed - 100 ) . abs < 10 , elapsed
101
- end
102
- end
0 commit comments