Exemplo n.º 1
0
 def test_timeout_schedule_action_cancel(self):
     ran = False
     scheduler = TimeoutScheduler()
 
     def action(scheduler, state):
         ran = True
     d = scheduler.schedule_relative(timedelta(milliseconds=1), action)
     d.dispose()
 
     sleep(0.1)
     assert (not ran)
Exemplo n.º 2
0
 def test_timeout_schedule_action(self):
     scheduler = TimeoutScheduler()
     ran = [False]
 
     def action(scheduler, state):
         ran[0] = True
 
     scheduler.schedule(action)
 
     sleep(0.1)
     assert (ran[0] == True)
Exemplo n.º 3
0
    def test_timeout_schedule_action(self):
        scheduler = TimeoutScheduler()
        ran = [False]

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

        scheduler.schedule(action)

        sleep(0.1)
        assert (ran[0] is True)
def test_timeout_schedule_action_cancel():
    ran = False
    scheduler = TimeoutScheduler()

    def action(scheduler, state):
        ran = True
    d = scheduler.schedule_relative(timedelta(milliseconds=1), action)
    d.dispose()

    sleep(0.1)
    assert (not ran)
Exemplo n.º 5
0
    def test_timeout_schedule_action(self):
        scheduler = TimeoutScheduler()
        ran = False

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

        scheduler.schedule(action)

        sleep(0.1)
        assert ran is True
Exemplo n.º 6
0
 def test_timeout_schedule_action_due(self):
     scheduler = TimeoutScheduler()
     starttime = datetime.utcnow()
     endtime = [None]
 
     def action(scheduler, state):
         endtime[0] = datetime.utcnow()
 
     scheduler.schedule_relative(timedelta(milliseconds=200), action)
 
     sleep(0.3)
     diff = endtime[0]-starttime
     assert(diff > timedelta(milliseconds=180))
Exemplo n.º 7
0
    def test_timeout_schedule_action_due(self):
        scheduler = TimeoutScheduler()
        starttime = datetime.utcnow()
        endtime = [None]

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

        scheduler.schedule_relative(timedelta(milliseconds=200), action)

        sleep(0.3)
        diff = endtime[0] - starttime
        assert (diff > timedelta(milliseconds=180))
def test_thread_pool_schedule_action_due():
    scheduler = TimeoutScheduler()
    starttime = datetime.utcnow()
    endtime = None
    
    def action(scheduler, state):
        nonlocal endtime
        endtime = datetime.utcnow()
    
    scheduler.schedule_relative(timedelta(milliseconds=200), action)

    sleep(0.3)
    diff = endtime-starttime
    assert(diff > timedelta(milliseconds=180))
Exemplo n.º 9
0
    def test_timeout_schedule_action_due(self):
        scheduler = TimeoutScheduler()
        starttime = default_now()
        endtime = None

        def action(scheduler, state):
            nonlocal endtime
            endtime = default_now()

        scheduler.schedule_relative(timedelta(milliseconds=200), action)

        sleep(0.3)
        assert endtime is not None
        diff = endtime - starttime
        assert diff > timedelta(milliseconds=180)
Exemplo n.º 10
0
    def interval(cls, period, scheduler=None):
        """Returns an observable sequence that produces a value after each period.
        1 - res = rx.Observable.interval(1000)
        2 - res = rx.Observable.interval(1000, rx.Scheduler.timeout)
        
        Keyword arguments:
        period -- Period for producing the values in the resulting sequence 
            (specified as an integer denoting milliseconds).
        scheduler -- [Optional] Scheduler to run the timer on. If not specified,
            rx.Scheduler.timeout is used.
        
        Returns an observable sequence that produces a value after each period.
        """

        scheduler = scheduler or TimeoutScheduler()
        return cls.observable_timer_timespan_and_period(
            period, period, scheduler)
Exemplo n.º 11
0
 def test_timeout_now(self):
     scheduler = TimeoutScheduler()
     res = scheduler.now() - datetime.utcnow()
     assert res < timedelta(microseconds=1000)
Exemplo n.º 12
0
 def test_threadpool_now_units(self):
     scheduler = TimeoutScheduler()
     diff = scheduler.now
     sleep(0.1)
     diff = scheduler.now - diff
     assert timedelta(milliseconds=80) < diff < timedelta(milliseconds=180)
Exemplo n.º 13
0
 def test_timeout_now(self):
     scheduler = TimeoutScheduler()
     diff = scheduler.now - default_now()
     assert abs(diff) < timedelta(milliseconds=1)
Exemplo n.º 14
0
 def test_timeout_now(self):
     scheduler = TimeoutScheduler()
     res = scheduler.now - datetime.utcnow()
     assert res < timedelta(microseconds=1000)
def test_timeout_now():
    res = TimeoutScheduler.now() - datetime.utcnow()
    assert res < timedelta(microseconds=1000)