Esempio n. 1
0
 def test_idle_repeat(self):
     qs = QueueScheduler()
     calls = []
     def idle_add(arg):
         calls.append(arg)
         return len(calls)<10
     qs.idle_add(idle_add, True)
     qs.timeout_add(500, qs.stop)
     qs.run()
     assert len(calls)==10
Esempio n. 2
0
    def test_idle_raises_exception(self):
        qs = QueueScheduler()

        def raise_exception():
            raise Exception("test scheduler error handling")

        with silence_error(log):
            qs.idle_add(raise_exception)
            qs.timeout_add(500, qs.stop)
            qs.run()
Esempio n. 3
0
 def test_idle_timeout(self):
     qs = QueueScheduler()
     calls = []
     def idle_add(arg):
         calls.append(arg)
     qs.idle_add(idle_add, True)
     def timeout_add(arg):
         calls.append(arg)
     qs.timeout_add(100, timeout_add, True)
     qs.timeout_add(500, qs.stop)
     qs.run()
     assert len(calls)==2
Esempio n. 4
0
    def test_idle_cancel(self):
        qs = QueueScheduler()
        calls = []

        def idle_add():
            calls.append(True)
            return True

        tid = qs.idle_add(idle_add)
        copy = []

        def cancel():
            qs.source_remove(tid)
            copy[:] = list(calls)
            return False

        qs.timeout_add(500, cancel)
        qs.timeout_add(1000, qs.stop)
        qs.run()
        assert len(calls) == len(copy), "idle_add continued to run!"
Esempio n. 5
0
 def test_stop_queue(self):
     qs = QueueScheduler()
     qs.idle_add(qs.stop_main_queue)
     qs.run()