aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch/live_response_test.rb
blob: 0e8dcc6a16e1f8874e27a15ddde5bbacbd61f2b7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require 'abstract_unit'
require 'active_support/concurrency/latch'

module ActionController
  module Live
    class ResponseTest < ActiveSupport::TestCase
      def setup
        @response = Live::Response.new
      end

      def test_parallel
        latch = ActiveSupport::Concurrency::Latch.new

        t = Thread.new {
          @response.stream.write 'foo'
          latch.await
          @response.stream.close
        }

        @response.each do |part|
          assert_equal 'foo', part
          latch.release
        end
        assert t.join
      end

      def test_setting_body_populates_buffer
        @response.body = 'omg'
        @response.close
        assert_equal ['omg'], @response.body_parts
      end
    end
  end
end