File: test_rt_behavior.py

package info (click to toggle)
python-simpy 2.3.1%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,864 kB
  • sloc: python: 11,171; makefile: 143
file content (36 lines) | stat: -rw-r--r-- 968 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# coding=utf-8

from SimPy.SimulationRT import *


class Ticker(Process):
    def tick(self):
        self.timing = []
        while True:
            yield hold,self,1
            tSim = self.sim.now()
            tRT = self.sim.rtnow()
            self.timing.append((tSim,tRT))


def test_ticker():
    """Tests SimulationRT for degree to which simulation time and wallclock
    time can be synchronized."""
    rel_speed = 10
    sim_slow=SimulationRT()
    t=Ticker(sim=sim_slow)
    sim_slow.activate(t,t.tick())
    sim_slow.simulate(until=10,real_time=True,rel_speed=rel_speed)

    for tSim, tRT in t.timing:
        assert tSim/tRT > rel_speed - 1

    rel_speed = 20
    sim_fast=SimulationRT()
    sim_fast.initialize()
    t=Ticker(sim=sim_fast)
    sim_fast.activate(t,t.tick())
    sim_fast.simulate(until=10,real_time=True,rel_speed=rel_speed)

    for tSim, tRT in t.timing:
        assert tSim/tRT > rel_speed - 1