def test_eventlet_schedule_action(self):
        scheduler = EventLetEventScheduler()
        ran = [False]

        def action(scheduler, state):
            ran[0] = True
        scheduler.schedule(action)

        eventlet.sleep(0.1)
        assert ran[0] is True
Exemplo n.º 2
0
    def test_eventlet_schedule_action(self):
        scheduler = EventLetEventScheduler()
        ran = [False]

        def action(scheduler, state):
            ran[0] = True
        scheduler.schedule(action)

        eventlet.sleep(0.1)
        assert(ran[0] is True)
    def test_eventlet_schedule_action_periodic_now(self):
        scheduler = EventLetEventScheduler()
        period = 0
        num_times = [3]

        def action(state):
            num_times[0] -= 1

        scheduler.schedule_periodic(period, action)
        eventlet.sleep(0.3)
        assert num_times[0] == 2
    def test_eventlet_schedule_action_cancel(self):
        scheduler = EventLetEventScheduler()
        ran = [False]

        def action(scheduler, state):
            ran[0] = True
        d = scheduler.schedule_relative(1.0, action)
        d.dispose()

        eventlet.sleep(0.01)
        assert not ran[0]
Exemplo n.º 5
0
    def test_eventlet_schedule_action_cancel(self):
        scheduler = EventLetEventScheduler()
        ran = [False]

        def action(scheduler, state):
            ran[0] = True
        d = scheduler.schedule_relative(1.0, action)
        d.dispose()

        eventlet.sleep(0.1)
        assert(not ran[0])
Exemplo n.º 6
0
    def test_eventlet_schedule_action_periodic_now(self):
        scheduler = EventLetEventScheduler()
        period = 0
        num_times = [3]

        def action(scheduler, state):
            num_times[0] -= 1

        scheduler.schedule_periodic(period, action)
        eventlet.sleep(.3)
        assert (num_times[0] == 2)
    def test_eventlet_schedule_action_periodic(self):
        scheduler = EventLetEventScheduler()
        period = 0.05
        counter = [3]

        def action(state):
            if counter[0]:
                counter[0] -= 1

        scheduler.schedule_periodic(period, action)
        eventlet.sleep(0.3)
        assert counter[0] == 0
Exemplo n.º 8
0
    def test_eventlet_schedule_action_periodic(self):
        scheduler = EventLetEventScheduler()
        period = 0.05
        counter = [3]

        def action(state):
            if counter[0]:
                counter[0] -= 1

        scheduler.schedule_periodic(period, action)
        eventlet.sleep(0.3)
        assert counter[0] == 0
Exemplo n.º 9
0
    def test_eventlet_schedule_action_periodic_now(self):
        scheduler = EventLetEventScheduler()
        period = 0
        counter = 3

        def action(state):
            nonlocal counter
            counter -= 1

        scheduler.schedule_periodic(period, action)
        eventlet.sleep(0.3)
        assert counter == 2
Exemplo n.º 10
0
    def test_eventlet_schedule_action_periodic_now(self):
        scheduler = EventLetEventScheduler()
        period = 0
        counter = 3

        def action(state):
            nonlocal counter
            counter -= 1

        scheduler.schedule_periodic(period, action)
        eventlet.sleep(0.3)
        assert counter == 2
Exemplo n.º 11
0
    def test_eventlet_schedule_action(self):
        scheduler = EventLetEventScheduler()
        ran = False

        def action(scheduler, state):
            nonlocal ran
            ran = True

        scheduler.schedule(action)

        eventlet.sleep(0.1)
        assert ran is True
Exemplo n.º 12
0
    def test_eventlet_schedule_action(self):
        scheduler = EventLetEventScheduler()
        ran = False

        def action(scheduler, state):
            nonlocal ran
            ran = True

        scheduler.schedule(action)

        eventlet.sleep(0.1)
        assert ran is True
Exemplo n.º 13
0
    def test_eventlet_schedule_action_cancel(self):
        scheduler = EventLetEventScheduler()
        ran = False

        def action(scheduler, state):
            nonlocal ran
            ran = True

        d = scheduler.schedule_relative(1.0, action)
        d.dispose()

        eventlet.sleep(0.01)
        assert ran is False
Exemplo n.º 14
0
    def test_eventlet_schedule_action_cancel(self):
        scheduler = EventLetEventScheduler()
        ran = False

        def action(scheduler, state):
            nonlocal ran
            ran = True

        d = scheduler.schedule_relative(1.0, action)
        d.dispose()

        eventlet.sleep(0.01)
        assert ran is False
    def test_eventlet_schedule_action_due(self):
        scheduler = EventLetEventScheduler()
        starttime = datetime.now()
        endtime = [None]

        def action(scheduler, state):
            endtime[0] = datetime.now()

        scheduler.schedule_relative(0.2, action)

        eventlet.sleep(0.3)
        diff = endtime[0] - starttime
        assert diff > timedelta(seconds=0.18)
Exemplo n.º 16
0
    def test_eventlet_schedule_action_due(self):
        scheduler = EventLetEventScheduler()
        starttime = datetime.now()
        endtime = [None]

        def action(scheduler, state):
            endtime[0] = datetime.now()

        scheduler.schedule_relative(2.0, action)

        eventlet.sleep(0.3)
        diff = endtime[0]-starttime
        assert(diff > timedelta(seconds=0.18))
Exemplo n.º 17
0
    def test_eventlet_schedule_action_due(self):
        scheduler = EventLetEventScheduler()
        starttime = datetime.now()
        endtime = None

        def action(scheduler, state):
            nonlocal endtime
            endtime = datetime.now()

        scheduler.schedule_relative(0.2, action)

        eventlet.sleep(0.3)
        assert endtime is not None
        diff = endtime - starttime
        assert diff > timedelta(seconds=0.18)
Exemplo n.º 18
0
    def test_eventlet_schedule_action_due(self):
        scheduler = EventLetEventScheduler()
        starttime = datetime.now()
        endtime = None

        def action(scheduler, state):
            nonlocal endtime
            endtime = datetime.now()

        scheduler.schedule_relative(0.2, action)

        eventlet.sleep(0.3)
        assert endtime is not None
        diff = endtime - starttime
        assert diff > timedelta(seconds=0.18)
Exemplo n.º 19
0
 def test_eventlet_schedule_now(self):
     scheduler = EventLetEventScheduler()
     res = scheduler.now - datetime.now()
     assert(res < timedelta(seconds=1))
Exemplo n.º 20
0
 def test_eventlet_schedule_now_units(self):
     scheduler = EventLetEventScheduler()
     diff = scheduler.now
     sleep(0.1)
     diff = scheduler.now - diff
     assert timedelta(milliseconds=80) < diff < timedelta(milliseconds=180)
Exemplo n.º 21
0
 def test_eventlet_schedule_now(self):
     scheduler = EventLetEventScheduler()
     hub = eventlet.hubs.get_hub()
     diff = scheduler.now - datetime.utcfromtimestamp(hub.clock())
     assert abs(diff) < timedelta(milliseconds=1)