Skip to content

Commit f975cc1

Browse files
committed
add spec for instantaneous and unsolicited PUBACKS
the case is already handled by my original refactor for allowing multiple outstanding packets, but this adds the spec to be sure. see njh#158
1 parent f5b6bfa commit f975cc1

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

spec/mqtt/client_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,20 @@ def register_for_ack(packet)
741741
expect(client).to receive(:send_packet) { |packet| expect(packet.id).to eq(2) }
742742
client.publish "topic", "message", qos: 1
743743
end
744+
745+
it "does not crash when receiving a PUBACK for a packet it never sent" do
746+
expect { client.send(:handle_packet, MQTT::Packet::Puback.new(id: 666)) }.not_to raise_error
747+
end
748+
749+
it "does not crash with QoS 1 when the broker sends the PUBACK instantly" do
750+
allow(client).to receive(:send_packet).and_wrap_original do |send_packet, packet, *args, **kwargs, &block|
751+
send_packet.call(packet, *args, **kwargs, &block).tap do
752+
client.send(:handle_packet, MQTT::Packet::Puback.new(id: packet.id))
753+
end
754+
end
755+
756+
expect { client.publish("topic", "message", qos: 1) }.not_to raise_error
757+
end
744758
end
745759

746760
describe "#subscribe" do

0 commit comments

Comments
 (0)