Skip to content

Commit 0d5b50e

Browse files
committed
pluginize concurrent block body part
1 parent 6335f5d commit 0d5b50e

File tree

3 files changed

+2
-107
lines changed

3 files changed

+2
-107
lines changed

actionpack/lib/action_view/base.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,12 @@ def template_format
288288
# Access the current template being rendered.
289289
# Returns a ActionView::Template object.
290290
def template
291-
Thread.current[:_current_render]
291+
@_current_render
292292
end
293293

294294
def template=(template) #:nodoc:
295295
@_first_render ||= template
296-
Thread.current[:_current_render] = template
296+
@_current_render = template
297297
end
298298

299299
def with_template(current_template)

actionpack/lib/action_view/body_parts/concurrent_block.rb

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
require 'abstract_unit'
2-
require 'action_view/body_parts/concurrent_block'
32

43
class BodyPartsTest < ActionController::TestCase
54
RENDERINGS = [Object.new, Object.new, Object.new]
@@ -21,82 +20,3 @@ def test_body_parts
2120
assert_equal RENDERINGS.join, @response.body
2221
end
2322
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

Comments
 (0)