Skip to content

Commit

Permalink
FIX: race condition in test worker made it conditional on hardware sp…
Browse files Browse the repository at this point in the history
…eed, resolved
  • Loading branch information
joshc-slac committed Aug 7, 2024
1 parent 4be9dc5 commit 60e56bc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions beams/tests/test_tree_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_tree_obj_execution(request):
):
for n in tree.tick():
print(f"ticking: {n}")
time.sleep(0.1)
time.sleep(0.05)
print(f"status of tick: {n.status}")

rel_val = caget("PERC:COMP")
Expand Down Expand Up @@ -74,7 +74,7 @@ def test_father_tree_execution(request):
print((tree.root.status, tree.root.status, ct))
for n in tree.root.tick():
print(f"ticking: {n}")
time.sleep(0.1)
time.sleep(0.05)
print(f"status of tick: {n.status}")

check_insert = caget("RET:INSERT")
Expand Down
15 changes: 10 additions & 5 deletions beams/tests/test_worker.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import time
from multiprocessing import Value

from beams.sequencer.helpers.Worker import Worker
Expand All @@ -8,11 +9,12 @@ def test_obj_instantiation(self):
class WorkChild(Worker):
def __init__(self):
super().__init__("test_worker")
self.value = Value('d', 0)
self.value = Value('d', 0) # Note: here value is a member object

def work_func(self):
while (self.do_work.value or self.value.value < 100):
self.value.value += 10
if (self.value.value < 100): # Note: here we reference member object
self.value.value += 10

w = WorkChild()
w.start_work()
Expand All @@ -22,14 +24,16 @@ def work_func(self):

def test_class_member_instantiation(self):
a = Worker("test_worker")
val = Value('i', 10)
val = Value('i', 10) # Note: value declared here to be captured via closure

def work_func(self):
while (self.do_work.value or val.value < 100):
val.value += 10
if (val.value < 100): # Note: value captured via closure
val.value += 10 # Note: value captured via closure
a.set_work_func(work_func)

a.start_work()
time.sleep(1)
a.stop_work()
assert val.value == 100

Expand All @@ -38,7 +42,8 @@ def test_inline_instantation(self):

def work_func(self):
while (self.do_work.value or val.value < 100):
val.value += 10
if (val.value < 100): # Note: value captured via closure
val.value += 10
a = Worker("test_worker", work_func=work_func)
a.start_work()
a.stop_work()
Expand Down

0 comments on commit 60e56bc

Please sign in to comment.