test: stabilize jt808 smoke sender
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
lingniu
2026-06-29 17:35:12 +08:00
parent acf087a3f5
commit d003757308

View File

@@ -123,11 +123,13 @@ def parse_event_time(value: str) -> dt.datetime:
return parsed return parsed
def send_frame(host: str, port: int, frame: bytes, timeout: float, read_response: bool) -> bytes: def send_frame(host: str, port: int, frame: bytes, timeout: float, read_response: bool, linger_ms: int = 0) -> bytes:
with socket.create_connection((host, port), timeout=timeout) as sock: with socket.create_connection((host, port), timeout=timeout) as sock:
sock.settimeout(timeout) sock.settimeout(timeout)
sock.sendall(frame) sock.sendall(frame)
if not read_response: if not read_response:
if linger_ms > 0:
time.sleep(linger_ms / 1000)
return b"" return b""
try: try:
return sock.recv(1024) return sock.recv(1024)
@@ -147,13 +149,20 @@ def send_register(host: str, port: int, phone: str, serial: int, timeout: float)
) )
def send_location(host: str, port: int, phone: str, serial: int, event_time: dt.datetime, timeout: float) -> bytes: def send_location(host: str,
port: int,
phone: str,
serial: int,
event_time: dt.datetime,
timeout: float,
linger_ms: int) -> bytes:
return send_frame( return send_frame(
host, host,
port, port,
build_frame(0x0200, phone, serial, build_location_body(event_time, serial)), build_frame(0x0200, phone, serial, build_location_body(event_time, serial)),
timeout, timeout,
False, False,
linger_ms,
) )
@@ -313,6 +322,7 @@ def run(args: argparse.Namespace) -> dict[str, Any]:
serial, serial,
event_time + dt.timedelta(seconds=frame_index), event_time + dt.timedelta(seconds=frame_index),
args.tcp_timeout, args.tcp_timeout,
args.linger_ms,
) )
sent += 1 sent += 1
if args.rate > 0: if args.rate > 0: