def test_task_received(self): state = EventsState() state.get_or_create_worker('worker1') state.get_or_create_worker('worker2') events = [Event('worker-online', hostname='worker1'), Event('worker-online', hostname='worker2'), Event('task-received', uuid=uuid(), name='task1', args='(2, 2)', kwargs="{'foo': 'bar'}", retries=0, eta=None, hostname='worker1')] for i, e in enumerate(events): e['clock'] = i e['local_received'] = time.time() state.event(e) self.app.events.state = state r = self.get('/dashboard') table = HtmlTableParser() table.parse(str(r.body)) self.assertEqual(200, r.code) self.assertEqual(2, len(table.rows())) self.assertEqual(['worker1', 'True', '0', '1', '0', '0', '0', None], table.get_row('worker1')) self.assertEqual(['worker2', 'True', '0', '0', '0', '0', '0', None], table.get_row('worker2'))
def test_tasks(self): state = EventsState() state.get_or_create_worker('worker1') state.get_or_create_worker('worker2') state.get_or_create_worker('worker3') events = [Event('worker-online', hostname='worker1'), Event('worker-online', hostname='worker2')] for i in range(100): events += task_succeeded_events(worker='worker1') for i in range(10): events += task_succeeded_events(worker='worker3') for i in range(13): events += task_failed_events(worker='worker3') for i, e in enumerate(events): e['clock'] = i e['local_received'] = time.time() state.event(e) self.app.events.state = state r = self.get('/dashboard') table = HtmlTableParser() table.parse(str(r.body)) self.assertEqual(200, r.code) self.assertEqual(3, len(table.rows())) self.assertEqual(['worker1', 'True', '0', '100', '0', '100', '0', None], table.get_row('worker1')) self.assertEqual(['worker2', 'True', '0', '0', '0', '0', '0', None], table.get_row('worker2')) self.assertEqual(['worker3', 'True', '0', '23', '13', '10', '0', None], table.get_row('worker3'))
def test_task_received(self): state = EventsState() state.get_or_create_worker('worker1') state.get_or_create_worker('worker2') events = [ Event('worker-online', hostname='worker1'), Event('worker-online', hostname='worker2'), Event('task-received', uuid=uuid(), name='task1', args='(2, 2)', kwargs="{'foo': 'bar'}", retries=0, eta=None, hostname='worker1') ] for i, e in enumerate(events): e['clock'] = i e['local_received'] = time.time() state.event(e) self.app.events.state = state r = self.get('/dashboard') table = HtmlTableParser() table.parse(str(r.body)) self.assertEqual(200, r.code) self.assertEqual(2, len(table.rows())) self.assertEqual(['worker1', 'True', '0', '1', '0', '0', '0', None], table.get_row('worker1')) self.assertEqual(['worker2', 'True', '0', '0', '0', '0', '0', None], table.get_row('worker2'))
def test_single_workers_online(self): state = EventsState() state.get_or_create_worker('worker1') state.event(Event('worker-online', hostname='worker1', local_received=time.time())) self.app.events.state = state r = self.get('/dashboard') table = HtmlTableParser() table.parse(str(r.body)) self.assertEqual(200, r.code) self.assertEqual(1, len(table.rows())) self.assertTrue(table.get_row('worker1')) self.assertEqual(['worker1', 'True', '0', '0', '0', '0', '0', None], table.get_row('worker1')) self.assertFalse(table.get_row('worker2'))
def test_single_workers_online(self): state = EventsState() state.get_or_create_worker('worker1') state.event( Event('worker-online', hostname='worker1', local_received=time.time())) self.app.events.state = state r = self.get('/dashboard') table = HtmlTableParser() table.parse(str(r.body)) self.assertEqual(200, r.code) self.assertEqual(1, len(table.rows())) self.assertTrue(table.get_row('worker1')) self.assertEqual(['worker1', 'True', '0', '0', '0', '0', '0', None], table.get_row('worker1')) self.assertFalse(table.get_row('worker2'))
def test_tasks(self): state = EventsState() state.get_or_create_worker('worker1') state.get_or_create_worker('worker2') state.get_or_create_worker('worker3') events = [ Event('worker-online', hostname='worker1'), Event('worker-online', hostname='worker2') ] for i in range(100): events += task_succeeded_events(worker='worker1') for i in range(10): events += task_succeeded_events(worker='worker3') for i in range(13): events += task_failed_events(worker='worker3') for i, e in enumerate(events): e['clock'] = i e['local_received'] = time.time() state.event(e) self.app.events.state = state r = self.get('/dashboard') table = HtmlTableParser() table.parse(str(r.body)) self.assertEqual(200, r.code) self.assertEqual(3, len(table.rows())) self.assertEqual( ['worker1', 'True', '0', '100', '0', '100', '0', None], table.get_row('worker1')) self.assertEqual(['worker2', 'True', '0', '0', '0', '0', '0', None], table.get_row('worker2')) self.assertEqual(['worker3', 'True', '0', '23', '13', '10', '0', None], table.get_row('worker3'))