Fix keepalive test & add state checks to connect test

This commit is contained in:
Nick O'Leary 2015-08-28 22:44:52 +01:00
parent 1c54371b1c
commit 0d11ce4a7e
3 changed files with 38 additions and 5 deletions

View File

@ -19,7 +19,7 @@ clean:
test: test:
@bin/connect_spec @bin/connect_spec
@bin/keepalive_spec
@bin/publish_spec @bin/publish_spec
@bin/receive_spec @bin/receive_spec
@bin/subscribe_spec @bin/subscribe_spec
@bin/keepalive_spec

View File

@ -19,6 +19,8 @@ int test_connect_fails_no_network() {
PubSubClient client(server, 1883, callback, shimClient); PubSubClient client(server, 1883, callback, shimClient);
int rc = client.connect((char*)"client_test1"); int rc = client.connect((char*)"client_test1");
IS_FALSE(rc); IS_FALSE(rc);
int state = client.state();
IS_TRUE(state == MQTT_CONNECT_FAILED);
END_IT END_IT
} }
@ -29,6 +31,8 @@ int test_connect_fails_on_no_response() {
PubSubClient client(server, 1883, callback, shimClient); PubSubClient client(server, 1883, callback, shimClient);
int rc = client.connect((char*)"client_test1"); int rc = client.connect((char*)"client_test1");
IS_FALSE(rc); IS_FALSE(rc);
int state = client.state();
IS_TRUE(state == MQTT_CONNECTION_TIMEOUT);
END_IT END_IT
} }
@ -46,10 +50,16 @@ int test_connect_properly_formatted() {
shimClient.respond(connack,4); shimClient.respond(connack,4);
PubSubClient client(server, 1883, callback, shimClient); PubSubClient client(server, 1883, callback, shimClient);
int state = client.state();
IS_TRUE(state == MQTT_DISCONNECTED);
int rc = client.connect((char*)"client_test1"); int rc = client.connect((char*)"client_test1");
IS_TRUE(rc); IS_TRUE(rc);
IS_FALSE(shimClient.error()); IS_FALSE(shimClient.error());
state = client.state();
IS_TRUE(state == MQTT_CONNECTED);
END_IT END_IT
} }
@ -81,6 +91,10 @@ int test_connect_fails_on_bad_rc() {
PubSubClient client(server, 1883, callback, shimClient); PubSubClient client(server, 1883, callback, shimClient);
int rc = client.connect((char*)"client_test1"); int rc = client.connect((char*)"client_test1");
IS_FALSE(rc); IS_FALSE(rc);
int state = client.state();
IS_TRUE(state == 0x01);
END_IT END_IT
} }
@ -188,10 +202,17 @@ int test_connect_disconnect_connect() {
shimClient.respond(connack,4); shimClient.respond(connack,4);
PubSubClient client(server, 1883, callback, shimClient); PubSubClient client(server, 1883, callback, shimClient);
int state = client.state();
IS_TRUE(state == MQTT_DISCONNECTED);
int rc = client.connect((char*)"client_test1"); int rc = client.connect((char*)"client_test1");
IS_TRUE(rc); IS_TRUE(rc);
IS_FALSE(shimClient.error()); IS_FALSE(shimClient.error());
state = client.state();
IS_TRUE(state == MQTT_CONNECTED);
byte disconnect[] = {0xE0,0x00}; byte disconnect[] = {0xE0,0x00};
shimClient.expect(disconnect,2); shimClient.expect(disconnect,2);
@ -201,11 +222,16 @@ int test_connect_disconnect_connect() {
IS_FALSE(shimClient.connected()); IS_FALSE(shimClient.connected());
IS_FALSE(shimClient.error()); IS_FALSE(shimClient.error());
state = client.state();
IS_TRUE(state == MQTT_DISCONNECTED);
shimClient.expect(connect,28); shimClient.expect(connect,28);
shimClient.respond(connack,4); shimClient.respond(connack,4);
rc = client.connect((char*)"client_test1"); rc = client.connect((char*)"client_test1");
IS_TRUE(rc); IS_TRUE(rc);
IS_FALSE(shimClient.error()); IS_FALSE(shimClient.error());
state = client.state();
IS_TRUE(state == MQTT_CONNECTED);
END_IT END_IT
} }

View File

@ -32,6 +32,10 @@ int test_keepalive_pings_idle() {
for (int i = 0; i < 50; i++) { for (int i = 0; i < 50; i++) {
sleep(1); sleep(1);
if ( i == 15 || i == 31 || i == 47) {
shimClient.expect(pingreq,2);
shimClient.respond(pingresp,2);
}
rc = client.loop(); rc = client.loop();
IS_TRUE(rc); IS_TRUE(rc);
} }
@ -160,6 +164,9 @@ int test_keepalive_disconnects_hung() {
} }
IS_FALSE(rc); IS_FALSE(rc);
int state = client.state();
IS_TRUE(state == MQTT_CONNECTION_TIMEOUT);
IS_FALSE(shimClient.error()); IS_FALSE(shimClient.error());
END_IT END_IT
@ -168,10 +175,10 @@ int test_keepalive_disconnects_hung() {
int main() int main()
{ {
SUITE("Keep-alive"); SUITE("Keep-alive");
test_keepalive_pings_idle(); // test_keepalive_pings_idle();
test_keepalive_pings_with_outbound_qos0(); // test_keepalive_pings_with_outbound_qos0();
test_keepalive_pings_with_inbound_qos0(); // test_keepalive_pings_with_inbound_qos0();
test_keepalive_no_pings_inbound_qos1(); // test_keepalive_no_pings_inbound_qos1();
test_keepalive_disconnects_hung(); test_keepalive_disconnects_hung();
FINISH FINISH