Skip to content

Commit

Permalink
Test multiple disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesa2 committed Feb 16, 2024
1 parent e81c6ca commit 26155f8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class AndroidServiceTest : IMqttActionListener {
var connectToken: IMqttToken = mqttClient.connect(null, null)
connectToken.waitForCompletion(waitForCompletionTime)
var disconnectToken: IMqttToken = mqttClient.disconnect(InstrumentationRegistry.getInstrumentation().targetContext, this)
mqttClient.disconnect(InstrumentationRegistry.getInstrumentation().targetContext, this)
disconnectToken.waitForCompletion(waitForCompletionTime)
connectToken = mqttClient.connect(null, null)
connectToken.waitForCompletion(waitForCompletionTime)
Expand Down Expand Up @@ -86,6 +87,7 @@ class AndroidServiceTest : IMqttActionListener {
val connectedToken1 = connectCallback1.asyncActionToken
assertFalse(connectedToken1!!.sessionPresent)
var disconnectToken: IMqttToken = mqttClient.disconnect(InstrumentationRegistry.getInstrumentation().targetContext, this)
mqttClient.disconnect(InstrumentationRegistry.getInstrumentation().targetContext, this)
disconnectToken.waitForCompletion(waitForCompletionTime)
val options2 = MqttConnectOptions()
options2.isCleanSession = false
Expand All @@ -102,6 +104,7 @@ class AndroidServiceTest : IMqttActionListener {
val connectedToken3 = connectCallback3.asyncActionToken
assertTrue(connectedToken3!!.sessionPresent)
disconnectToken = mqttClient.disconnect(InstrumentationRegistry.getInstrumentation().targetContext, this)
mqttClient.disconnect(InstrumentationRegistry.getInstrumentation().targetContext, this)
disconnectToken.waitForCompletion(waitForCompletionTime)
}
} catch (exception: Exception) {
Expand Down Expand Up @@ -454,6 +457,7 @@ class AndroidServiceTest : IMqttActionListener {

// Disconnect and reconnect to make sure the subscription and all queued messages are cleared.
disconnectToken = mqttClient.disconnect(InstrumentationRegistry.getInstrumentation().targetContext, this)
mqttClient.disconnect(InstrumentationRegistry.getInstrumentation().targetContext, this)
disconnectToken.waitForCompletion(waitForCompletionTime)
mqttClient.close()

Expand All @@ -478,6 +482,7 @@ class AndroidServiceTest : IMqttActionListener {
fail(validateResult.message)
}
disconnectToken = mqttClient.disconnect(InstrumentationRegistry.getInstrumentation().targetContext, this)
mqttClient.disconnect(InstrumentationRegistry.getInstrumentation().targetContext, this)
disconnectToken.waitForCompletion(waitForCompletionTime)
mqttClient.close()

Expand Down Expand Up @@ -507,6 +512,7 @@ class AndroidServiceTest : IMqttActionListener {
} finally {
try {
disconnectToken = mqttClient!!.disconnect(null, null)
mqttClient.disconnect(null, null)
disconnectToken.waitForCompletion(waitForCompletionTime)
mqttClient.close()
} catch (ignored: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@ class AndroidServiceWithActionListenerTest {
var token = mqttClient.connect(null, ActionListener())
token.waitForCompletion(waitForCompletionTime)
token = mqttClient.disconnect(InstrumentationRegistry.getInstrumentation().targetContext, ActionListener())
mqttClient.disconnect(InstrumentationRegistry.getInstrumentation().targetContext, ActionListener())
token.waitForCompletion(waitForCompletionTime)
token = mqttClient.connect(null, ActionListener())
token.waitForCompletion(waitForCompletionTime)
token = mqttClient.disconnect(InstrumentationRegistry.getInstrumentation().targetContext, ActionListener())
mqttClient.disconnect(InstrumentationRegistry.getInstrumentation().targetContext, ActionListener())
token.waitForCompletion(waitForCompletionTime)
}

Expand Down

0 comments on commit 26155f8

Please sign in to comment.