mirror of
https://github.com/openglow-org/forgefirm.git
synced 2026-10-15 17:19:55 -07:00
forgetest: no press is ever held; the arm notice goes down at the press
- The presence press at the Ready gate polled forgectrl's /status over HTTPS every 0.25 s plus the request's own time, so a short press fell between two reads and the operator held the button for seconds. It is read as an edge from the switches' input events (hw.ButtonEdges, no grab), opened before the notice goes up: a press of any length counts. Events read and not yet looked at are kept, so a short press whose release arrives in the same read gives the release to the next wait. With no switches device (the host harnesses) the status is polled at 50 ms. - An operator's arm notice (arm_press, press_now) stood until the test's next step, over a press already taken. A watcher takes it down the moment the controller puts the button out at the press; a notice put up meanwhile is left alone. Proof: host tests: a press and release written back to back on a FIFO standing in for the switches' device pass the Ready gate in well under a second with the status never showing the button down (the first version dropped the release with the press and waited 10 s: the test caught it); the arm notice stays while the button is dark or lit and goes down when it goes out, and a notice put up meanwhile stays. The fixture (35), setup (87), manifest (26) and operator (22) host tests pass. Acceptance: these are the harness's own paths; every live and operator test with a press runs through them.
This commit is contained in:
@@ -734,6 +734,73 @@ class RoutingTests(unittest.TestCase):
|
||||
finally:
|
||||
runner_mod.hw.button_lit = saved
|
||||
|
||||
@unittest.skipUnless(hasattr(os, "mkfifo"), "needs a FIFO for the switches' event device")
|
||||
def test_ready_reads_a_short_press_as_an_edge(self):
|
||||
"""The presence press is the switches' input events, so a press
|
||||
far shorter than a quarter second counts: the press and release
|
||||
land back to back, and the status the old poll read never shows
|
||||
the button down at all."""
|
||||
dev = os.path.join(self.tmp, "switches")
|
||||
os.mkfifo(dev)
|
||||
os.environ["GF_SWITCH_DEV"] = dev
|
||||
ev = runner_mod.hw.ButtonEdges.EVENT
|
||||
|
||||
def press():
|
||||
with open(dev, "wb") as w:
|
||||
w.write(ev.pack(0, 0, runner_mod.hw.EV_SW, runner_mod.hw.SW_BUTTON, 1) +
|
||||
ev.pack(0, 0, 0, 0, 0) +
|
||||
ev.pack(0, 0, runner_mod.hw.EV_SW, runner_mod.hw.SW_BUTTON, 0))
|
||||
try:
|
||||
run = Run("test", "r.live", "r.live")
|
||||
ctx = Context(run, self.runner, self.reg["r.live"])
|
||||
self.runner.probe_fixture(force=True)
|
||||
self.press_button(False) # the status never shows it down
|
||||
threading.Timer(0.3, press).start()
|
||||
t0 = time.time()
|
||||
ctx.ready("LIVE FIRE. Scrap under the head.")
|
||||
self.assertLess(time.time() - t0, 5)
|
||||
self.assertTrue(run.fixture_takeover)
|
||||
rec = [r for r in run.evidence["actions"] if r["state"] == "presence"]
|
||||
self.assertEqual(len(rec), 1)
|
||||
self.assertIsNone(run.notice) # the notice is down with the press
|
||||
finally:
|
||||
os.environ.pop("GF_SWITCH_DEV", None)
|
||||
|
||||
def test_the_arm_notice_comes_down_when_the_press_is_taken(self):
|
||||
"""The controller puts the button out at the press: the operator's
|
||||
arm notice goes down then, not at the test's next step, so nobody
|
||||
presses again (a press during the job pauses it)."""
|
||||
run = Run("test", "r.live", "r.live")
|
||||
ctx = Context(run, self.runner, self.reg["r.live"])
|
||||
self.runner.probe_fixture(force=True)
|
||||
lit = {"v": False}
|
||||
saved = runner_mod.hw.button_lit
|
||||
runner_mod.hw.button_lit = lambda: lit["v"]
|
||||
try:
|
||||
self.assertFalse(ctx.arm_press()) # the operator's press
|
||||
self.assertIsNotNone(run.notice)
|
||||
time.sleep(0.2)
|
||||
self.assertIsNotNone(run.notice) # dark before the arm: still asked for
|
||||
lit["v"] = True
|
||||
time.sleep(0.2)
|
||||
self.assertIsNotNone(run.notice) # lit: the arm waits for the press
|
||||
lit["v"] = False # the press taken
|
||||
deadline = time.time() + 2
|
||||
while run.notice is not None and time.time() < deadline:
|
||||
time.sleep(0.02)
|
||||
self.assertIsNone(run.notice)
|
||||
# A notice put up meanwhile is not the arm's: it stays.
|
||||
lit["v"] = False
|
||||
self.assertFalse(ctx.arm_press())
|
||||
ctx.notice("Something else.")
|
||||
lit["v"] = True
|
||||
time.sleep(0.2)
|
||||
lit["v"] = False
|
||||
time.sleep(0.3)
|
||||
self.assertEqual((run.notice or {}).get("text"), "Something else.")
|
||||
finally:
|
||||
runner_mod.hw.button_lit = saved
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user