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
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:
sock.settimeout(timeout)
sock.sendall(frame)
if not read_response:
if linger_ms > 0:
time.sleep(linger_ms / 1000)
return b""
try:
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(
host,
port,
build_frame(0x0200, phone, serial, build_location_body(event_time, serial)),
timeout,
False,
linger_ms,
)
@@ -313,6 +322,7 @@ def run(args: argparse.Namespace) -> dict[str, Any]:
serial,
event_time + dt.timedelta(seconds=frame_index),
args.tcp_timeout,
args.linger_ms,
)
sent += 1
if args.rate > 0: