LIFX::GatewayConnection
write queue resiliency
does not send if there is no available connection
pushes message back into queue if unable to write (FAILED - 1)
Failures:
1) LIFX::GatewayConnection write queue resiliency pushes message back into queue if unable to write
Failure/Error: expect(gateway).to receive(:actually_write).and_return(false, true)
(#<LIFX::GatewayConnection tcp= tcp_attempts=0 udp=#<LIFX::Transport::UDP 127.0.0.1:35003>>).actually_write(any args)
expected: 2 times with any arguments
received: 0 times with any arguments
# ./spec/gateway_connection_spec.rb:22:in `block (3 levels) in <module:LIFX>'
Finished in 0.72379 seconds (files took 0.54662 seconds to load)
I have traced code of gateway_connection.rb.
I think it is caused by thread of message queue pop message out before call actually_write(message) method. At this moment, the queue is empty and flush method check the queue size at the same time. it found queue is empty then return. Thus, actually_write(message) method won't be called.
You can easy reproduce this issue by adding a long sleep right after message = @queue.pop in initialize_write_queue method.
I am new in Ruby world and interested in IoT, so I would like to solve this issue by myself for practicing more. A simple solution is only pop message out after actually_write(message) succeed.
First of all, I need to write a test which can exactly reproduce this issue. But I think that run a large number of loops for trigger the issue is not a good way. Does anyone have suggestions? :D
Hi, The rspec log is below.
I have traced code of
gateway_connection.rb
. I think it is caused by thread of message queue pop message out before callactually_write(message)
method. At this moment, the queue is empty andflush
method check the queue size at the same time. it found queue is empty then return. Thus,actually_write(message)
method won't be called. You can easy reproduce this issue by adding a long sleep right aftermessage = @queue.pop
ininitialize_write_queue
method.I am new in Ruby world and interested in IoT, so I would like to solve this issue by myself for practicing more. A simple solution is only pop message out after
actually_write(message)
succeed. First of all, I need to write a test which can exactly reproduce this issue. But I think that run a large number of loops for trigger the issue is not a good way. Does anyone have suggestions? :D