File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -205,3 +205,43 @@ def test_reconnect(topics, to_send) -> None:
205205 assert user_data .get ("disconnect" ) == True
206206 assert mqtt_client ._connection_manager .close_cnt == 1
207207 assert set (user_data .get ("topics" )) == set ([t [0 ] for t in topics ])
208+
209+
210+ def test_reconnect_not_connected () -> None :
211+ """
212+ Test reconnect() handling not connected.
213+ """
214+ logging .basicConfig ()
215+ logger = logging .getLogger (__name__ )
216+ logger .setLevel (logging .DEBUG )
217+
218+ host = "localhost"
219+ port = 1883
220+
221+ user_data = {"topics" : [], "disconnect" : False }
222+ mqtt_client = MQTT .MQTT (
223+ broker = host ,
224+ port = port ,
225+ ssl_context = ssl .create_default_context (),
226+ connect_retries = 1 ,
227+ user_data = user_data ,
228+ )
229+
230+ mocket = Mocket (
231+ bytearray (
232+ [
233+ 0x20 , # CONNACK
234+ 0x02 ,
235+ 0x00 ,
236+ 0x00 ,
237+ ]
238+ )
239+ )
240+ mqtt_client ._connection_manager = FakeConnectionManager (mocket )
241+
242+ mqtt_client .logger = logger
243+ mqtt_client .on_disconnect = handle_disconnect
244+ mqtt_client .reconnect ()
245+
246+ assert user_data .get ("disconnect" ) == False
247+ assert mqtt_client ._connection_manager .close_cnt == 0
You can’t perform that action at this time.
0 commit comments