| 11 | |
| 12 | |
| 13 | class Timer: |
| 14 | def __init__(self): |
| 15 | self._cond = threading.Condition() |
| 16 | self._time = 0 |
| 17 | self._stop = 0 |
| 18 | |
| 19 | def time(self): |
| 20 | with self._cond: |
| 21 | return self._time |
| 22 | |
| 23 | # increase the time but not beyond the established limit |
| 24 | def sleep(self, t): |
| 25 | assert t >= 0 |
| 26 | with self._cond: |
| 27 | t += self._time |
| 28 | while self._stop < t: |
| 29 | self._time = self._stop |
| 30 | self._cond.wait() |
| 31 | self._time = t |
| 32 | |
| 33 | # advance time limit for user code |
| 34 | def advance(self, t): |
| 35 | assert t >= 0 |
| 36 | with self._cond: |
| 37 | self._stop += t |
| 38 | self._cond.notify_all() |
| 39 | |
| 40 | |
| 41 | class TestCase(unittest.TestCase): |
no outgoing calls
searching dependent graphs…