Skip to content

Commit

Permalink
Fix integration test from change in MQTT_Publish behavior (#1170)
Browse files Browse the repository at this point in the history
* Fix resend unacked Publish tests

* Add assertion on return value of MQTT_PublishToResend on the packet ID validity

* Hygiene improvement to use resumePersistentSession in PUBLISH resend tests
  • Loading branch information
aggarw13 authored Aug 27, 2020
1 parent 7e4bf86 commit 06e683b
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions libraries/standard/mqtt/integration-test/mqtt_system_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,9 @@ void test_MQTT_Restore_Session_Complete_Incoming_Publish( void )
*/
void test_MQTT_Resend_Unacked_Publish_QoS1( void )
{
/* Start a persistent session with the broker. */
startPersistentSession();

/* Initiate the PUBLISH operation at QoS 1. The library should add an
* outgoing PUBLISH record in the context. */
TEST_ASSERT_EQUAL( MQTTSuccess, publishToTopic(
Expand Down Expand Up @@ -1175,22 +1178,16 @@ void test_MQTT_Resend_Unacked_Publish_QoS1( void )
/* Reset the transport receive function in the context. */
context.transportInterface.recv = Openssl_Recv;

/* Re-establish a TLS+TCP network connection with the server. */
TEST_ASSERT_EQUAL( OPENSSL_SUCCESS, Openssl_Connect( &networkContext,
&serverInfo,
&opensslCredentials,
TRANSPORT_SEND_RECV_TIMEOUT_MS,
TRANSPORT_SEND_RECV_TIMEOUT_MS ) );
TEST_ASSERT_NOT_EQUAL( -1, networkContext.socketDescriptor );
TEST_ASSERT_NOT_NULL( networkContext.pSsl );

/* Re-establish a connection with the broker to resend the PUBLISH packet. */
establishMqttSession( &context, &networkContext, false, &persistentSession );
/* We will re-establish an MQTT over TLS connection with the broker to restore
* the persistent session. */
resumePersistentSession();

/* Obtain the packet ID of the PUBLISH packet that didn't complete in the previous connection. */
MQTTStateCursor_t cursor = MQTT_STATE_CURSOR_INITIALIZER;
uint16_t publishPackedId = MQTT_PublishToResend( &context, &cursor );
TEST_ASSERT_NOT_EQUAL( MQTT_PACKET_ID_INVALID, publishPackedId );

/* Make sure that the packet ID is maintained in the outgoing publish state records. */
TEST_ASSERT_EQUAL( context.outgoingPublishRecords[ 0 ].packetId, publishPackedId );

/* Resend the PUBLISH packet that didn't complete in the previous connection. */
Expand Down Expand Up @@ -1221,6 +1218,9 @@ void test_MQTT_Resend_Unacked_Publish_QoS1( void )
*/
void test_MQTT_Resend_Unacked_Publish_QoS2( void )
{
/* Start a persistent session with the broker. */
startPersistentSession();

/* Initiate the PUBLISH operation at QoS 2. The library should add an
* outgoing PUBLISH record in the context. */
TEST_ASSERT_EQUAL( MQTTSuccess, publishToTopic(
Expand All @@ -1247,22 +1247,16 @@ void test_MQTT_Resend_Unacked_Publish_QoS2( void )
/* Reset the transport receive function in the context. */
context.transportInterface.recv = Openssl_Recv;

/* Re-establish a TLS+TCP network connection with the server. */
TEST_ASSERT_EQUAL( OPENSSL_SUCCESS, Openssl_Connect( &networkContext,
&serverInfo,
&opensslCredentials,
TRANSPORT_SEND_RECV_TIMEOUT_MS,
TRANSPORT_SEND_RECV_TIMEOUT_MS ) );
TEST_ASSERT_NOT_EQUAL( -1, networkContext.socketDescriptor );
TEST_ASSERT_NOT_NULL( networkContext.pSsl );

/* Re-establish a connection with the broker to resend the PUBLISH packet. */
establishMqttSession( &context, &networkContext, false, &persistentSession );
/* We will re-establish an MQTT over TLS connection with the broker to restore
* the persistent session. */
resumePersistentSession();

/* Obtain the packet ID of the PUBLISH packet that didn't complete in the previous connection. */
MQTTStateCursor_t cursor = MQTT_STATE_CURSOR_INITIALIZER;
uint16_t publishPackedId = MQTT_PublishToResend( &context, &cursor );
TEST_ASSERT_NOT_EQUAL( MQTT_PACKET_ID_INVALID, publishPackedId );

/* Make sure that the packet ID is maintained in the outgoing publish state records. */
TEST_ASSERT_EQUAL( context.outgoingPublishRecords[ 0 ].packetId, publishPackedId );

/* Resend the PUBLISH packet that didn't complete in the previous connection. */
Expand Down

0 comments on commit 06e683b

Please sign in to comment.