frappy/test/test_multievent.py
Markus Zolliker c5d228ffc4 add timeouts to MultiEvents
to be used for a follow up change for startup events

Change-Id: Id8816eb8f561dcd8d1473e25a9685e796fb14953
Reviewed-on: https://forge.frm2.tum.de/review/c/sine2020/secop/playground/+/27364
Tested-by: Jenkins Automated Tests <pedersen+jenkins@frm2.tum.de>
Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
2021-12-22 15:12:56 +01:00

61 lines
1.8 KiB
Python

# -*- coding: utf-8 -*-
# *****************************************************************************
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Module authors:
# Markus Zolliker <markus.zolliker@psi.ch>
#
# *****************************************************************************
import time
from secop.lib.multievent import MultiEvent
def test_without_timeout():
m = MultiEvent()
s1 = m.setfunc(name='s1')
s2 = m.setfunc(name='s2')
assert not m.wait(0)
assert m.deadline() is None
assert m.waiting_for() == {'s1', 's2'}
s2()
assert m.waiting_for() == {'s1'}
assert not m.wait(0)
s1()
assert not m.waiting_for()
assert m.wait(0)
def test_with_timeout(monkeypatch):
current_time = 1000
monkeypatch.setattr(time, 'monotonic', lambda: current_time)
m = MultiEvent()
assert m.deadline() == 0
m.name = 's1'
s1 = m.setfunc(10)
assert m.deadline() == 1010
m.name = 's2'
s2 = m.setfunc(20)
assert m.deadline() == 1020
current_time += 21
assert not m.wait(0)
assert m.waiting_for() == {'s1', 's2'}
s1()
assert m.waiting_for() == {'s2'}
s2()
assert not m.waiting_for()
assert m.wait(0)