Skip to content

Commit

Permalink
Testing to demonstrate the issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesArruda committed Mar 4, 2025
1 parent a867165 commit 3177378
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions src/upstage_des/test/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,3 +476,104 @@ def test_conflicts() -> None:
env.run()
assert data["time_two"] == data["time_three"]
assert data["time_five"] == 1.1


def test_resubmit_wait_events() -> None:
# Test the bug found in github issue 41
# Where Wait wasn't acting like timeout for being resubmitted.

# This illustrates the simpy behavior
with EnvironmentContext() as env:
w1 = Wait(1.1)
w2 = Wait(2.2)

# put the events into simpy
w1.as_event()
w2.as_event()

env.run()
assert env.now == 2.2

# even when the timeout has no callbacks, it completes
with EnvironmentContext() as env:
w1 = Wait(1.1)
w2 = Wait(2.2)

def _proc() -> SIMPY_GEN:
yield w1.as_event() | w2.as_event()
assert env.now == 1.1

env.process(_proc())
env.run()
assert env.now == 2.2

# if we re-wait on w2, it should end at the right time.
with EnvironmentContext() as env:
w1 = Wait(1.1)
w2 = Wait(2.2)

def _proc() -> SIMPY_GEN:
yield w1.as_event() | w2.as_event()
assert env.now == 1.1
yield w2.as_event()
assert env.now == 2.2

env.process(_proc())
env.run()
assert env.now == 2.2


def test_resubmit_get_put_events() -> None:
# Make sure that get/put events don't hang.
with EnvironmentContext() as env:
store1 = SIM.Store(env)
store2 = SIM.Store(env)

def _put_stuff() -> SIMPY_GEN:
yield Wait(1.0).as_event()
yield store1.put("thing")
yield Wait(1.0).as_event()
yield store2.put("other")

def _get_stuff() -> SIMPY_GEN:
g1 = Get(store1)
g2 = Get(store2)
yield g1.as_event() | g2.as_event()
assert g1.is_complete()
assert g1.get_value() == "thing"
assert env.now == 1.0
yield g2.as_event()
assert env.now == 2.0
assert g2.is_complete()
assert g2.get_value() == "other"

env.process(_put_stuff())
env.process(_get_stuff())
env.run()

# run the same through UPSTAGE
with EnvironmentContext() as env:
store1 = SIM.Store(env)
store2 = SIM.Store(env)

def _put_stuff() -> SIMPY_GEN:
yield Wait(1.0).as_event()
yield store1.put("thing")
yield Wait(1.0).as_event()
yield store2.put("other")

def _get_stuff() -> SIMPY_GEN:
g1 = Get(store1)
g2 = Get(store2)
yield Any(g1, g2).as_event()
assert g1.is_complete()
assert g1.get_value() == "thing"
assert env.now == 1.0
yield g2.as_event()
assert env.now == 2.0
assert g2.is_complete()
assert g2.get_value() == "other"

env.process(_put_stuff())
env.process(_get_stuff())
env.run()

0 comments on commit 3177378

Please sign in to comment.