test/websocket/api_channel_test.rb in bixby-common-0.5.0 vs test/websocket/api_channel_test.rb in bixby-common-0.6.0

- old
+ new

@@ -20,13 +20,18 @@ attr_reader :api_chan, :ws def setup @em_thread = Thread.new { EM.run{} } @ws = mock("websocket") - @api_chan = Bixby::WebSocket::APIChannel.new(ws, SampleHandler) + @thread_pool = Bixby::ThreadPool.new + @api_chan = Bixby::WebSocket::APIChannel.new(ws, SampleHandler, @thread_pool) end + def teardown + @thread_pool.dispose + end + def test_open refute api_chan.connected? api_chan.open(nil) assert api_chan.connected? end @@ -54,9 +59,16 @@ ws.expects(:send).once.with { |str| res = Bixby::WebSocket::Message.from_wire(str) !res.nil? && res.json_response.to_wire == json_res.to_wire } api_chan.message(event) + + # wait for jobs to finish and cleanup + @thread_pool.dispose + sleep 0.05 + while !EM.defers_finished? do + sleep 0.01 + end end def test_message_response # test receiving a response on the channel cr = CommandResponse.new(:status => 0, :stdout => "foobar", :stderr => "")