Files
NODEDC_MISSION_CORE/simulation/ai-polygon/navigation/qualify_ipc.py
T

51 lines
1.6 KiB
Python

"""Bounded Windows snapshot read/replace acceptance; no simulator required."""
import json
import sys
import tempfile
import threading
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from local_state import StateChannel
def main():
errors = []
done = threading.Event()
with tempfile.TemporaryDirectory(prefix="ndc-polygon-ipc-") as folder:
directory = Path(folder)
writer = StateChannel(directory)
writer.write("snapshot", {"sequence": -1})
def reader():
channel = StateChannel(directory)
try:
while not done.is_set():
row = channel.read("snapshot")
if row is None or not -1 <= row["sequence"] < 1000:
raise RuntimeError("Incomplete snapshot read")
except Exception as exc:
errors.append(type(exc).__name__ + ": " + str(exc))
finally:
channel.close()
thread = threading.Thread(target=reader)
thread.start()
try:
for sequence in range(1000):
writer.write("snapshot", {"sequence": sequence, "telemetry": [sequence] * 100})
finally:
done.set()
thread.join()
if errors:
raise RuntimeError(str(errors))
if writer.read("snapshot")["sequence"] != 999:
raise RuntimeError("Final snapshot was not retained")
writer.close()
print(json.dumps({"passed": True, "concurrent_replacements": 1000}))
if __name__ == "__main__":
main()