@@ -247,33 +247,6 @@ TEST_F(MqttIsolatedUnitTest, mqtt_tcp_client_should_receive_loopback_publication
247247 });
248248 client->set_close_handler ([] { std::cout << " closed" << std::endl; });
249249
250- client->set_suback_handler (
251- [&client, &pid_sub1](std::uint16_t packet_id, std::vector<mqtt::suback_return_code> results) {
252- std::cout << " suback received. packet_id: " << packet_id << std::endl;
253- for (auto const &e : results)
254- {
255- std::cout << " subscribe result: " << e << std::endl;
256- }
257-
258- if (packet_id == pid_sub1)
259- {
260- client->async_publish (" mqtt_tcp_client_cpp/topic1" , " test1" , MQTT_NS::qos::at_most_once,
261- // [optional] checking async_publish completion code
262- [](MQTT_NS::error_code ec) {
263- EXPECT_FALSE (ec);
264-
265- std::cout << " async_tcp_publish callback: " << ec.message ()
266- << std::endl;
267- EXPECT_EQ (ec.message (), " Success" );
268- });
269- return true ;
270- }
271-
272- return true ;
273- });
274-
275- client->set_close_handler ([] { std::cout << " closed" << std::endl; });
276-
277250 client->set_suback_handler (
278251 [&client, &pid_sub1](std::uint16_t packet_id, std::vector<mqtt::suback_return_code> results) {
279252 std::cout << " suback received. packet_id: " << packet_id << std::endl;
@@ -318,12 +291,8 @@ TEST_F(MqttIsolatedUnitTest, mqtt_tcp_client_should_receive_loopback_publication
318291 return true ;
319292 });
320293
321- client->async_connect ();
322-
323- m_agentTestHelper->m_ioContext .removeGuard ();
324- m_agentTestHelper->m_ioContext .run_for (2s);
325-
326- ASSERT_TRUE (received);
294+ client->async_connect ([](mqtt::error_code ec) { ASSERT_FALSE (ec) << " CAnnot connect" ; });
295+ ASSERT_TRUE (waitFor (5s, [&received]() { return received; }));
327296}
328297
329298TEST_F (MqttIsolatedUnitTest, should_connect_using_tls)
@@ -446,7 +415,7 @@ TEST_F(MqttIsolatedUnitTest, mqtt_tcp_client_authentication)
446415 ASSERT_NE (0 , m_port);
447416
448417 std::uint16_t pid_sub1;
449-
418+
450419 auto client = mqtt::make_async_client (m_agentTestHelper->m_ioContext .get (), " localhost" , m_port);
451420
452421 client->set_client_id (" cliendId1" );
@@ -544,10 +513,6 @@ TEST_F(MqttIsolatedUnitTest, mqtt_tcp_client_authentication)
544513 return true ;
545514 });
546515
547- client->async_connect ();
548-
549- m_agentTestHelper->m_ioContext .removeGuard ();
550- m_agentTestHelper->m_ioContext .run_for (2s);
551-
552- ASSERT_TRUE (received);
516+ client->async_connect ([](mqtt::error_code ec) { ASSERT_FALSE (ec) << " CAnnot connect" ; });
517+ ASSERT_TRUE (waitFor (5s, [&received]() { return received; }));
553518}
0 commit comments