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)