Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/mqtt/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ def connect(clientid = nil)
# Receive response
receive_connack

# Reset ping stopwatch
@last_ping_request = Time.now
@last_ping_response = Time.now

# Start packet reading thread
@read_thread = Thread.new(Thread.current) do |parent|
Thread.current[:parent] = parent
Expand Down
10 changes: 10 additions & 0 deletions spec/mqtt_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,16 @@
client.connect('myclient')
end

it "should reset @last_ping_request and @last_ping_response" do
frozen_time = Time.now
expect(Time).to receive(:now).exactly(2).and_return(frozen_time)
client.instance_variable_set('@last_ping_request', Time.at(0))
client.instance_variable_set('@last_ping_response', Time.at(0))
client.connect('myclient')
expect(client.instance_variable_get('@last_ping_request')).to eq(frozen_time)
expect(client.instance_variable_get('@last_ping_response')).to eq(frozen_time)
end

context "protocol version 3.1.0" do
it "should write a valid CONNECT packet to the socket if not connected" do
client.version = '3.1.0'
Expand Down