Ejemplo n.º 1
0
 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!')
Ejemplo n.º 2
0
 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!')
Ejemplo n.º 3
0
def query(request):
    try:
        worker = Worker.objects.get(pk=request.POST.get('worker_id', 0))
    except (ValueError, Worker.DoesNotExist):
        return {
            'work_queue_id': -1,
            'cmd': 'restart',
            'description': 'Unknown worker ID',
            'args': []
        }
    worker.last_heartbeat = datetime.now()
    worker.parse_user_agent(request.POST['user_agent'])
    worker.save()
    collect_garbage()
    # Look for work, FIFO:
    queue = (WorkQueue.objects
                      .filter(worker=worker, work_received=False)
                      .order_by('created'))
    if not queue.count():
        return {'desc': 'No commands from server.'}
    q = queue[0]
    q.work_received = True
    q.save()
    args = json.loads(q.cmd_args)
    if len(args):
        # Always patch in the work_queue_id because
        # this is awkward to generate when the arg packet is
        # generated.
        args[0]['work_queue_id'] = q.id
    return {
        'work_queue_id': q.id,
        'cmd': q.cmd,
        'desc': q.description,
        'args': args
    }
Ejemplo n.º 4
0
def test_result(request, test_run_id):
    test_run = get_object_or_404(TestRun, pk=test_run_id)
    # Group assertions by module/test
    tests = {}
    for tq in TestRunQueue.objects.filter(test_run=test_run,
                                          work_queue__finished=True):
        for test in json.loads(tq.work_queue.results)['tests']:
            k = (str(test['module']), str(test['test']))
            tests.setdefault(k, [])
            r = {
                'worker_id': tq.work_queue.worker.id,
                'worker_user_agent': tq.work_queue.worker.user_agent,
                'browser': tq.work_queue.worker.browser
            }
            r.update(test)
            tests[k].append(r)

    all_results = []
    for module, test in sorted(tests.keys()):
        all_results.append({
            'module': module,
            'test': test,
            'assertions': tests[(module, test)]
        })

    return {'finished': test_run.is_finished(), 'results': all_results}
Ejemplo n.º 5
0
def test_result(request, test_run_id):
    test_run = get_object_or_404(TestRun, pk=test_run_id)
    # Group assertions by module/test
    tests = {}
    for tq in TestRunQueue.objects.filter(test_run=test_run,
                                          work_queue__finished=True):
        for test in json.loads(tq.work_queue.results)['tests']:
            k = (str(test['module']), str(test['test']))
            tests.setdefault(k, [])
            r = {
                'worker_id': tq.work_queue.worker.id,
                'worker_user_agent': tq.work_queue.worker.user_agent,
                'browser': tq.work_queue.worker.browser
            }
            r.update(test)
            tests[k].append(r)

    all_results = []
    for module, test in sorted(tests.keys()):
        all_results.append({
            'module': module,
            'test': test,
            'assertions': tests[(module, test)]
        })

    return {'finished': test_run.is_finished(), 'results': all_results}
Ejemplo n.º 6
0
def query(request):
    try:
        worker = Worker.objects.get(pk=request.POST.get('worker_id', 0))
    except (ValueError, Worker.DoesNotExist):
        return {
            'work_queue_id': -1,
            'cmd': 'restart',
            'description': 'Unknown worker ID',
            'args': []
        }
    worker.last_heartbeat = datetime.now()
    worker.parse_user_agent(request.POST['user_agent'])
    worker.save()
    collect_garbage()
    # Look for work, FIFO:
    queue = (WorkQueue.objects.filter(worker=worker,
                                      work_received=False).order_by('created'))
    if not queue.count():
        return {'desc': 'No commands from server.'}
    q = queue[0]
    q.work_received = True
    q.save()
    args = json.loads(q.cmd_args)
    if len(args):
        # Always patch in the work_queue_id because
        # this is awkward to generate when the arg packet is
        # generated.
        args[0]['work_queue_id'] = q.id
    return {
        'work_queue_id': q.id,
        'cmd': q.cmd,
        'desc': q.description,
        'args': args
    }
Ejemplo n.º 7
0
def submit_results(request):
    q = get_object_or_404(WorkQueue, pk=request.POST.get('work_queue_id', 0))
    results = json.loads(request.POST['results'])
    if results.get('test_run_error'):
        tests = results.get('tests', [])
        tests.append({
            'result': False,
            'module': '__jstestnet__',
            'test': 'test_run_error',
            'message': results['test_run_error_msg']
        })
        results['tests'] = tests
    if 'tests' not in results:
        raise ValueError('Results JSON is missing key tests (list)')
    for i, test in enumerate(results['tests']):
        if 'result' not in test:
            raise ValueError('results.tests[%s] JSON is missing key result '
                             '(True or False)' % i)
        for k in ('module', 'test', 'message'):
            if k not in test:
                test[k] = '<%r was empty>' % k
    q.finished = True
    q.results = json.dumps(results)
    q.save()
    return {'desc': 'Test result received'}
Ejemplo n.º 8
0
def submit_results(request):
    q = get_object_or_404(WorkQueue,
                          pk=request.POST.get('work_queue_id', 0))
    results = json.loads(request.POST['results'])
    if results.get('test_run_error'):
        tests = results.get('tests', [])
        tests.append({
            'result': False,
            'module': '__jstestnet__',
            'test': 'test_run_error',
            'message': results['test_run_error_msg']
        })
        results['tests'] = tests
    if 'tests' not in results:
        raise ValueError('Results JSON is missing key tests (list)')
    for i, test in enumerate(results['tests']):
        if 'result' not in test:
            raise ValueError(
                'results.tests[%s] JSON is missing key result '
                '(True or False)' % i)
        for k in ('module', 'test', 'message'):
            if k not in test:
                test[k] = '<%r was empty>' % k
    q.finished = True
    q.results = json.dumps(results)
    q.save()
    return {
        'desc': 'Test result received'
    }
Ejemplo n.º 9
0
 def test_invalid_input_gets_told_to_restart(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')
     r = self.client.post(
         reverse('work.query'),
         dict(worker_id='some kind of garbage', user_agent=user_agent))
     eq_(r.status_code, 200)
     data = json.loads(r.content)
     eq_(data['cmd'], 'restart')
Ejemplo n.º 10
0
 def test_invalid_input_gets_told_to_restart(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')
     r = self.client.post(reverse('work.query'),
                          dict(worker_id='some kind of garbage',
                               user_agent=user_agent))
     eq_(r.status_code, 200)
     data = json.loads(r.content)
     eq_(data['cmd'], 'restart')
Ejemplo n.º 11
0
 def test_zombie_worker_gets_told_to_restart(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')
     # post an unknown worker ID
     r = self.client.post(reverse('work.query'),
                          dict(worker_id=666, user_agent=user_agent))
     eq_(r.status_code, 200)
     data = json.loads(r.content)
     eq_(data['cmd'], 'restart')
Ejemplo n.º 12
0
 def test_zombie_worker_gets_told_to_restart(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')
     # post an unknown worker ID
     r = self.client.post(reverse('work.query'),
                          dict(worker_id=666, user_agent=user_agent))
     eq_(r.status_code, 200)
     data = json.loads(r.content)
     eq_(data['cmd'], 'restart')
Ejemplo n.º 13
0
 def test_start_tests_with_no_workers(self):
     ts = create_ts()
     token = Token.create(ts)
     r = self.client.post(reverse('system.start_tests'),
                          data={'browsers': 'firefox', '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'firefox' are connected")
Ejemplo n.º 14
0
    def test_start_tests_with_correct_token(self):
        ts = create_ts()
        worker = create_worker()
        token = Token.create(ts)

        r = self.client.post(reverse('system.start_tests'),
                             data={'browsers': 'firefox', 'token': token,
                                   'name': ts.slug})
        eq_(r.status_code, 200)
        data = json.loads(r.content)
        assert 'test_run_id' in data, ('Unexpected: %s' % data)
Ejemplo n.º 15
0
    def test_start_tests_without_token(self):
        ts = create_ts()
        worker = create_worker()

        r = self.client.post(reverse('system.start_tests'),
                             data={'browsers': 'firefox', 'name': ts.slug})
        eq_(r.status_code, 500)
        data = json.loads(r.content)
        eq_(data['error'], True)
        eq_(data['message'],
            'Invalid or expired token sent to start_tests. '
            'Contact an administrator.')
Ejemplo n.º 16
0
 def test_start_tests_with_no_workers(self):
     ts = create_ts()
     token = Token.create(ts)
     r = self.client.post(reverse('system.start_tests'),
                          data={
                              'browsers': 'firefox',
                              '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'firefox' are connected")
Ejemplo n.º 17
0
    def test_start_tests_with_wrong_token(self):
        ts = create_ts('one')
        other_ts = create_ts('two')
        token = Token.create(other_ts)

        r = self.client.post(reverse('system.start_tests'),
                             data={'browsers': 'firefox', 'token': token,
                                   'name': ts.slug})
        eq_(r.status_code, 500)
        data = json.loads(r.content)
        eq_(data['error'], True)
        eq_(data['message'],
            'Invalid or expired token sent to start_tests. '
            'Contact an administrator.')
Ejemplo n.º 18
0
    def test_start_tests_with_correct_token(self):
        ts = create_ts()
        worker = create_worker()
        token = Token.create(ts)

        r = self.client.post(reverse('system.start_tests'),
                             data={
                                 'browsers': 'firefox',
                                 'token': token,
                                 'name': ts.slug
                             })
        eq_(r.status_code, 200)
        data = json.loads(r.content)
        assert 'test_run_id' in data, ('Unexpected: %s' % data)
Ejemplo n.º 19
0
    def test_start_tests_without_token(self):
        ts = create_ts()
        worker = create_worker()

        r = self.client.post(reverse('system.start_tests'),
                             data={
                                 'browsers': 'firefox',
                                 'name': ts.slug
                             })
        eq_(r.status_code, 500)
        data = json.loads(r.content)
        eq_(data['error'], True)
        eq_(
            data['message'], 'Invalid or expired token sent to start_tests. '
            'Contact an administrator.')
Ejemplo n.º 20
0
 def test_missing_results(self):
     results = {
         'failures': 0,
         'total': 1,
         # totally empty
         'tests': [{}]
     }
     r = self.client.post(reverse('work.submit_results'),
                          dict(work_queue_id=self.work_queue_id,
                               results=json.dumps(results)))
     eq_(r.status_code, 500)
     d = json.loads(r.content)
     eq_(d['error'], True)
     assert 'missing key result' in d['message'], (
                                         'Unexpected: %s' % d['message'])
Ejemplo n.º 21
0
 def test_start_tests_with_custom_url(self):
     ts = create_ts()
     token = Token.create(ts)
     fx_worker = create_worker(
                 user_agent='Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; '
                            'rv:2.0b10) Gecko/20100101 Firefox/4.0b10')
     custom_url = 'http://custom.com/qunit'
     r = self.client.post(reverse('system.start_tests'),
                          data={'browsers': 'firefox=~*', 'token': token,
                                'name': ts.slug, 'url': custom_url})
     eq_(r.status_code, 200)
     data = json.loads(r.content)
     test_run_id = data['test_run_id']
     test_run = TestRun.objects.get(id=test_run_id)
     eq_(custom_url, test_run.url)
Ejemplo n.º 22
0
 def test_missing_results(self):
     results = {
         'failures': 0,
         'total': 1,
         # totally empty
         'tests': [{}]
     }
     r = self.client.post(reverse('work.submit_results'),
                          dict(work_queue_id=self.work_queue_id,
                               results=json.dumps(results)))
     eq_(r.status_code, 500)
     d = json.loads(r.content)
     eq_(d['error'], True)
     assert 'missing key result' in d['message'], (
                                         'Unexpected: %s' % d['message'])
Ejemplo n.º 23
0
 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")
Ejemplo n.º 24
0
    def test_start_tests_with_wrong_token(self):
        ts = create_ts('one')
        other_ts = create_ts('two')
        token = Token.create(other_ts)

        r = self.client.post(reverse('system.start_tests'),
                             data={
                                 'browsers': 'firefox',
                                 'token': token,
                                 'name': ts.slug
                             })
        eq_(r.status_code, 500)
        data = json.loads(r.content)
        eq_(data['error'], True)
        eq_(
            data['message'], 'Invalid or expired token sent to start_tests. '
            'Contact an administrator.')
Ejemplo n.º 25
0
    def test_submit_error_results(self):
        results = {
            'test_run_error': True,
            'test_run_error_msg': 'Timed out waiting for test results'
        }
        r = self.client.post(reverse('work.submit_results'),
                             dict(work_queue_id=self.work_queue_id,
                                  results=json.dumps(results)))
        eq_(r.status_code, 200)

        q = WorkQueue.objects.get(pk=self.work_queue_id)
        eq_(q.finished, True)
        d = json.loads(q.results)
        eq_(d['tests'][0], {'module': '__jstestnet__',
                            'test': 'test_run_error',
                            'result': False,
                            'message': results['test_run_error_msg']})
Ejemplo n.º 26
0
    def test_submit_error_results(self):
        results = {
            'test_run_error': True,
            'test_run_error_msg': 'Timed out waiting for test results'
        }
        r = self.client.post(reverse('work.submit_results'),
                             dict(work_queue_id=self.work_queue_id,
                                  results=json.dumps(results)))
        eq_(r.status_code, 200)

        q = WorkQueue.objects.get(pk=self.work_queue_id)
        eq_(q.finished, True)
        d = json.loads(q.results)
        eq_(d['tests'][0], {'module': '__jstestnet__',
                            'test': 'test_run_error',
                            'result': False,
                            'message': results['test_run_error_msg']})
Ejemplo n.º 27
0
 def test_start_tests_with_custom_url(self):
     ts = create_ts()
     token = Token.create(ts)
     fx_worker = create_worker(
         user_agent='Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; '
         'rv:2.0b10) Gecko/20100101 Firefox/4.0b10')
     custom_url = 'http://custom.com/qunit'
     r = self.client.post(reverse('system.start_tests'),
                          data={
                              'browsers': 'firefox=~*',
                              'token': token,
                              'name': ts.slug,
                              'url': custom_url
                          })
     eq_(r.status_code, 200)
     data = json.loads(r.content)
     test_run_id = data['test_run_id']
     test_run = TestRun.objects.get(id=test_run_id)
     eq_(custom_url, test_run.url)
Ejemplo n.º 28
0
 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")
Ejemplo n.º 29
0
 def setUp(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.objects.create()
     worker.parse_user_agent(user_agent)
     worker.save()
     ts = TestSuite(name='Zamboni', slug='zamboni',
                    url='http://server/qunit1.html')
     ts.save()
     token = Token.create(ts)
     r = self.client.post(reverse('system.start_tests'),
                          data={'browsers': 'firefox', 'token': token,
                                'name': ts.slug})
     eq_(r.status_code, 200)
     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)
     self.work_queue_id = data['work_queue_id']
Ejemplo n.º 30
0
    def test_submit_incomplete_results(self):
        results = {
            'failures': 0,
            'total': 1,
            # mostly empty test result:
            'tests': [{'result': True}]
        }
        r = self.client.post(reverse('work.submit_results'),
                             dict(work_queue_id=self.work_queue_id,
                                  results=json.dumps(results)))
        eq_(r.status_code, 200)

        q = WorkQueue.objects.get(pk=self.work_queue_id)
        eq_(q.finished, True)
        eq_(json.loads(q.results)['tests'],
            [{'result': True,
              'module': "<'module' was empty>",
              'test': "<'test' was empty>",
              'message': "<'message' was empty>"}])
Ejemplo n.º 31
0
    def test_submit_incomplete_results(self):
        results = {
            'failures': 0,
            'total': 1,
            # mostly empty test result:
            'tests': [{'result': True}]
        }
        r = self.client.post(reverse('work.submit_results'),
                             dict(work_queue_id=self.work_queue_id,
                                  results=json.dumps(results)))
        eq_(r.status_code, 200)

        q = WorkQueue.objects.get(pk=self.work_queue_id)
        eq_(q.finished, True)
        eq_(json.loads(q.results)['tests'],
            [{'result': True,
              'module': "<'module' was empty>",
              'test': "<'test' was empty>",
              'message': "<'message' was empty>"}])
Ejemplo n.º 32
0
 def setUp(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.objects.create()
     worker.parse_user_agent(user_agent)
     worker.save()
     ts = TestSuite(name='Zamboni', slug='zamboni',
                    default_url='http://server/qunit1.html')
     ts.save()
     token = Token.create(ts)
     r = self.client.post(reverse('system.start_tests'),
                          data={'browsers': 'firefox', 'token': token,
                                'name': ts.slug})
     eq_(r.status_code, 200)
     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)
     self.work_queue_id = data['work_queue_id']
Ejemplo n.º 33
0
    def test_start_specific_worker(self):
        ts = create_ts()
        token = Token.create(ts)
        fx_worker = create_worker(
                    user_agent='Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; '
                               'rv:2.0b10) Gecko/20100101 Firefox/4.0b10')
        ch_worker = create_worker(
                    user_agent='Mozilla/5.0 (Windows; U; Windows NT 5.2; '
                               'en-US) AppleWebKit/534.17 (KHTML, like Gecko)'
                               ' Chrome/11.0.652.0 Safari/534.17')
        r = self.client.post(reverse('system.start_tests'),
                             data={'browsers': 'firefox=~*', 'token': token,
                                   'name': ts.slug})
        eq_(r.status_code, 200)
        data = json.loads(r.content)

        data = self.query(ch_worker)
        eq_(data, {u'desc': u'No commands from server.'})
        data = self.query(fx_worker)
        eq_(data['cmd'], 'run_test')
Ejemplo n.º 34
0
    def test_start_specific_worker(self):
        ts = create_ts()
        token = Token.create(ts)
        fx_worker = create_worker(
            user_agent='Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; '
            'rv:2.0b10) Gecko/20100101 Firefox/4.0b10')
        ch_worker = create_worker(
            user_agent='Mozilla/5.0 (Windows; U; Windows NT 5.2; '
            'en-US) AppleWebKit/534.17 (KHTML, like Gecko)'
            ' Chrome/11.0.652.0 Safari/534.17')
        r = self.client.post(reverse('system.start_tests'),
                             data={
                                 'browsers': 'firefox=~*',
                                 'token': token,
                                 'name': ts.slug
                             })
        eq_(r.status_code, 200)
        data = json.loads(r.content)

        data = self.query(ch_worker)
        eq_(data, {u'desc': u'No commands from server.'})
        data = self.query(fx_worker)
        eq_(data['cmd'], 'run_test')
Ejemplo n.º 35
0
    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.')
Ejemplo n.º 36
0
    def test_get_job_result(self):
        ts = create_ts()
        token = Token.create(ts)
        worker = create_worker()

        r = self.client.post(reverse('system.start_tests'),
                             data={
                                 'browsers': 'firefox',
                                 'token': token,
                                 'name': ts.slug
                             })
        eq_(r.status_code, 200)
        data = json.loads(r.content)
        test_run_id = data['test_run_id']

        r = self.client.get(reverse('system.test_result', args=[test_run_id]))
        eq_(r.status_code, 200)
        data = json.loads(r.content)
        eq_(data['finished'], False)
        eq_(data['results'], [])

        data = self.query(worker)
        queue_id = data['work_queue_id']

        results = {
            'failures':
            0,
            'total':
            1,
            'tests': [
                {
                    'module': 'Bar',
                    'test': 'foo',
                    'message': '1 equals 2',
                    'result': False
                },
                {
                    'module': 'Bar',
                    'test': 'foo',
                    'message': 'ok',
                    'result': True
                },
                {
                    'module': 'Zebo',
                    'test': 'zee',
                    'message': 'ok',
                    '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)

        r = self.client.get(reverse('system.test_result', args=[test_run_id]))
        eq_(r.status_code, 200)
        data = json.loads(r.content)
        eq_(data['finished'], True)

        tests = sorted(data['results'])
        eq_(tests[0]['module'], 'Bar')
        eq_(tests[0]['test'], 'foo')
        eq_(tests[0]['assertions'], [
            {
                'module': 'Bar',
                'test': 'foo',
                'worker_id': worker.id,
                'worker_user_agent': worker.user_agent,
                'browser': 'firefox/3.6.12, gecko/1.9.2.12',
                'message': '1 equals 2',
                'result': False
            },
            {
                'module': 'Bar',
                'test': 'foo',
                'worker_id': worker.id,
                'worker_user_agent': worker.user_agent,
                'browser': 'firefox/3.6.12, gecko/1.9.2.12',
                'message': 'ok',
                'result': True
            },
        ])
        eq_(tests[1]['module'], 'Zebo')
        eq_(tests[1]['test'], 'zee')
        eq_(tests[1]['assertions'], [
            {
                'module': 'Zebo',
                'test': 'zee',
                'worker_id': worker.id,
                'worker_user_agent': worker.user_agent,
                'browser': 'firefox/3.6.12, gecko/1.9.2.12',
                'message': 'ok',
                'result': True
            },
        ])
Ejemplo n.º 37
0
 def query(self, worker):
     r = self.client.post(
         reverse('work.query'),
         dict(worker_id=worker.id, user_agent=worker.user_agent))
     eq_(r.status_code, 200)
     return json.loads(r.content)
Ejemplo n.º 38
0
    def test_get_job_result(self):
        ts = create_ts()
        token = Token.create(ts)
        worker = create_worker()

        r = self.client.post(reverse('system.start_tests'),
                             data={'browsers': 'firefox', 'token': token,
                                   'name': ts.slug})
        eq_(r.status_code, 200)
        data = json.loads(r.content)
        test_run_id = data['test_run_id']

        r = self.client.get(reverse('system.test_result', args=[test_run_id]))
        eq_(r.status_code, 200)
        data = json.loads(r.content)
        eq_(data['finished'], False)
        eq_(data['results'], [])

        data = self.query(worker)
        queue_id = data['work_queue_id']

        results = {
            'failures': 0,
            'total': 1,
            'tests': [
                {'module':'Bar', 'test':'foo',
                 'message':'1 equals 2', 'result':False},
                {'module':'Bar', 'test':'foo',
                 'message':'ok', 'result':True},
                {'module':'Zebo', 'test':'zee',
                 'message':'ok', '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)

        r = self.client.get(reverse('system.test_result', args=[test_run_id]))
        eq_(r.status_code, 200)
        data = json.loads(r.content)
        eq_(data['finished'], True)

        tests = sorted(data['results'])
        eq_(tests[0]['module'], 'Bar')
        eq_(tests[0]['test'], 'foo')
        eq_(tests[0]['assertions'], [
            {'module':'Bar', 'test':'foo', 'worker_id': worker.id,
             'worker_user_agent': worker.user_agent,
             'browser': 'firefox/3.6.12, gecko/1.9.2.12',
             'message':'1 equals 2', 'result':False},
            {'module':'Bar', 'test':'foo', 'worker_id': worker.id,
             'worker_user_agent': worker.user_agent,
             'browser': 'firefox/3.6.12, gecko/1.9.2.12',
             'message':'ok', 'result':True},
        ])
        eq_(tests[1]['module'], 'Zebo')
        eq_(tests[1]['test'], 'zee')
        eq_(tests[1]['assertions'], [
            {'module':'Zebo', 'test':'zee', 'worker_id': worker.id,
             'worker_user_agent': worker.user_agent,
             'browser': 'firefox/3.6.12, gecko/1.9.2.12',
             'message':'ok', 'result':True},
        ])
Ejemplo n.º 39
0
 def query(self, worker):
     r = self.client.post(reverse('work.query'),
                          dict(worker_id=worker.id,
                               user_agent=worker.user_agent))
     eq_(r.status_code, 200)
     return json.loads(r.content)
Ejemplo n.º 40
0
    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.')