1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-24 22:13:52 +01:00

Merge pull request #13882 from miri64/tests/fix/emcute-samr21-xpro

tests/emcute: add small inter-packet gap between server replies
This commit is contained in:
Martine Lenders 2020-04-16 23:34:09 +02:00 committed by GitHub
commit 94e08b9307
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)