def test_dbi(self): self.var = 0 for f in self.dbi.files: self.dbi.files[f] = 'UV_POT' # Jon : HARDWF class NullHandler(ts.TaskHandler): def handle(me): task, obs, still, args = me.get_pkt() t = NullTask(task, obs, still, args, self.dbi) me.server.append_task(t) t.run() self.var += 1 s = ts.TaskServer(self.dbi, handler=NullHandler, port=TEST_PORT) thd = threading.Thread(target=s.start) thd.start() try: sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.sendto(ts.to_pkt('UV', 1, 'still', []), ('127.0.0.1', TEST_PORT)) # Jon : HARDWF while self.var != 1: time.sleep(.6) self.assertEqual(self.var, 1) self.assertEqual(self.dbi.get_obs_status(1), 'UV') # Jon : HARDWF finally: s.shutdown() thd.join()
def test_send_task(self): self.var = 0 class SleepHandler(ts.TaskHandler): def handle(me): self.var += 1 t = SleepTask('UV', 1, 'still', [], self.dbi) # Jon : HARDWF t.run() me.server.append_task(t) s = ts.TaskServer(self.dbi, port=TEST_PORT, handler=SleepHandler) thd = threading.Thread(target=s.start) thd.start() # print("Still port %s") % ts.STILL_PORT try: self.assertEqual(len(s.active_tasks), 0) self.assertEqual(self.var, 0) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.sendto('test', ('localhost', TEST_PORT)) while self.var != 1: time.sleep(.1) self.assertEqual(self.var, 1) self.assertEqual(len(s.active_tasks), 1) finally: s.shutdown() thd.join()
def test_shutdown(self): s = ts.TaskServer(self.dbi, port=TEST_PORT) t = threading.Thread(target=s.start) t.start() s.shutdown() t.join() self.assertFalse(s.is_running)
def test_many_stills(self): dbi = FakeDataBaseInterface() try: os.mkdir('still0') os.mkdir('still1') except (OSError): pass ts0 = ts.TaskServer(dbi, data_dir='still0', port=4441) ts1 = ts.TaskServer(dbi, data_dir='still1', port=4442) ts0_thd = threading.Thread(target=ts0.start) ts1_thd = threading.Thread(target=ts1.start) tc = { 0: ts.TaskClient(dbi, 'localhost', port=4441), 1: ts.TaskClient(dbi, 'localhost', port=4442) } s = ts.Scheduler(tc, actions_per_still=2, blocksize=2) s_thd = threading.Thread(target=s.start, args=(dbi, ), kwargs={ 'ActionClass': ts.Action, 'action_args': (tc, 30), 'sleeptime': 0 }) ts0_thd.start() ts1_thd.start() s_thd.start() try: def all_done(): for f in dbi.files: if dbi.get_obs_status(f) != 'COMPLETE': return False return True while not all_done(): time.sleep(.1) finally: s.quit() ts0.shutdown() ts1.shutdown() s_thd.join() ts0_thd.join() ts1_thd.join() for i in dbi.files: self.assertEqual(dbi.get_obs_status(i), 'COMPLETE')
def test__tx(self): self.pkt = '' class SleepHandler(ts.TaskHandler): def handle(me): self.pkt = me.get_pkt() s = ts.TaskServer(self.dbi, handler=SleepHandler, port=TEST_PORT) thd = threading.Thread(target=s.start) thd.start() try: tc = ts.TaskClient(self.dbi, 'localhost', self.wf, port=TEST_PORT) tc._tx('UV', 1, ['a', 'b', 'c']) # Jon : HARDWF finally: s.shutdown() thd.join() self.assertEqual( self.pkt, ('UV', 1, 'localhost', ['a', 'b', 'c'])) # Jon : HARDWF
def test_basics(self): s = ts.TaskServer(self.dbi, port=TEST_PORT) t = SleepTask('UV', 1, 'still', [], self.dbi) # Jon : HARDWF s.append_task(t) self.assertEqual(len(s.active_tasks), 1) t.run() print("My Pid!: %s") % t.process.pid s.kill(t.process.pid) while t.poll() is None: time.sleep(.01) self.assertEqual(t.poll(), -9) thd = threading.Thread(target=s.finalize_tasks, args=(.1, )) s.is_running = True thd.start() s.is_running = False thd.join() self.assertEqual(len(s.active_tasks), 0)
def setUp(self): self.dbi = FakeDataBaseInterface() self.ts = ts.TaskServer(self.dbi) self.ts_thread = threading.Thread(target=self.ts.start) self.ts_thread.start()