EpoxyDuino upgrade
This commit is contained in:
@@ -34,6 +34,7 @@ MqttBroker::~MqttBroker()
|
|||||||
// private constructor used by broker only
|
// private constructor used by broker only
|
||||||
MqttClient::MqttClient(MqttBroker* local_broker, TcpClient* new_client)
|
MqttClient::MqttClient(MqttBroker* local_broker, TcpClient* new_client)
|
||||||
{
|
{
|
||||||
|
dclass;
|
||||||
connect(local_broker);
|
connect(local_broker);
|
||||||
debug("MqttClient private with broker");
|
debug("MqttClient private with broker");
|
||||||
#ifdef TINY_MQTT_ASYNC
|
#ifdef TINY_MQTT_ASYNC
|
||||||
@@ -50,6 +51,7 @@ MqttClient::MqttClient(MqttBroker* local_broker, TcpClient* new_client)
|
|||||||
MqttClient::MqttClient(MqttBroker* local_broker, const std::string& id)
|
MqttClient::MqttClient(MqttBroker* local_broker, const std::string& id)
|
||||||
: local_broker(local_broker), clientId(id)
|
: local_broker(local_broker), clientId(id)
|
||||||
{
|
{
|
||||||
|
dclass;
|
||||||
alive = 0;
|
alive = 0;
|
||||||
keep_alive = 0;
|
keep_alive = 0;
|
||||||
|
|
||||||
@@ -58,6 +60,7 @@ MqttClient::MqttClient(MqttBroker* local_broker, const std::string& id)
|
|||||||
|
|
||||||
MqttClient::~MqttClient()
|
MqttClient::~MqttClient()
|
||||||
{
|
{
|
||||||
|
dtor;
|
||||||
close();
|
close();
|
||||||
debug("*** MqttClient delete()");
|
debug("*** MqttClient delete()");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,15 @@
|
|||||||
#define debug(what) {}
|
#define debug(what) {}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <TinyConsole.h>
|
||||||
|
#if 0
|
||||||
|
#define dclass { Console << __LINE__ << ':' << __PRETTY_FUNCTION__ << ", this=" << (long)this << endl; }
|
||||||
|
#define dtor { Console << __LINE__ << ": ~" << __PRETTY_FUNCTION__ << ", this=" << (long)this << endl; }
|
||||||
|
#else
|
||||||
|
#define dclass
|
||||||
|
#define dtor
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef TINY_MQTT_ASYNC
|
#ifdef TINY_MQTT_ASYNC
|
||||||
using TcpClient = AsyncClient;
|
using TcpClient = AsyncClient;
|
||||||
using TcpServer = AsyncServer;
|
using TcpServer = AsyncServer;
|
||||||
@@ -188,7 +197,7 @@ class MqttClient
|
|||||||
/** Constructor. Broker is the adress of a local broker if not null
|
/** Constructor. Broker is the adress of a local broker if not null
|
||||||
If you want to connect elsewhere, leave broker null and use connect() **/
|
If you want to connect elsewhere, leave broker null and use connect() **/
|
||||||
MqttClient(MqttBroker* broker = nullptr, const std::string& id = TINY_MQTT_DEFAULT_CLIENT_ID);
|
MqttClient(MqttBroker* broker = nullptr, const std::string& id = TINY_MQTT_DEFAULT_CLIENT_ID);
|
||||||
MqttClient(const std::string& id) : MqttClient(nullptr, id){}
|
MqttClient(const std::string& id) : MqttClient(nullptr, id){ dclass; }
|
||||||
|
|
||||||
~MqttClient();
|
~MqttClient();
|
||||||
|
|
||||||
|
|||||||
@@ -1,29 +1,29 @@
|
|||||||
SUB=
|
SUB=
|
||||||
|
|
||||||
tests:
|
tests:
|
||||||
set -e; \
|
@set -e; \
|
||||||
for i in ${SUB}*-tests/Makefile; do \
|
for i in ${SUB}*-tests/Makefile; do \
|
||||||
echo '==== Making:' $$(dirname $$i); \
|
echo '==== Making:' $$(dirname $$i); \
|
||||||
$(MAKE) -C $$(dirname $$i) -j; \
|
$(MAKE) -C $$(dirname $$i) -j; \
|
||||||
done
|
done
|
||||||
|
|
||||||
debugtest:
|
debugtest:
|
||||||
set -e; \
|
@set -e; \
|
||||||
$(MAKE) clean; \
|
$(MAKE) clean; \
|
||||||
$(MAKE) -C debug-mode -j; \
|
$(MAKE) -C debug-mode -j; \
|
||||||
debug-mode/debug-tests.out
|
debug-mode/debug-tests.out
|
||||||
|
|
||||||
runtests: debugtest
|
runtests: debugtest
|
||||||
$(MAKE) clean
|
@$(MAKE) clean
|
||||||
$(MAKE) tests
|
@$(MAKE) tests
|
||||||
set -e; \
|
@set -e; \
|
||||||
for i in ${SUB}*-tests/Makefile; do \
|
for i in ${SUB}*-tests/Makefile; do \
|
||||||
echo '==== Running:' $$(dirname $$i); \
|
echo '==== Running:' $$(dirname $$i); \
|
||||||
$$(dirname $$i)/$$(dirname $$i).out; \
|
$$(dirname $$i)/$$(dirname $$i).out; \
|
||||||
done
|
done
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
set -e; \
|
@set -e; \
|
||||||
for i in ${SUB}*-tests/Makefile; do \
|
for i in ${SUB}*-tests/Makefile; do \
|
||||||
echo '==== Cleaning:' $$(dirname $$i); \
|
echo '==== Cleaning:' $$(dirname $$i); \
|
||||||
$(MAKE) -C $$(dirname $$i) clean; \
|
$(MAKE) -C $$(dirname $$i) clean; \
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
EXTRA_CXXFLAGS=-g3 -O0 -DTINY_MQTT_TESTS
|
EXTRA_CXXFLAGS=-g3 -O0 -DTINY_MQTT_TESTS
|
||||||
|
|
||||||
# Remove flto flag from EpoxyDuino (too many <optimized out>)
|
# Remove flto flag from EpoxyDuino (too many <optimized out>)
|
||||||
CXXFLAGS = -Wextra -Wall -std=gnu++11 -fno-exceptions -fno-threadsafe-statics
|
CXXFLAGS = -Wextra -Wall -std=gnu++11 -fno-exceptions -fno-threadsafe-statics -DEPOXY_TEST
|
||||||
|
|
||||||
APP_NAME := classbind-tests
|
APP_NAME := classbind-tests
|
||||||
ARDUINO_LIBS := AUnit AceCommon AceTime TinyMqtt EspMock ESP8266WiFi ESPAsyncTCP TinyConsole
|
ARDUINO_LIBS := AUnit AceCommon AceTime TinyMqtt EspMock ESP8266WiFi ESPAsyncTCP TinyConsole
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ void reset_and_start_servers(int n, bool early_accept = true)
|
|||||||
|
|
||||||
test(classbind_two_subscribers_binded_one_sender_wildcard)
|
test(classbind_two_subscribers_binded_one_sender_wildcard)
|
||||||
{
|
{
|
||||||
set_millis(0);
|
EpoxyTest::set_millis(0);
|
||||||
reset_and_start_servers(2, true);
|
reset_and_start_servers(2, true);
|
||||||
assertEqual(WiFi.status(), WL_CONNECTED);
|
assertEqual(WiFi.status(), WL_CONNECTED);
|
||||||
|
|
||||||
@@ -158,7 +158,7 @@ test(classbind_two_subscribers_binded_one_sender_wildcard)
|
|||||||
|
|
||||||
for (int i =0; i<10; i++)
|
for (int i =0; i<10; i++)
|
||||||
{
|
{
|
||||||
add_millis(100);
|
EpoxyTest::add_millis(100);
|
||||||
mqtt_a.loop();
|
mqtt_a.loop();
|
||||||
mqtt_b.loop();
|
mqtt_b.loop();
|
||||||
mqtt_sender.loop();
|
mqtt_sender.loop();
|
||||||
@@ -167,12 +167,12 @@ test(classbind_two_subscribers_binded_one_sender_wildcard)
|
|||||||
|
|
||||||
assertEqual(TestReceiver::messages["receiver"], 2);
|
assertEqual(TestReceiver::messages["receiver"], 2);
|
||||||
assertEqual(unrouted, 0);
|
assertEqual(unrouted, 0);
|
||||||
set_real_time();
|
EpoxyTest::set_real_time();
|
||||||
}
|
}
|
||||||
|
|
||||||
test(classbind_one_client_receives_the_message)
|
test(classbind_one_client_receives_the_message)
|
||||||
{
|
{
|
||||||
set_millis(0);
|
EpoxyTest::set_millis(0);
|
||||||
reset_and_start_servers(2, true);
|
reset_and_start_servers(2, true);
|
||||||
assertEqual(WiFi.status(), WL_CONNECTED);
|
assertEqual(WiFi.status(), WL_CONNECTED);
|
||||||
|
|
||||||
@@ -195,14 +195,14 @@ test(classbind_one_client_receives_the_message)
|
|||||||
|
|
||||||
for (int i =0; i<10; i++)
|
for (int i =0; i<10; i++)
|
||||||
{
|
{
|
||||||
add_millis(100);
|
EpoxyTest::add_millis(100);
|
||||||
client.loop();
|
client.loop();
|
||||||
broker.loop();
|
broker.loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEqual(TestReceiver::messages["receiver"], 1);
|
assertEqual(TestReceiver::messages["receiver"], 1);
|
||||||
assertEqual(unrouted, 0);
|
assertEqual(unrouted, 0);
|
||||||
set_real_time();
|
EpoxyTest::set_real_time();
|
||||||
}
|
}
|
||||||
|
|
||||||
test(classbind_routes_should_be_empty_when_receiver_goes_out_of_scope)
|
test(classbind_routes_should_be_empty_when_receiver_goes_out_of_scope)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# See https://github.com/bxparks/EpoxyDuino for documentation about this
|
# See https://github.com/bxparks/EpoxyDuino for documentation about this
|
||||||
# Makefile to compile and run Arduino programs natively on Linux or MacOS.
|
# Makefile to compile and run Arduino programs natively on Linux or MacOS.
|
||||||
|
|
||||||
EXTRA_CXXFLAGS=-g3 -O0 -DTINY_MQTT_DEBUG
|
EXTRA_CXXFLAGS=-g3 -O0
|
||||||
|
|
||||||
# Remove flto flag from EpoxyDuino (too many <optimized out>)
|
# Remove flto flag from EpoxyDuino (too many <optimized out>)
|
||||||
CXXFLAGS = -Wextra -Wall -std=gnu++11 -fno-exceptions -fno-threadsafe-statics
|
CXXFLAGS = -Wextra -Wall -std=gnu++11 -fno-exceptions -fno-threadsafe-statics
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# See https://github.com/bxparks/EpoxyDuino for documentation about this
|
# See https://github.com/bxparks/EpoxyDuino for documentation about this
|
||||||
# Makefile to compile and run Arduino programs natively on Linux or MacOS.
|
# Makefile to compile and run Arduino programs natively on Linux or MacOS.
|
||||||
|
|
||||||
EXTRA_CXXFLAGS=-g3 -O0 -DTINY_MQTT_DEFAULT_ALIVE=1
|
EXTRA_CXXFLAGS=-g3 -O0 -DTINY_MQTT_DEFAULT_ALIVE=1 -DEPOXY_TEST
|
||||||
|
|
||||||
# Remove flto flag from EpoxyDuino (too many <optimized out>)
|
# Remove flto flag from EpoxyDuino (too many <optimized out>)
|
||||||
CXXFLAGS = -Wextra -Wall -std=gnu++11 -fno-exceptions -fno-threadsafe-statics
|
CXXFLAGS = -Wextra -Wall -std=gnu++11 -fno-exceptions -fno-threadsafe-statics
|
||||||
|
|||||||
@@ -41,25 +41,25 @@ test(local_client_should_unregister_when_destroyed)
|
|||||||
|
|
||||||
test(local_client_alive)
|
test(local_client_alive)
|
||||||
{
|
{
|
||||||
set_millis(0);
|
EpoxyTest::set_millis(0);
|
||||||
MqttBroker broker(1883);
|
MqttBroker broker(1883);
|
||||||
MqttClient client(&broker);
|
MqttClient client(&broker);
|
||||||
|
|
||||||
broker.loop();
|
broker.loop();
|
||||||
assertEqual(broker.localClientsCount(), (size_t)1); // Ensure client is now connected
|
assertEqual(broker.localClientsCount(), (size_t)1); // Ensure client is now connected
|
||||||
|
|
||||||
add_millis(TINY_MQTT_DEFAULT_ALIVE*1000/2);
|
EpoxyTest::add_millis(TINY_MQTT_DEFAULT_ALIVE*1000/2);
|
||||||
broker.loop();
|
broker.loop();
|
||||||
assertEqual(broker.localClientsCount(), (size_t)1); // Ensure client is still connected
|
assertEqual(broker.localClientsCount(), (size_t)1); // Ensure client is still connected
|
||||||
|
|
||||||
add_seconds(TINY_MQTT_DEFAULT_ALIVE*5);
|
EpoxyTest::add_seconds(TINY_MQTT_DEFAULT_ALIVE*5);
|
||||||
broker.loop();
|
broker.loop();
|
||||||
assertEqual(broker.localClientsCount(), (size_t)1); // Ensure client is still connected
|
assertEqual(broker.localClientsCount(), (size_t)1); // Ensure client is still connected
|
||||||
}
|
}
|
||||||
|
|
||||||
test(local_wildcard_subscribe)
|
test(local_wildcard_subscribe)
|
||||||
{
|
{
|
||||||
set_millis(0);
|
EpoxyTest::set_millis(0);
|
||||||
MqttBroker broker(1883);
|
MqttBroker broker(1883);
|
||||||
MqttClient client(&broker, "client");
|
MqttClient client(&broker, "client");
|
||||||
MqttClient sender(&broker, "sender");
|
MqttClient sender(&broker, "sender");
|
||||||
@@ -78,7 +78,7 @@ test(local_wildcard_subscribe)
|
|||||||
|
|
||||||
test(local_client_do_not_disconnect_after_publishing)
|
test(local_client_do_not_disconnect_after_publishing)
|
||||||
{
|
{
|
||||||
set_millis(0);
|
EpoxyTest::set_millis(0);
|
||||||
MqttBroker broker(1883);
|
MqttBroker broker(1883);
|
||||||
MqttClient client(&broker, "client");
|
MqttClient client(&broker, "client");
|
||||||
MqttClient sender(&broker, "sender");
|
MqttClient sender(&broker, "sender");
|
||||||
@@ -92,7 +92,7 @@ test(local_client_do_not_disconnect_after_publishing)
|
|||||||
sender.publish("test", "value");
|
sender.publish("test", "value");
|
||||||
broker.loop();
|
broker.loop();
|
||||||
|
|
||||||
add_seconds(60);
|
EpoxyTest::add_seconds(60);
|
||||||
client.loop();
|
client.loop();
|
||||||
sender.loop();
|
sender.loop();
|
||||||
broker.loop();
|
broker.loop();
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
EXTRA_CXXFLAGS=-g3 -O0
|
EXTRA_CXXFLAGS=-g3 -O0
|
||||||
|
|
||||||
# Remove flto flag from EpoxyDuino (too many <optimized out>)
|
# Remove flto flag from EpoxyDuino (too many <optimized out>)
|
||||||
CXXFLAGS = -Wextra -Wall -std=gnu++11 -fno-exceptions -fno-threadsafe-statics
|
CXXFLAGS = -Wextra -Wall -std=gnu++11 -fno-exceptions -fno-threadsafe-statics -DEPOXY_TEST
|
||||||
|
|
||||||
APP_NAME := network-tests
|
APP_NAME := network-tests
|
||||||
ARDUINO_LIBS := AUnit AceCommon AceTime TinyMqtt EspMock ESP8266WiFi ESPAsyncTCP TinyConsole
|
ARDUINO_LIBS := AUnit AceCommon AceTime TinyMqtt EspMock ESP8266WiFi ESPAsyncTCP TinyConsole
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ test(network_client_alive)
|
|||||||
const uint32_t keep_alive=1;
|
const uint32_t keep_alive=1;
|
||||||
start_servers(2, true);
|
start_servers(2, true);
|
||||||
assertEqual(WiFi.status(), WL_CONNECTED);
|
assertEqual(WiFi.status(), WL_CONNECTED);
|
||||||
set_millis(0); // Enter simulated time
|
EpoxyTest::set_millis(0); // Enter simulated time
|
||||||
|
|
||||||
MqttBroker broker(1883);
|
MqttBroker broker(1883);
|
||||||
broker.begin();
|
broker.begin();
|
||||||
@@ -178,18 +178,18 @@ test(network_client_alive)
|
|||||||
|
|
||||||
// All is going well if we call client.loop()
|
// All is going well if we call client.loop()
|
||||||
// The client is able to send PingReq to the broker
|
// The client is able to send PingReq to the broker
|
||||||
add_seconds(keep_alive);
|
EpoxyTest::add_seconds(keep_alive);
|
||||||
client.loop();
|
client.loop();
|
||||||
broker.loop();
|
broker.loop();
|
||||||
assertEqual(broker.clientsCount(), (size_t)1);
|
assertEqual(broker.clientsCount(), (size_t)1);
|
||||||
|
|
||||||
// Now simulate that the client is frozen for
|
// Now simulate that the client is frozen for
|
||||||
// a too long time
|
// a too long time
|
||||||
add_seconds(TINY_MQTT_CLIENT_ALIVE_TOLERANCE*2);
|
EpoxyTest::add_seconds(TINY_MQTT_CLIENT_ALIVE_TOLERANCE*2);
|
||||||
broker.loop();
|
broker.loop();
|
||||||
assertEqual(broker.clientsCount(), (size_t)0);
|
assertEqual(broker.clientsCount(), (size_t)0);
|
||||||
|
|
||||||
set_real_time();
|
EpoxyTest::set_real_time();
|
||||||
}
|
}
|
||||||
|
|
||||||
test(network_client_keep_alive_high)
|
test(network_client_keep_alive_high)
|
||||||
|
|||||||
Reference in New Issue
Block a user