Skip to content

Commit

Permalink
fixed disconnect tests
Browse files Browse the repository at this point in the history
  • Loading branch information
256dpi committed Dec 4, 2015
1 parent b2a06ba commit efc3242
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/MQTTTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class MQTTTest {
boolean passedTest = false;
String testTopic;
String testPayload;
boolean testConnectivity(boolean test);
};

/* Methods */
Expand All @@ -21,8 +22,10 @@ template <class T>
void MQTTTest<T>::run(T *client) {
this->client = client;

Serial.println("Starting tests...");

Serial.print("[Test 1] Connect: ");
this->printResult(this->client->connect("arduino-mqtt-test", "try", "try"));
this->printResult(this->client->connect("arduino-mqtt-test", "try", "try") && this->testConnectivity(true));

Serial.print("[Test 2] Subscribe & Publish: ");
this->client->subscribe("arduino-mqtt-test/topic1");
Expand All @@ -39,7 +42,9 @@ void MQTTTest<T>::run(T *client) {

Serial.print("[Test 4] Disconnect: ");
this->client->disconnect();
this->printResult(!this->client->connected());
this->printResult(this->testConnectivity(false));

Serial.println("Tests finished!");
}

template <class T>
Expand Down Expand Up @@ -70,3 +75,12 @@ boolean MQTTTest<T>::testMessage(const char *topic, const char *payload) {

return ret;
}

template <class T>
boolean MQTTTest<T>::testConnectivity(boolean test) {
while(this->client->connected() != test) {
this->client->loop();
}

return this->client->connected() == test;
}

0 comments on commit efc3242

Please sign in to comment.