EpoxyDuino upgrade
This commit is contained in:
@@ -34,6 +34,7 @@ MqttBroker::~MqttBroker()
|
||||
// private constructor used by broker only
|
||||
MqttClient::MqttClient(MqttBroker* local_broker, TcpClient* new_client)
|
||||
{
|
||||
dclass;
|
||||
connect(local_broker);
|
||||
debug("MqttClient private with broker");
|
||||
#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)
|
||||
: local_broker(local_broker), clientId(id)
|
||||
{
|
||||
dclass;
|
||||
alive = 0;
|
||||
keep_alive = 0;
|
||||
|
||||
@@ -58,6 +60,7 @@ MqttClient::MqttClient(MqttBroker* local_broker, const std::string& id)
|
||||
|
||||
MqttClient::~MqttClient()
|
||||
{
|
||||
dtor;
|
||||
close();
|
||||
debug("*** MqttClient delete()");
|
||||
}
|
||||
|
||||
@@ -57,6 +57,15 @@
|
||||
#define debug(what) {}
|
||||
#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
|
||||
using TcpClient = AsyncClient;
|
||||
using TcpServer = AsyncServer;
|
||||
@@ -188,7 +197,7 @@ class MqttClient
|
||||
/** Constructor. Broker is the adress of a local broker if not null
|
||||
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(const std::string& id) : MqttClient(nullptr, id){}
|
||||
MqttClient(const std::string& id) : MqttClient(nullptr, id){ dclass; }
|
||||
|
||||
~MqttClient();
|
||||
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
SUB=
|
||||
|
||||
tests:
|
||||
set -e; \
|
||||
@set -e; \
|
||||
for i in ${SUB}*-tests/Makefile; do \
|
||||
echo '==== Making:' $$(dirname $$i); \
|
||||
$(MAKE) -C $$(dirname $$i) -j; \
|
||||
done
|
||||
|
||||
debugtest:
|
||||
set -e; \
|
||||
@set -e; \
|
||||
$(MAKE) clean; \
|
||||
$(MAKE) -C debug-mode -j; \
|
||||
debug-mode/debug-tests.out
|
||||
|
||||
runtests: debugtest
|
||||
$(MAKE) clean
|
||||
$(MAKE) tests
|
||||
set -e; \
|
||||
@$(MAKE) clean
|
||||
@$(MAKE) tests
|
||||
@set -e; \
|
||||
for i in ${SUB}*-tests/Makefile; do \
|
||||
echo '==== Running:' $$(dirname $$i); \
|
||||
$$(dirname $$i)/$$(dirname $$i).out; \
|
||||
done
|
||||
|
||||
clean:
|
||||
set -e; \
|
||||
@set -e; \
|
||||
for i in ${SUB}*-tests/Makefile; do \
|
||||
echo '==== Cleaning:' $$(dirname $$i); \
|
||||
$(MAKE) -C $$(dirname $$i) clean; \
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
EXTRA_CXXFLAGS=-g3 -O0 -DTINY_MQTT_TESTS
|
||||
|
||||
# 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
|
||||
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)
|
||||
{
|
||||
set_millis(0);
|
||||
EpoxyTest::set_millis(0);
|
||||
reset_and_start_servers(2, true);
|
||||
assertEqual(WiFi.status(), WL_CONNECTED);
|
||||
|
||||
@@ -158,7 +158,7 @@ test(classbind_two_subscribers_binded_one_sender_wildcard)
|
||||
|
||||
for (int i =0; i<10; i++)
|
||||
{
|
||||
add_millis(100);
|
||||
EpoxyTest::add_millis(100);
|
||||
mqtt_a.loop();
|
||||
mqtt_b.loop();
|
||||
mqtt_sender.loop();
|
||||
@@ -167,12 +167,12 @@ test(classbind_two_subscribers_binded_one_sender_wildcard)
|
||||
|
||||
assertEqual(TestReceiver::messages["receiver"], 2);
|
||||
assertEqual(unrouted, 0);
|
||||
set_real_time();
|
||||
EpoxyTest::set_real_time();
|
||||
}
|
||||
|
||||
test(classbind_one_client_receives_the_message)
|
||||
{
|
||||
set_millis(0);
|
||||
EpoxyTest::set_millis(0);
|
||||
reset_and_start_servers(2, true);
|
||||
assertEqual(WiFi.status(), WL_CONNECTED);
|
||||
|
||||
@@ -195,14 +195,14 @@ test(classbind_one_client_receives_the_message)
|
||||
|
||||
for (int i =0; i<10; i++)
|
||||
{
|
||||
add_millis(100);
|
||||
EpoxyTest::add_millis(100);
|
||||
client.loop();
|
||||
broker.loop();
|
||||
}
|
||||
|
||||
assertEqual(TestReceiver::messages["receiver"], 1);
|
||||
assertEqual(unrouted, 0);
|
||||
set_real_time();
|
||||
EpoxyTest::set_real_time();
|
||||
}
|
||||
|
||||
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
|
||||
# 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>)
|
||||
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
|
||||
# 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>)
|
||||
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)
|
||||
{
|
||||
set_millis(0);
|
||||
EpoxyTest::set_millis(0);
|
||||
MqttBroker broker(1883);
|
||||
MqttClient client(&broker);
|
||||
|
||||
broker.loop();
|
||||
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();
|
||||
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();
|
||||
assertEqual(broker.localClientsCount(), (size_t)1); // Ensure client is still connected
|
||||
}
|
||||
|
||||
test(local_wildcard_subscribe)
|
||||
{
|
||||
set_millis(0);
|
||||
EpoxyTest::set_millis(0);
|
||||
MqttBroker broker(1883);
|
||||
MqttClient client(&broker, "client");
|
||||
MqttClient sender(&broker, "sender");
|
||||
@@ -78,7 +78,7 @@ test(local_wildcard_subscribe)
|
||||
|
||||
test(local_client_do_not_disconnect_after_publishing)
|
||||
{
|
||||
set_millis(0);
|
||||
EpoxyTest::set_millis(0);
|
||||
MqttBroker broker(1883);
|
||||
MqttClient client(&broker, "client");
|
||||
MqttClient sender(&broker, "sender");
|
||||
@@ -92,7 +92,7 @@ test(local_client_do_not_disconnect_after_publishing)
|
||||
sender.publish("test", "value");
|
||||
broker.loop();
|
||||
|
||||
add_seconds(60);
|
||||
EpoxyTest::add_seconds(60);
|
||||
client.loop();
|
||||
sender.loop();
|
||||
broker.loop();
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
EXTRA_CXXFLAGS=-g3 -O0
|
||||
|
||||
# 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
|
||||
ARDUINO_LIBS := AUnit AceCommon AceTime TinyMqtt EspMock ESP8266WiFi ESPAsyncTCP TinyConsole
|
||||
|
||||
@@ -157,7 +157,7 @@ test(network_client_alive)
|
||||
const uint32_t keep_alive=1;
|
||||
start_servers(2, true);
|
||||
assertEqual(WiFi.status(), WL_CONNECTED);
|
||||
set_millis(0); // Enter simulated time
|
||||
EpoxyTest::set_millis(0); // Enter simulated time
|
||||
|
||||
MqttBroker broker(1883);
|
||||
broker.begin();
|
||||
@@ -178,18 +178,18 @@ test(network_client_alive)
|
||||
|
||||
// All is going well if we call client.loop()
|
||||
// The client is able to send PingReq to the broker
|
||||
add_seconds(keep_alive);
|
||||
EpoxyTest::add_seconds(keep_alive);
|
||||
client.loop();
|
||||
broker.loop();
|
||||
assertEqual(broker.clientsCount(), (size_t)1);
|
||||
|
||||
// Now simulate that the client is frozen for
|
||||
// a too long time
|
||||
add_seconds(TINY_MQTT_CLIENT_ALIVE_TOLERANCE*2);
|
||||
EpoxyTest::add_seconds(TINY_MQTT_CLIENT_ALIVE_TOLERANCE*2);
|
||||
broker.loop();
|
||||
assertEqual(broker.clientsCount(), (size_t)0);
|
||||
|
||||
set_real_time();
|
||||
EpoxyTest::set_real_time();
|
||||
}
|
||||
|
||||
test(network_client_keep_alive_high)
|
||||
|
||||
Reference in New Issue
Block a user