def test_status_page_ignores_partial_worker(self): # Be sure a worker that has not fully started up # isn't on status page w = Worker() w.last_heartbeat = None w.is_alive = True w.save() r = self.client.get(reverse('system.status')) eq_(r.status_code, 200) eq_(list(r.context['workers']), [])
def test_user_string_truncation(self): user_agent = ('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) ' 'AppleWebKit/535.1 (KHTML, like Gecko) ' 'Chrome/13.0.782.215 Safari/535.1') worker = Worker() worker.save() ts = self.suite() token = Token.create(ts) # This was raising a MySQL error r = self.client.post(reverse('work.query'), dict(worker_id=worker.id, user_agent=user_agent)) eq_(r.status_code, 200)
def test_restart_workers(self): worker = Worker(user_agent='Mozilla/5.0 (Macintosh; U; etc...') worker.save() r = self.client.get(reverse('system.restart_workers')) eq_(r.status_code, 200) data = json.loads(r.content) eq_(data['workers_restarted'], 1) r = self.client.post( reverse('work.query'), dict(worker_id=worker.id, user_agent=worker.user_agent)) eq_(r.status_code, 200) data = json.loads(r.content) eq_(data['cmd'], 'restart') eq_(data['args'], []) eq_(data['desc'], 'Server said restart. Goodbye!')
def test_restart_workers(self): worker = Worker(user_agent='Mozilla/5.0 (Macintosh; U; etc...') worker.save() r = self.client.get(reverse('system.restart_workers')) eq_(r.status_code, 200) data = json.loads(r.content) eq_(data['workers_restarted'], 1) r = self.client.post(reverse('work.query'), dict(worker_id=worker.id, user_agent=worker.user_agent)) eq_(r.status_code, 200) data = json.loads(r.content) eq_(data['cmd'], 'restart') eq_(data['args'], []) eq_(data['desc'], 'Server said restart. Goodbye!')
def test_start_tests_with_partial_worker(self): ts = create_ts() token = Token.create(ts) # Be sure a worker that has not fully started up doesn't get # chosen for work: w = Worker() w.last_heartbeat = None w.is_alive = True w.save() r = self.client.post(reverse('system.start_tests'), data={'browsers': '*', 'token': token, 'name': ts.slug}) eq_(r.status_code, 500) data = json.loads(r.content) eq_(data['error'], True) eq_(data['message'], "No workers for u'*' are connected")
def create_worker(user_agent=None): if not user_agent: user_agent = ('Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; ' 'en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12') worker = Worker() worker.save() worker.parse_user_agent(user_agent) worker.save() return worker
def test_start_tests_with_partial_worker(self): ts = create_ts() token = Token.create(ts) # Be sure a worker that has not fully started up doesn't get # chosen for work: w = Worker() w.last_heartbeat = None w.is_alive = True w.save() r = self.client.post(reverse('system.start_tests'), data={ 'browsers': '*', 'token': token, 'name': ts.slug }) eq_(r.status_code, 500) data = json.loads(r.content) eq_(data['error'], True) eq_(data['message'], "No workers for u'*' are connected")
def test_work(self): user_agent = ('Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; ' 'en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12') worker = Worker() worker.save() ts = self.suite() token = Token.create(ts) # No work to fetch. r = self.client.post(reverse('work.query'), dict(worker_id=worker.id, user_agent=user_agent)) eq_(r.status_code, 200) data = json.loads(r.content) eq_(data['desc'], 'No commands from server.') # Simulate Hudson requesting a job: r = self.client.post(reverse('system.start_tests'), data={ 'browsers': 'firefox', 'token': token, 'name': ts.slug }) eq_(r.status_code, 200) # Do work r = self.client.post(reverse('work.query'), dict(worker_id=worker.id, user_agent=user_agent)) eq_(r.status_code, 200) data = json.loads(r.content) eq_(data['cmd'], 'run_test') eq_(data['args'][0]['url'], ts.default_url) eq_(data['args'][0]['name'], ts.name) work_queue_id = data['args'][0]['work_queue_id'] queue = WorkQueue.objects.get(pk=work_queue_id) eq_(queue.worker.id, worker.id) eq_(queue.finished, False) eq_(queue.results, None) eq_(queue.results_received, False) eq_(queue.worker.last_heartbeat.timetuple()[0:3], datetime.now().timetuple()[0:3]) eq_(queue.worker.user_agent, user_agent) eq_( sorted([(e.engine, e.version) for e in queue.worker.engines.all()]), sorted(parse_useragent(user_agent))) results = { 'failures': 0, 'total': 1, 'tests': [{ 'test': 'foo', 'message': '1 equals 2', 'module': 'some module', 'result': True }] } r = self.client.post( reverse('work.submit_results'), dict(work_queue_id=queue.id, results=json.dumps(results))) eq_(r.status_code, 200) data = json.loads(r.content) eq_(data['desc'], 'Test result received') # Refresh from db... queue = WorkQueue.objects.get(pk=queue.id) eq_(queue.finished, True) eq_(queue.results, json.dumps(results)) eq_(queue.results_received, False) # Cannot fetch more work. r = self.client.post(reverse('work.query'), dict(worker_id=worker.id, user_agent=user_agent)) eq_(r.status_code, 200) data = json.loads(r.content) eq_(data['desc'], 'No commands from server.')
def test_work(self): user_agent = ('Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; ' 'en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12') worker = Worker() worker.save() ts = self.suite() token = Token.create(ts) # No work to fetch. r = self.client.post(reverse('work.query'), dict(worker_id=worker.id, user_agent=user_agent)) eq_(r.status_code, 200) data = json.loads(r.content) eq_(data['desc'], 'No commands from server.') # Simulate Hudson requesting a job: r = self.client.post(reverse('system.start_tests'), data={'browsers': 'firefox', 'token': token, 'name': ts.slug}) eq_(r.status_code, 200) # Do work r = self.client.post(reverse('work.query'), dict(worker_id=worker.id, user_agent=user_agent)) eq_(r.status_code, 200) data = json.loads(r.content) eq_(data['cmd'], 'run_test') eq_(data['args'][0]['url'], ts.default_url) eq_(data['args'][0]['name'], ts.name) work_queue_id = data['args'][0]['work_queue_id'] queue = WorkQueue.objects.get(pk=work_queue_id) eq_(queue.worker.id, worker.id) eq_(queue.finished, False) eq_(queue.results, None) eq_(queue.results_received, False) eq_(queue.worker.last_heartbeat.timetuple()[0:3], datetime.now().timetuple()[0:3]) eq_(queue.worker.user_agent, user_agent) eq_(sorted([(e.engine, e.version) for e in queue.worker.engines.all()]), sorted(parse_useragent(user_agent))) results = { 'failures': 0, 'total': 1, 'tests': [{'test': 'foo', 'message': '1 equals 2', 'module': 'some module', 'result': True}] } r = self.client.post(reverse('work.submit_results'), dict(work_queue_id=queue.id, results=json.dumps(results))) eq_(r.status_code, 200) data = json.loads(r.content) eq_(data['desc'], 'Test result received') # Refresh from db... queue = WorkQueue.objects.get(pk=queue.id) eq_(queue.finished, True) eq_(queue.results, json.dumps(results)) eq_(queue.results_received, False) # Cannot fetch more work. r = self.client.post(reverse('work.query'), dict(worker_id=worker.id, user_agent=user_agent)) eq_(r.status_code, 200) data = json.loads(r.content) eq_(data['desc'], 'No commands from server.')