From 05b5db1a66898e57c0be3d0fe8b8c9dfc1a3c6a8 Mon Sep 17 00:00:00 2001 From: "Martine S. Lenders" Date: Thu, 16 Apr 2020 18:05:47 +0200 Subject: [PATCH] tests/emcute: add small inter-packet gap between server replies On `samr21-xpro` not all UDP packets were received, leading to the testing automaton to get into an invalid state and failing. This small delay between `sendto()` fixes that issue. --- tests/emcute/tests/01-run.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/emcute/tests/01-run.py b/tests/emcute/tests/01-run.py index 026aec7c1f..4a61c8c881 100755 --- a/tests/emcute/tests/01-run.py +++ b/tests/emcute/tests/01-run.py @@ -13,6 +13,7 @@ import re import socket import sys import subprocess +import threading import time from scapy.all import Automaton, ATMT, log_runtime, MTU, raw, SimpleSocket @@ -24,6 +25,7 @@ TEST_INTERACTIVE_DELAY = int(os.environ.get('TEST_INTERACTIVE_DELAY') or 1) SERVER_PORT = 1883 MODES = set(["pub", "sub", "sub_w_reg"]) +INTER_PACKET_GAP = 0.07 TIMEOUT = 1 @@ -33,6 +35,7 @@ class MQTTSNServer(Automaton): super(MQTTSNServer.MQTTSNServerSocket, self)\ .__init__(*args, **kwargs) self.server = server + self.send_lock = threading.Lock() def recv(self, x=MTU): pkt, sa = self.ins.recvfrom(x) @@ -44,7 +47,13 @@ class MQTTSNServer(Automaton): try: sx = raw(x) x.sent_time = time.time() + # wait if last sendto was less than INTER_PACKET_GAP seconds + # ago + self.send_lock.acquire() self.outs.sendto(sx, self.server.last_remote) + # add small delay between each send to not overwhelm ethos + threading.Timer(INTER_PACKET_GAP, + self.send_lock.release).start() except socket.error as msg: log_runtime.error(msg)