Sha256: c61a7cc8cfa351bffce12472961a0c91dfd1c296e8cd323527d206ff90004d86

Contents?: true

Size: 812 Bytes

Versions: 19

Compression:

Stored size: 812 Bytes

Contents

require 'helper'

module Bixby
module Test
module WebSocket
class TestAsyncResponse < TestCase

  def test_block

    sync_response = nil
    cb_response = nil

    res = Bixby::WebSocket::AsyncResponse.new("1234") do |r|
      cb_response = r
    end

    assert res
    assert_equal "1234", res.id
    refute res.completed?

    # start a thread waiting on the response to be writ ten
    t = Thread.new {
      sync_response = res.response
    }
    assert t.alive?

    # small sleep here, otherwise execution will continue too quickly, before the thread starts
    assert_nil t.join(0.001)

    # now write it, thread should complete & callback will fire
    res.response = "hi"

    t.join
    refute t.alive?
    assert_equal "hi", cb_response
    assert_equal "hi", sync_response
  end

end
end
end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
bixby-common-0.7.1 test/websocket/async_response_test.rb
bixby-common-0.7.0 test/websocket/async_response_test.rb
bixby-common-0.6.6 test/websocket/async_response_test.rb
bixby-common-0.6.5 test/websocket/async_response_test.rb
bixby-common-0.6.4 test/websocket/async_response_test.rb
bixby-common-0.6.3 test/websocket/async_response_test.rb
bixby-common-0.6.2 test/websocket/async_response_test.rb
bixby-common-0.6.1 test/websocket/async_response_test.rb
bixby-common-0.6.0 test/websocket/async_response_test.rb
bixby-common-0.5.0 test/websocket/async_response_test.rb
bixby-common-0.4.13 test/websocket/async_response_test.rb
bixby-common-0.4.12 test/websocket/async_response_test.rb
bixby-common-0.4.11 test/websocket/async_response_test.rb
bixby-common-0.4.10 test/websocket/async_response_test.rb
bixby-common-0.4.9 test/websocket/async_response_test.rb
bixby-common-0.4.8 test/websocket/async_response_test.rb
bixby-common-0.4.7 test/websocket/async_response_test.rb
bixby-common-0.4.6 test/websocket/async_response_test.rb
bixby-common-0.4.5 test/websocket/async_response_test.rb