Sha256: 0df7fd69c03e9b9b7de36f4af844426bc4bea19deb9148a961941d29c3ab41cf
Contents?: true
Size: 1.2 KB
Versions: 1
Compression:
Stored size: 1.2 KB
Contents
require 'minitest_helper' describe 'Straming' do let(:request) { Rack::Request.new Hash.new } let(:response) { Rack::Response.new } let(:render) { Rasti::Web::Render.new request, response } it 'Server sent events' do render.server_sent_events :channel_1 response.status.must_equal 200 response['Content-Type'].must_equal 'text/event-stream' response['Cache-Control'].must_equal 'no-cache' response['Connection'].must_equal 'keep-alive' response.body.must_be_instance_of Rasti::Web::Stream events = [] thread = Thread.new do response.body.each { |e| events << e } end channel_1 = Rasti::Web::Channel[:channel_1] channel_2 = Rasti::Web::Channel[:channel_2] sleep 0.05 # Wait for establish connection 3.times do |i| data = {text: "Tick #{i}"} event = Rasti::Web::ServerSentEvent.new data, id: i, event: 'tick' channel_1.publish event channel_2.publish event end Timeout.timeout(3) do while events.count < 3; sleep 0.0001 # Wait for subscriptions end end response.body.close events.must_equal 3.times.map { |i| "id: #{i}\nevent: tick\ndata: {\"text\":\"Tick #{i}\"}\n\n" } end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rasti-web-0.2.1 | spec/streaming_spec.rb |