qubitro-mqtt 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,23 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+
3
+ require 'spec_helper'
4
+ require 'qubitro-mqtt'
5
+
6
+ describe MQTT do
7
+
8
+ describe "version number" do
9
+ it "should be defined as a constant" do
10
+ expect(defined?(MQTT::VERSION)).to eq('constant')
11
+ end
12
+
13
+ it "should be a string" do
14
+ expect(MQTT::VERSION).to be_a(String)
15
+ end
16
+
17
+ it "should be in the format x.y.z" do
18
+ expect(MQTT::VERSION).to match(/^\d{1,2}\.\d{1,2}\.\d{1,2}$/)
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,177 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+
3
+ require 'spec_helper'
4
+ require 'qubitro-mqtt'
5
+ require 'fake_server'
6
+
7
+ describe "a client talking to a server" do
8
+
9
+ before(:each) do
10
+ @error_log = StringIO.new
11
+ @server = MQTT::FakeServer.new
12
+ @server.just_one_connection = true
13
+ @server.respond_to_pings = true
14
+ @server.logger = Logger.new(@error_log)
15
+ @server.logger.level = Logger::WARN
16
+ @server.start
17
+
18
+ @client = MQTT::Client.new(@server.address, @server.port)
19
+ end
20
+
21
+ after(:each) do
22
+ @client.disconnect
23
+ @server.stop
24
+ end
25
+
26
+ context "connecting and publishing a packet" do
27
+ def connect_and_publish(options = {})
28
+ @client.connect
29
+
30
+ retain = options.fetch(:retain) { false }
31
+ qos = options.fetch(:qos) { 0 }
32
+
33
+ @client.publish('test', 'foobar', retain, qos)
34
+ @client.disconnect
35
+ @server.thread.join(1)
36
+ end
37
+
38
+ it "the server should have received a packet" do
39
+ connect_and_publish
40
+ expect(@server.last_publish).not_to be_nil
41
+ end
42
+
43
+ it "the server should have received the correct topic" do
44
+ connect_and_publish
45
+ expect(@server.last_publish.topic).to eq('test')
46
+ end
47
+
48
+ it "the server should have received the correct payload" do
49
+ connect_and_publish
50
+ expect(@server.last_publish.payload).to eq('foobar')
51
+ end
52
+
53
+ it "the server should not report any errors" do
54
+ connect_and_publish
55
+ expect(@error_log.string).to be_empty
56
+ end
57
+
58
+ context "with qos > 0" do
59
+ it "the server should have received a packet without timeout" do
60
+ connect_and_publish(:qos => 1)
61
+ expect(@server.last_publish).not_to be_nil
62
+ end
63
+ end
64
+ end
65
+
66
+ context "connecting, subscribing to a topic and getting a message" do
67
+ def connect_and_subscribe
68
+ @client.connect
69
+ @client.subscribe('test')
70
+ @topic, @message = @client.get
71
+ @client.disconnect
72
+ end
73
+
74
+ it "the client should have received the right topic name" do
75
+ connect_and_subscribe
76
+ expect(@topic).to eq('test')
77
+ end
78
+
79
+ it "the client should have received the right message" do
80
+ connect_and_subscribe
81
+ expect(@message).to eq('hello test')
82
+ end
83
+
84
+ it "the server should not report any errors" do
85
+ connect_and_subscribe
86
+ expect(@error_log.string).to be_empty
87
+ end
88
+ end
89
+
90
+ context "connecting, subscribing to a topic and getting a packet" do
91
+ def connect_and_subscribe
92
+ @client.connect
93
+ @client.subscribe('test', 'foobar')
94
+ @packet = @client.get_packet
95
+ @client.disconnect
96
+ end
97
+
98
+ it "the client should have received a packet" do
99
+ connect_and_subscribe
100
+ expect(@packet).not_to be_nil
101
+ end
102
+
103
+ it "the client should have received the correct topic" do
104
+ connect_and_subscribe
105
+ expect(@packet.topic).to eq('test')
106
+ end
107
+
108
+ it "the client should have received the correct payload" do
109
+ connect_and_subscribe
110
+ expect(@packet.payload).to eq('hello test')
111
+ end
112
+
113
+ it "the client should have received a retained packet" do
114
+ connect_and_subscribe
115
+ expect(@packet.retain).to be_truthy
116
+ end
117
+
118
+ it "the server should not report any errors" do
119
+ connect_and_subscribe
120
+ expect(@error_log.string).to be_empty
121
+ end
122
+ end
123
+
124
+ context "sends pings when idle" do
125
+ def connect_and_ping(keep_alive)
126
+ @client.keep_alive = keep_alive
127
+ @client.connect
128
+ @server.thread.join(2)
129
+ @client.disconnect
130
+ end
131
+
132
+ context "when keep-alive=1" do
133
+ it "the server should have received at least one ping" do
134
+ connect_and_ping(1)
135
+ expect(@server.pings_received).to be >= 1
136
+ end
137
+
138
+ it "the server should not report any errors" do
139
+ connect_and_ping(1)
140
+ expect(@error_log.string).to be_empty
141
+ end
142
+ end
143
+
144
+ context "when keep-alive=0" do
145
+ it "the server should not receive any pings" do
146
+ connect_and_ping(0)
147
+ expect(@server.pings_received).to eq(0)
148
+ end
149
+
150
+ it "the server should not report any errors" do
151
+ connect_and_ping(0)
152
+ expect(@error_log.string).to be_empty
153
+ end
154
+ end
155
+ end
156
+
157
+ context "detects server not sending ping responses" do
158
+ def connect_and_timeout(keep_alive)
159
+ @server.respond_to_pings = false
160
+ @client.keep_alive = keep_alive
161
+ @client.connect
162
+ sleep(keep_alive * 3)
163
+ end
164
+
165
+ context "when keep-alive=1" do
166
+ it "the server should have received at least one ping" do
167
+ expect {
168
+ connect_and_timeout(1)
169
+ }.to raise_error(
170
+ MQTT::ProtocolException,
171
+ 'No Ping Response received for 2 seconds'
172
+ )
173
+ end
174
+ end
175
+ end
176
+
177
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qubitro-mqtt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Qubitro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-03-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.11.2
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.11.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 10.2.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 10.2.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: yard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.9.11
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.11
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 3.5.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 3.5.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 0.9.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 0.9.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.48.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.48.0
97
+ description: Pure Ruby gem that implements the MQTT protocol, a lightweight protocol
98
+ for publish/subscribe messaging.
99
+ email: social@qubitro.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - LICENSE.md
105
+ - NEWS.md
106
+ - README.md
107
+ - lib/qubitro-mqtt.rb
108
+ - lib/qubitro-mqtt/client.rb
109
+ - lib/qubitro-mqtt/packet.rb
110
+ - lib/qubitro-mqtt/patches/string_encoding.rb
111
+ - lib/qubitro-mqtt/proxy.rb
112
+ - lib/qubitro-mqtt/sn/packet.rb
113
+ - lib/qubitro-mqtt/version.rb
114
+ - spec/mqtt_client_spec.rb
115
+ - spec/mqtt_packet_spec.rb
116
+ - spec/mqtt_proxy_spec.rb
117
+ - spec/mqtt_sn_packet_spec.rb
118
+ - spec/mqtt_version_spec.rb
119
+ - spec/zz_client_integration_spec.rb
120
+ homepage: https://github.com/qubitro/mqtt-client-ruby
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubygems_version: 3.0.3
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Implementation of the MQTT protocol
143
+ test_files:
144
+ - spec/mqtt_client_spec.rb
145
+ - spec/mqtt_packet_spec.rb
146
+ - spec/mqtt_proxy_spec.rb
147
+ - spec/mqtt_version_spec.rb
148
+ - spec/mqtt_sn_packet_spec.rb
149
+ - spec/zz_client_integration_spec.rb