Skip to content

Commit

Permalink
Add logging to problematic test
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderWells-diamond committed Sep 18, 2024
1 parent 206cd13 commit 5ce9345
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def create_random_prefix():
return "".join(random.choice(string.ascii_uppercase) for _ in range(12))

# Can't use logging as it's not multiprocess safe, and
# alteratives are overkill
# alternatives are overkill
def log(*args):
print(datetime.now().strftime("%H:%M:%S"), *args)

Expand Down
9 changes: 9 additions & 0 deletions tests/sim_cothread_ioc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from conftest import ADDRESS, log, select_and_recv

if __name__ == "__main__":
log("sim_cothread_ioc starting")
with Client(ADDRESS) as conn:
import cothread

Expand All @@ -18,16 +19,24 @@

import sim_records

log("sim_cothread_ioc records created")

# Run the IOC
builder.LoadDatabase()
softioc.iocInit()

log("sim_cothread_ioc ready")

conn.send("R") # "Ready"

log("sim_cothread_ioc waiting for Done")

select_and_recv(conn, "D") # "Done"
# Attempt to ensure all buffers flushed - C code (from `import pvlog`)
# may not be affected by these calls...
sys.stdout.flush()
sys.stderr.flush()

log("sim_cothread_ioc sending Done")

conn.send("D") # "Ready"
8 changes: 6 additions & 2 deletions tests/test_cothread.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from multiprocessing.connection import Listener

from conftest import requires_cothread, ADDRESS, select_and_recv
from conftest import requires_cothread, ADDRESS, log, select_and_recv

@requires_cothread
def test_cothread_ioc(cothread_ioc):
Expand All @@ -12,8 +12,9 @@ def test_cothread_ioc(cothread_ioc):
pre = cothread_ioc.pv_prefix

with Listener(ADDRESS) as listener, listener.accept() as conn:

log("test_cothread_ioc wait for Ready")
select_and_recv(conn, "R") # "Ready"
log("test_cothread_ioc Ready received")

# Start
assert caget(pre + ":UPTIME").startswith("00:00:0")
Expand All @@ -31,9 +32,12 @@ def test_cothread_ioc(cothread_ioc):
with Context("pva") as ctx:
assert ctx.get(pre + ":STRINGOUT") == "something"

log("test_cothread_ioc sending Done")
conn.send("D") # "Done"

log("test_cothread_ioc waiting for Done")
select_and_recv(conn, "D") # "Done"
log("test_cothread_ioc received Done")

# Stop
cothread_ioc.proc.send_signal(signal.SIGINT)
Expand Down

0 comments on commit 5ce9345

Please sign in to comment.