Exemplo n.º 1
0
def restart_workers(request):
    work_views.collect_garbage()
    count = 0
    for worker in Worker.objects.filter(is_alive=True):
        worker.restart()
        count += 1
    return {'workers_restarted': count}
Exemplo n.º 2
0
def status(request):
    work_views.collect_garbage()

    data = dict(workers=(Worker.objects.filter(is_alive=True)
                         .exclude(last_heartbeat=None)),
                test_suites=TestSuite.objects.all().order_by('name'))
    return render(request, 'system/index.html', data)
Exemplo n.º 3
0
def status(request):
    work_views.collect_garbage()

    data = dict(workers=(Worker.objects.filter(is_alive=True).exclude(
        last_heartbeat=None)),
                test_suites=TestSuite.objects.all().order_by('name'))
    return render(request, 'system/index.html', data)
Exemplo n.º 4
0
def start_tests(request):
    ts = get_object_or_404(TestSuite, slug=request.POST.get('name', None))
    url = request.POST.get('url') or ts.default_url
    token_is_valid = False
    if request.POST.get('token', None):
        if Token.is_valid(request.POST['token'], ts):
            token_is_valid = True
    if not token_is_valid:
        raise InvalidToken('Invalid or expired token sent to start_tests. '
                           'Contact an administrator.')

    work_views.collect_garbage()
    # TODO(kumar) don't start a test suite if it's already running.
    test = TestRun(test_suite=ts, url=url)
    test.save()
    workers = []
    qs = Worker.objects.filter(is_alive=True)
    browsers = request.POST.get('browsers', None)
    if not browsers:
        raise ValueError("No browsers were specified in GET request")
    for worker in get_workers(qs, browsers):
        # TODO(kumar) add options to ignore workers for
        # unwanted browsers perhaps?
        worker.run_test(test)
        workers.append(worker)
    return {'test_run_id': test.id,
            'workers': [{'worker_id': w.id, 'user_agent': w.user_agent}
                         for w in workers]}
Exemplo n.º 5
0
def restart_workers(request):
    work_views.collect_garbage()
    count = 0
    for worker in Worker.objects.filter(is_alive=True):
        worker.restart()
        count += 1
    return {'workers_restarted': count}
Exemplo n.º 6
0
def start_tests(request):
    ts = get_object_or_404(TestSuite, slug=request.POST.get('name', None))
    url = request.POST.get('url') or ts.default_url
    token_is_valid = False
    if request.POST.get('token', None):
        if Token.is_valid(request.POST['token'], ts):
            token_is_valid = True
    if not token_is_valid:
        raise InvalidToken('Invalid or expired token sent to start_tests. '
                           'Contact an administrator.')

    work_views.collect_garbage()
    # TODO(kumar) don't start a test suite if it's already running.
    test = TestRun(test_suite=ts, url=url)
    test.save()
    workers = []
    qs = Worker.objects.filter(is_alive=True)
    browsers = request.POST.get('browsers', None)
    if not browsers:
        raise ValueError("No browsers were specified in GET request")
    for worker in get_workers(qs, browsers):
        # TODO(kumar) add options to ignore workers for
        # unwanted browsers perhaps?
        worker.run_test(test)
        workers.append(worker)
    return {
        'test_run_id':
        test.id,
        'workers': [{
            'worker_id': w.id,
            'user_agent': w.user_agent
        } for w in workers]
    }
Exemplo n.º 7
0
def start_remote_debugger(request, worker_id):
    work_views.collect_garbage()
    worker = get_object_or_404(Worker, id=worker_id)
    worker.start_debugging()
    # TODO check is_alive?
    # Cannot be a POST since user might need to login first (login redirect)
    return http.HttpResponseRedirect(reverse('system.debug_in_worker',
                                     args=[worker_id]))
Exemplo n.º 8
0
def start_remote_debugger(request, worker_id):
    work_views.collect_garbage()
    worker = get_object_or_404(Worker, id=worker_id)
    worker.start_debugging()
    # TODO check is_alive?
    # Cannot be a POST since user might need to login first (login redirect)
    return http.HttpResponseRedirect(
        reverse('system.debug_in_worker', args=[worker_id]))
Exemplo n.º 9
0
 def test_garbage_collection(self):
     w = Worker.objects.create()
     w.parse_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')
     w.last_heartbeat = datetime.now() - timedelta(seconds=31)
     w.save()
     w.restart()
     collect_garbage()
     eq_([o.id for o in Worker.objects.all()], [])
     eq_([o.engine for o in WorkerEngine.objects.all()], [])
     eq_([o.id for o in WorkQueue.objects.all()], [])
Exemplo n.º 10
0
 def test_garbage_collection(self):
     w = Worker.objects.create()
     w.parse_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')
     w.last_heartbeat = datetime.now() - timedelta(seconds=31)
     w.save()
     w.restart()
     collect_garbage()
     eq_([o.id for o in Worker.objects.all()], [])
     eq_([o.engine for o in WorkerEngine.objects.all()], [])
     eq_([o.id for o in WorkQueue.objects.all()], [])
Exemplo n.º 11
0
def debug_in_worker(request, worker_id):
    work_views.collect_garbage()
    worker = get_object_or_404(Worker, id=worker_id)
    # TODO check is_alive?
    return render(request, 'system/admin/debug_in_worker.html',
                  {'worker_id': worker_id})
Exemplo n.º 12
0
def debug_in_worker(request, worker_id):
    work_views.collect_garbage()
    worker = get_object_or_404(Worker, id=worker_id)
    # TODO check is_alive?
    return render(request, 'system/admin/debug_in_worker.html',
                  {'worker_id': worker_id})