3. Simulating Connection Issues

Applies to ReadyAPI 3.53, last modified on June 26, 2024

The MQTT protocol was engineered with possible connection issues in view. The broker can store a Will message of a publisher and forward it to listeners if the connection to the publisher is broken. You usually use different topics for messages that contain information about connection problems.

Configuring the Topic Publisher Test Case

  • Switch to the Request Test Case that you created during the first step of this tutorial.

  • Add the Drop MQTT Connection test step to the end of the test case.

    ReadyAPI: Adding the Drop MQTT Connection test step
  • In the test step editor, select SampleConnection from the Connection drop-down list.

  • Click Configure.

  • In the Configure Connection dialog, open the Will message tab.

    ReadyAPI: The Configure Connection dialog
  • Select the Will Message check box.

  • In the Topic field, enter sampletopic/willsample.

  • In the Message box, type the contents of the Will message. In the current case, it is There were connection issues..

  • Click OK to save the changes.

  • You will return back to the editor of the Drop MQTT Connection test step. Select the Close network connection drop method. This will command the test step to simulate the connection loss. In this example, it will be the situation when the connection is lost and the publisher does not send the DISCONNECT packet.

    ReadyAPI: Simulating the fault

Creating a Test Case for Receiving the Will Message

To make sure you are getting the Will message from the broker, you need to prepare a specific test case.

  • Create a new test case.

  • Name it Receive Will Test Case.

  • Add a Receive MQTT Message test step to the new test case in the way described above. This time, specify the sampletopic/willsample subscribed topic to receive the Will message.

Here is what your test will look like.

ReadyAPI: The prepared test

Click the image to enlarge it.

Running the Test

Run the test suite again. Test cases will be executed in parallel.

This time, ReadyAPI will first post a message to the MQTT broker, and then simulate a network connection issue. The Receive Test Case will catch the message you sent first. It will be the same message as the one on the previous step of the tutorial.

The Receive Will Test Case will catch the Will message. You can see it in the Received Message section of the Receive MQTT Message test step.

ReadyAPI: The received Will message

Click the image to enlarge it.

Note: You can use assertions to automatically verify that the message content matches the results you expected.

Prev     Next

See Also

MQTT Testing Tutorial
About IoT MQTT Testing

Highlight search results