예제 #1
0
파일: executor_test.py 프로젝트: tml/norc
 def test_kill(self):
     self.thread.start()
     wait_until(lambda: self.executor.status == Status.RUNNING, 3)
     self.assertEqual(self.executor.status, Status.RUNNING)
     self.executor.make_request(Request.KILL)
     wait_until(lambda: Status.is_final(self.executor.status), 5)
     self.assertEqual(self.executor.status, Status.KILLED)
예제 #2
0
파일: job_test.py 프로젝트: Smarsh/norc
 def test_job(self):
     schedule = Schedule.create(self.job, self.queue, 1)
     instance = Instance.objects.create(task=self.job, schedule=schedule)
     # instance.log = log.Log(os.devnull)
     self.thread = Thread(target=instance.start)
     self.thread.start()
     wait_until(lambda: self.queue.count() == 2, 2)
     self.assertEqual(set([i.item.node for i in self.queue.items.all()]),
         set([self.nodes[0], self.nodes[1]]))
     for i in self.queue_items():
         self._start_instance(i)
     self.assertEqual(set([i.item.node for i in self.queue.items.all()]),
         set([self.nodes[2], self.nodes[4]]))
     for i in self.queue_items():
         self._start_instance(i)
     self.assertEqual(set([i.item.node for i in self.queue.items.all()]),
         set([self.nodes[3]]))
     for i in self.queue_items():
         self._start_instance(i)
     self.assertEqual(set([i.item.node for i in self.queue.items.all()]),
         set([self.nodes[5]]))
     for i in self.queue_items():
         self._start_instance(i)
     self.thread.join(2)
     self.assertFalse(self.thread.isAlive())
예제 #3
0
 def test_kill(self):
     self.thread.start()
     wait_until(lambda: self.executor.status == Status.RUNNING, 3)
     self.assertEqual(self.executor.status, Status.RUNNING)
     self.executor.make_request(Request.KILL)
     wait_until(lambda: Status.is_final(self.executor.status), 5)
     self.assertEqual(self.executor.status, Status.KILLED)
예제 #4
0
파일: job_test.py 프로젝트: xuanhan863/norc
 def test_job(self):
     schedule = Schedule.create(self.job, self.queue, 1)
     instance = Instance.objects.create(task=self.job, schedule=schedule)
     # instance.log = log.Log(os.devnull)
     self.thread = Thread(target=instance.start)
     self.thread.start()
     wait_until(lambda: self.queue.count() == 2, 2)
     self.assertEqual(set([i.item.node for i in self.queue.items.all()]),
                      set([self.nodes[0], self.nodes[1]]))
     for i in self.queue_items():
         self._start_instance(i)
     self.assertEqual(set([i.item.node for i in self.queue.items.all()]),
                      set([self.nodes[2], self.nodes[4]]))
     for i in self.queue_items():
         self._start_instance(i)
     self.assertEqual(set([i.item.node for i in self.queue.items.all()]),
                      set([self.nodes[3]]))
     for i in self.queue_items():
         self._start_instance(i)
     self.assertEqual(set([i.item.node for i in self.queue.items.all()]),
                      set([self.nodes[5]]))
     for i in self.queue_items():
         self._start_instance(i)
     self.thread.join(2)
     self.assertFalse(self.thread.isAlive())
예제 #5
0
    def test_cron_make_up(self):
        task = make_task()
        queue = make_queue()
        now = datetime.utcnow()
        s = CronSchedule(encoding='o*d*w*h*m*s%s' % ((now.second - 1) % 60),
                         task=task,
                         queue=queue,
                         repetitions=0,
                         remaining=0,
                         make_up=False)
        s.base = now - timedelta(seconds=2)
        s.save()
        self._scheduler.flag.set()
        wait_until(lambda: s.instances.count() == 1, 3)

        now = datetime.utcnow()
        s = CronSchedule(encoding='o*d*w*h*m*s*',
                         task=task,
                         queue=queue,
                         repetitions=0,
                         remaining=0,
                         make_up=True)
        s.base = now - timedelta(seconds=5)
        s.save()
        self._scheduler.flag.set()
        wait_until(lambda: s.instances.count() == 6, 1)
예제 #6
0
 def test_bad_schedule(self):
     task = make_task()
     queue = make_queue()
     s = CronSchedule.create(task, queue, "o*d*w*h*m*s*")
     s.encoding = "gibberish"
     s.save()
     self._scheduler.flag.set()
     wait_until(lambda: CronSchedule.objects.get(pk=s.pk).deleted, 2)
예제 #7
0
 def test_start_stop(self):    
     self.assertEqual(self.executor.status, Status.CREATED)
     self.thread.start()
     wait_until(lambda: self.executor.status == Status.RUNNING, 3)
     self.assertEqual(self.executor.status, Status.RUNNING)
     self.executor.make_request(Request.STOP)
     wait_until(lambda: Status.is_final(self.executor.status), 5)
     self.assertEqual(self.executor.status, Status.ENDED)
예제 #8
0
파일: tests.py 프로젝트: Smarsh/norc
 def test_push_pop(self):
     self.queue.push(self.item)
     self.i = None
     def get_item():
         self.i = self.queue.pop()
         return self.i != None
     wait_until(get_item)
     self.assertEqual(self.item, self.i)
예제 #9
0
파일: executor_test.py 프로젝트: tml/norc
 def test_start_stop(self):    
     self.assertEqual(self.executor.status, Status.CREATED)
     self.thread.start()
     wait_until(lambda: self.executor.status == Status.RUNNING, 3)
     self.assertEqual(self.executor.status, Status.RUNNING)
     self.executor.make_request(Request.STOP)
     wait_until(lambda: Status.is_final(self.executor.status), 5)
     self.assertEqual(self.executor.status, Status.ENDED)
예제 #10
0
 def test_bad_schedule(self):
     task = make_task()
     queue = make_queue()
     s = CronSchedule.create(task, queue, "o*d*w*h*m*s*")
     s.encoding = "gibberish"
     s.save()
     self._scheduler.flag.set()
     wait_until(lambda: CronSchedule.objects.get(pk=s.pk).deleted, 2)
예제 #11
0
 def test_make_up(self):
     task = make_task()
     queue = make_queue()
     s = Schedule.create(task, queue, 1, 10, -10, True)
     self._scheduler.flag.set()
     wait_until(lambda: s.instances.count() == 10, 5)
     s = Schedule.create(task, queue, 60, 10, -10, False)
     self._scheduler.flag.set()
     wait_until(lambda: s.instances.count() == 1, 5)
예제 #12
0
 def test_make_up(self):
     task = make_task()
     queue = make_queue()
     s = Schedule.create(task, queue, 1, 10, -10, True)
     self._scheduler.flag.set()
     wait_until(lambda: s.instances.count() == 10, 5)
     s = Schedule.create(task, queue, 60, 10, -10, False)
     self._scheduler.flag.set()
     wait_until(lambda: s.instances.count() == 1, 5)
예제 #13
0
파일: tests.py 프로젝트: xuanhan863/norc
    def test_push_pop(self):
        self.queue.push(self.item)
        self.i = None

        def get_item():
            self.i = self.queue.pop()
            return self.i != None

        wait_until(get_item)
        self.assertEqual(self.item, self.i)
예제 #14
0
 def test_update_schedule(self):
     task = make_task()
     queue = make_queue()
     s = CronSchedule.create(task, queue, 'o*d*w*h*m*s*', 10)
     self._scheduler.flag.set()
     wait_until(lambda: queue.count() == 2, 5)
     s.encoding = 'o*d*w*h*m*s4'
     s.save()
     self.assertRaises(
         Exception, lambda: wait_until(lambda: s.instances.count() > 3, 3))
예제 #15
0
 def test_update_schedule(self):
     task = make_task()
     queue = make_queue()
     s = CronSchedule.create(task, queue, 'o*d*w*h*m*s*', 10)
     self._scheduler.flag.set()
     wait_until(lambda: queue.count() == 2, 5)
     s.encoding = 'o*d*w*h*m*s4'
     s.save()
     self.assertRaises(Exception,
         lambda: wait_until(lambda: s.instances.count() > 3, 3))
예제 #16
0
 def test_duplicate(self):
     task = make_task()
     queue = make_queue()
     s = Schedule.create(task, queue, 1, 2, start=2)
     self._scheduler.flag.set()
     wait_until(lambda: self.scheduler.schedules.count() == 1, 2)
     s = Schedule.objects.get(pk=s.pk)
     s.scheduler = None
     s.save()
     self._scheduler.flag.set()
     wait_until(lambda: s.instances.count() == 2, 5)
예제 #17
0
 def test_duplicate(self):
     task = make_task()
     queue = make_queue()
     s = Schedule.create(task, queue, 1, 2, start=2)
     self._scheduler.flag.set()
     wait_until(lambda: self.scheduler.schedules.count() == 1, 2)
     s = Schedule.objects.get(pk=s.pk)
     s.scheduler = None
     s.save()
     self._scheduler.flag.set()
     wait_until(lambda: s.instances.count() == 2, 5)
예제 #18
0
 def test_cron(self):
     task = make_task()
     queue = make_queue()
     s = CronSchedule.create(task, queue, 'o*d*w*h*m*s*', 3)
     self._scheduler.flag.set()
     wait_until(lambda: queue.count() == 3, 8)
     enqueued = map(lambda i: i.enqueued, s.instances)
     def fold(acc, e):
         self.assertEqual(e - acc, timedelta(seconds=1))
         return e
     reduce(fold, enqueued)
예제 #19
0
 def test_reload(self):
     task = make_task()
     queue = make_queue()
     now = datetime.utcnow()
     s = CronSchedule.create(task, queue,
                             'o*d*w*h*m*s%s' % ((now.second - 1) % 60), 1)
     self._scheduler.flag.set()
     wait_until(lambda: self.scheduler.cronschedules.count() == 1, 5)
     CronSchedule.objects.get(pk=s.pk).reschedule('o*d*w*h*m*s*')
     self.scheduler.make_request(Request.RELOAD)
     self._scheduler.flag.set()
     wait_until(lambda: s.instances.count() == 1, 10)
예제 #20
0
 def test_reload(self):
     task = make_task()
     queue = make_queue()
     now = datetime.utcnow()
     s = CronSchedule.create(task, queue, 'o*d*w*h*m*s%s' %
         ((now.second - 1) % 60), 1)
     self._scheduler.flag.set()
     wait_until(lambda: self.scheduler.cronschedules.count() == 1, 5)
     CronSchedule.objects.get(pk=s.pk).reschedule('o*d*w*h*m*s*')
     self.scheduler.make_request(Request.RELOAD)
     self._scheduler.flag.set()
     wait_until(lambda: s.instances.count() == 1, 10)
예제 #21
0
    def test_cron(self):
        task = make_task()
        queue = make_queue()
        s = CronSchedule.create(task, queue, 'o*d*w*h*m*s*', 3)
        self._scheduler.flag.set()
        wait_until(lambda: queue.count() == 3, 8)
        enqueued = map(lambda i: i.enqueued, s.instances)

        def fold(acc, e):
            self.assertEqual(e - acc, timedelta(seconds=1))
            return e

        reduce(fold, enqueued)
예제 #22
0
 def test_cron_make_up(self):
     task = make_task()
     queue = make_queue()
     now = datetime.utcnow()
     s = CronSchedule(encoding='o*d*w*h*m*s%s' % ((now.second - 1) % 60),
         task=task, queue=queue, repetitions=0, remaining=0, make_up=False)
     s.base = now - timedelta(seconds=2)
     s.save()
     self._scheduler.flag.set()
     wait_until(lambda: s.instances.count() == 1, 3)
     
     now = datetime.utcnow()
     s = CronSchedule(encoding='o*d*w*h*m*s*',
         task=task, queue=queue, repetitions=0, remaining=0, make_up=True)
     s.base = now - timedelta(seconds=5)
     s.save()
     self._scheduler.flag.set()
     wait_until(lambda: s.instances.count() == 6, 1)
예제 #23
0
 def test_pause_resume(self):
     self.thread.start()
     wait_until(lambda: self.executor.status == Status.RUNNING, 3)
     self.assertEqual(self.executor.status, Status.RUNNING)
     self.executor.make_request(Request.PAUSE)
     wait_until(lambda: self.executor.status == Status.PAUSED, 5)
     self.assertEqual(self.executor.status, Status.PAUSED)
     self.executor.make_request(Request.RESUME)
     wait_until(lambda: self.executor.status == Status.RUNNING, 5)
     self.assertEqual(self.executor.status, Status.RUNNING)
예제 #24
0
파일: executor_test.py 프로젝트: tml/norc
 def test_pause_resume(self):
     self.thread.start()
     wait_until(lambda: self.executor.status == Status.RUNNING, 3)
     self.assertEqual(self.executor.status, Status.RUNNING)
     self.executor.make_request(Request.PAUSE)
     wait_until(lambda: self.executor.status == Status.PAUSED, 5)
     self.assertEqual(self.executor.status, Status.PAUSED)
     self.executor.make_request(Request.RESUME)
     wait_until(lambda: self.executor.status == Status.RUNNING, 5)
     self.assertEqual(self.executor.status, Status.RUNNING)
예제 #25
0
 def setUp(self):
     self._scheduler = Scheduler.objects.create()
     self._scheduler.log = log.Log(os.devnull)
     self.thread = Thread(target=self._scheduler.start)
     self.thread.start()
     wait_until(lambda: self.scheduler.is_alive(), 3)
예제 #26
0
 def test_stop(self):
     self.scheduler.make_request(Request.STOP)
     self._scheduler.flag.set()
     wait_until(lambda: not self.scheduler.is_alive(), 3)
예제 #27
0
 def test_schedule(self):
     task = make_task()
     queue = make_queue()
     s = Schedule.create(task, queue, 0, 5)
     self._scheduler.flag.set()
     wait_until(lambda: s.instances.count() == 5, 5)
예제 #28
0
 def test_stop(self):
     self.scheduler.make_request(Request.STOP)
     self._scheduler.flag.set()
     wait_until(lambda: not self.scheduler.is_alive(), 3)
예제 #29
0
 def test_schedule(self):
     task = make_task()
     queue = make_queue()
     s = Schedule.create(task, queue, 0, 5)
     self._scheduler.flag.set()
     wait_until(lambda: s.instances.count() == 5, 5)
예제 #30
0
파일: queue_test.py 프로젝트: tml/norc
 def test_push_pop(self):
     self.queue.push(self.queue)
     wait_until(self.queue.peek, 10)
     q = self.queue.pop()
     self.assertEqual(self.queue, q)
예제 #31
0
 def setUp(self):
     self._scheduler = Scheduler.objects.create()
     self._scheduler.log = log.Log(os.devnull)
     self.thread = Thread(target=self._scheduler.start)
     self.thread.start()
     wait_until(lambda: self.scheduler.is_alive(), 3)