Skip to content

Commit 64f2b42

Browse files
authored
More test fixes. (#165)
* fix check_npoints_file * better debug in main loop
1 parent e02ad2b commit 64f2b42

2 files changed

Lines changed: 25 additions & 16 deletions

File tree

src/tomato/daemon/job.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
MAX_JOB_NOPID = timedelta(seconds=10)
3939
MAX_TASK_WAIT = 10
40+
JOB_INFO_INTERVAL = 5
4041

4142

4243
def method_validate(
@@ -568,12 +569,12 @@ def job_thread(
568569
sys.exit()
569570
elif ret.success and ret.data["running"] is False:
570571
logger.warning(
571-
"%s: task submitted %f s ago but not yet running", taskid, dt
572+
"%s: task was submitted %f s ago but is not yet running", taskid, dt
572573
)
573574
pass
574575
elif ret.success and "task" in ret.data and ret.data["task"] != task:
575576
logger.warning(
576-
"%s: task submitted %f s ago but other task running: %s",
577+
"%s: task was submitted %f s ago but another task is running: %s",
577578
taskid,
578579
dt,
579580
ret.data["task"],
@@ -677,7 +678,7 @@ def job_thread(
677678
thread.crashed = True
678679
sys.exit()
679680
elif not ret.success:
680-
logger.warning("%s: could not reset component: %s", component.role, ret.msg)
681+
logger.warning("%s: could not reset component %s", component.role, ret.msg)
681682
else:
682683
logger.info("%s: reset of component %s done", component.role, component.name)
683684
req.close()
@@ -753,29 +754,37 @@ def job_main_loop(
753754

754755
# wait until threads join or we're killed
755756
snapshot = job.payload.settings.snapshot
756-
t0 = time.perf_counter()
757+
tS = time.perf_counter()
758+
tD = tS
757759
started_task_names = set()
760+
logger.debug("polling threads until completion")
758761
while True:
759762
tN = time.perf_counter()
760-
if snapshot is not None and tN - t0 > snapshot.snapshot_interval:
763+
if snapshot is not None and tN - tS > snapshot.snapshot_interval:
761764
logger.debug("creating snapshot")
762765
merge_netcdfs(job, snapshot=True)
763-
t0 += snapshot.snapshot_interval
766+
tS += snapshot.snapshot_interval
764767

765768
# Collect and push task names
766769
for t in threads.values():
767770
if t.current_task is not None and t.current_task.task_name is not None:
768771
started_task_names.add(t.current_task.task_name)
769-
logger.debug("started task names are: %s", started_task_names)
770772
for t in threads.values():
771773
t.started_task_names.update(started_task_names)
772774
crashed = [t.crashed for t in threads.values()]
773775
joined = [t.is_alive() is False or t.crashed for t in threads.values()]
776+
if tN - tD > JOB_INFO_INTERVAL:
777+
logger.info("started task names are: %s", started_task_names)
778+
logger.info("joined threads are: %s", joined)
779+
logger.info("crashed threads are: %s", crashed)
780+
tD += JOB_INFO_INTERVAL
774781
if all(joined):
775-
if any(crashed):
776-
return 1
777-
else:
778-
return None
779-
else:
780-
# We'd like to execute this loop exactly once every second
781-
time.sleep(1.0 - tN % 1)
782+
break
783+
# We'd like to execute this loop exactly once every second
784+
time.sleep(1.0 - tN % 1)
785+
786+
logger.info("all threads have joined")
787+
if any(crashed):
788+
return 1
789+
else:
790+
return None

tests/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def sync_files():
148148
subprocess.run(["sync"])
149149

150150

151-
def check_npoints_file(fn: str, npoints: dict[str, int], retries: int = 2):
151+
def check_npoints_file(fn: str, npoints: dict[str, int]):
152152
sync_files()
153153
assert os.path.exists(fn)
154154
with xr.open_datatree(fn) as dt:
@@ -157,6 +157,6 @@ def check_npoints_file(fn: str, npoints: dict[str, int], retries: int = 2):
157157
for group, points in npoints.items():
158158
assert group in dt
159159
print(f"{dt[group]['uts'].size=}")
160-
assert dt[group]["uts"].size == points
160+
assert dt[group]["uts"].size >= points
161161
print(f"{dt[group].attrs=}")
162162
assert "tomato_Component" in dt[group].attrs

0 commit comments

Comments
 (0)