Exemplo n.º 1
0
 def test_get_action(self):
     s = sch.Scheduler(nstills=1, actions_per_still=1)
     f = 1
     a = s.get_action(self.dbi, f, ActionClass=self.FakeAction)
     self.assertNotEqual(a, None)  # everything is actionable in this test
     self.assertEqual(a.task, sch.FILE_PROCESSING_LINKS[
         self.dbi.files[f]])  # check this links to the next step
Exemplo n.º 2
0
    def test_start(self):
        self.dbi = PopulatedDataBaseInterface(3, 1, test=True)
        obsnums = self.dbi.list_observations()

        class SuccessAction(sch.Action):
            def _command(me):
                me.dbi = self.dbi
                #print "Action setting {obsnum} status to {status}".format(
                #        status=me.task,obsnum=me.obs)
                me.dbi.set_obs_status(me.obs, me.task)

        def all_done():
            for obsnum in obsnums:
                if self.dbi.get_obs_status(obsnum) != 'COMPLETE': return False
                return True

        s = sch.Scheduler(nstills=1, actions_per_still=1, blocksize=10)
        t = threading.Thread(target=s.start, args=(self.dbi, SuccessAction))
        t.start()
        tstart = time.time()
        completion_time = len(
            FILE_PROCESSING_STAGES) * 3 * 0.2  #0.2 s per file per step
        #print "time to completion:",completion_time,'s'
        while not all_done():
            if time.time() - tstart > completion_time: break
            time.sleep(1)
        s.quit()
        for obsnum in obsnums:
            self.assertEqual(self.dbi.get_obs_status(obsnum), 'COMPLETE')
Exemplo n.º 3
0
 def test_update_action_queue(self):
     s = sch.Scheduler(nstills=1, actions_per_still=1, blocksize=10)
     s.get_new_active_obs(self.dbi)
     s.update_action_queue(self.dbi)
     self.assertEqual(len(s.action_queue), self.nfiles)
     self.assertGreater(s.action_queue[0].priority,
                        s.action_queue[-1].priority)
     for a in s.action_queue:
         self.assertEqual(a.task, 'UV')
Exemplo n.º 4
0
 def test_get_action(self):
     """
     """
     obsnum = self.files[5]
     s = sch.Scheduler(nstills=1, actions_per_still=1)
     tic = time.time()
     a = s.get_action(self.dbi, obsnum, ActionClass=NullAction)
     print "time to execute get_action", time.time() - tic, 's'
     self.assertNotEqual(a, None)  # everything is actionable in this test
     self.assertEqual(a.task, sch.FILE_PROCESSING_LINKS[
         self.dbi.defaultstatus])  # check this links to the next step
Exemplo n.º 5
0
 def test_launch(self):
     dbi = FakeDataBaseInterface(10)
     s = sch.Scheduler(nstills=1, actions_per_still=1, blocksize=10)
     s.get_new_active_obs(self.dbi)
     s.update_action_queue(self.dbi)
     a = s.pop_action_queue(0)
     s.launch_action(a)
     self.assertEqual(s.launched_actions[0], [a])
     self.assertNotEqual(a.launch_time, -1)
     self.assertTrue(s.already_launched(a))
     s.update_action_queue(self.dbi)
     self.assertEqual(
         len(s.action_queue), self.nfiles -
         1)  # make sure this action is excluded from list next time
Exemplo n.º 6
0
    def test_clean_completed_actions(self):
        dbi = FakeDataBaseInterface(10)

        class FakeAction(sch.Action):
            def _command(self):
                dbi.files[self.obs] = self.task

        s = sch.Scheduler(nstills=1, actions_per_still=1, blocksize=10)
        s.get_new_active_obs(self.dbi)
        s.update_action_queue(self.dbi, ActionClass=FakeAction)
        a = s.pop_action_queue(0)
        s.launch_action(a)
        self.assertEqual(len(s.launched_actions[0]), 1)
        s.clean_completed_actions(dbi)
        self.assertEqual(len(s.launched_actions[0]), 0)
Exemplo n.º 7
0
    def test_clean_completed_actions(self):
        """
        todo
        """
        self.dbi = PopulatedDataBaseInterface(3, 1, test=True)

        class SuccessAction(sch.Action):
            def _command(me):
                me.dbi = self.dbi
                me.dbi.set_obs_status(me.obs, me.task)
                print "Action has status:", me.dbi.get_obs_status(me.obs)
                return None

        s = sch.Scheduler(nstills=1, actions_per_still=1, blocksize=10)
        s.get_new_active_obs(self.dbi)
        s.update_action_queue(self.dbi, ActionClass=SuccessAction)
        a = s.pop_action_queue(0)
        s.launch_action(a)
        self.assertEqual(len(s.launched_actions[0]), 1)
        time.sleep(1)
        s.clean_completed_actions(self.dbi)
        self.assertEqual(len(s.launched_actions[0]), 0)
Exemplo n.º 8
0
    def test_start(self):
        dbi = FakeDataBaseInterface(10)

        class FakeAction(sch.Action):
            def _command(self):
                dbi.files[self.obs] = self.task

        def all_done():
            for f in dbi.files:
                if dbi.get_obs_status(f) != 'COMPLETE': return False
            return True

        s = sch.Scheduler(nstills=1, actions_per_still=1, blocksize=10)
        t = threading.Thread(target=s.start,
                             args=(dbi, FakeAction),
                             kwargs={'sleeptime': 0})
        t.start()
        tstart = time.time()
        while not all_done() and time.time() - tstart < 1:
            time.sleep(.1)
        s.quit()
        for f in dbi.files:
            self.assertEqual(dbi.get_obs_status(f), 'COMPLETE')
Exemplo n.º 9
0
    def test_faulty(self):
        for i in xrange(1):
            dbi = FakeDataBaseInterface(10)

            class FakeAction(sch.Action):
                def __init__(self, f, task, neighbors, still):
                    sch.Action.__init__(self,
                                        f,
                                        task,
                                        neighbors,
                                        still,
                                        timeout=.01)

                def _command(self):
                    if random.random() > .5: dbi.files[self.obs] = self.task

            def all_done():
                for f in dbi.files:
                    if dbi.get_obs_status(f) != 'COMPLETE': return False
                return True

            s = sch.Scheduler(nstills=1, actions_per_still=1, blocksize=10)
            t = threading.Thread(target=s.start,
                                 args=(dbi, FakeAction),
                                 kwargs={'sleeptime': 0})
            t.start()
            tstart = time.time()
            while not all_done() and time.time() - tstart < 10:
                #print s.launched_actions[0][0].obs, s.launched_actions[0][0].task
                #print [(a.obs, a.task) for a in s.action_queue]
                time.sleep(.1)
            s.quit()
            #for f in dbi.files:
            #    print f, dbi.files[f]
            for f in dbi.files:
                self.assertEqual(dbi.get_obs_status(f), 'COMPLETE')
Exemplo n.º 10
0
 def test_get_new_active_obs(self):
     s = sch.Scheduler(nstills=1, actions_per_still=1, blocksize=10)
     tic = time.time()
     s.get_new_active_obs(self.dbi)
     print "time to execute get_new_active_obs:", time.time() - tic, 's'
     self.assertEqual(len(s.active_obs), self.ntimes * self.npols)
Exemplo n.º 11
0
 def test_get_new_active_obs(self):
     s = sch.Scheduler(nstills=1, actions_per_still=1)
     s.get_new_active_obs(self.dbi)
     for i in xrange(self.nfiles):
         self.assertTrue(i in s.active_obs)
Exemplo n.º 12
0
 def test_attributes(self):
     s = sch.Scheduler(nstills=1, actions_per_still=1)
     self.assertEqual(s.launched_actions.keys(), [0])