Ejemplo n.º 1
0
def test_simple(s, a, b):
    server = HTTPWorker(a)
    server.listen(0)
    client = AsyncHTTPClient()

    response = yield client.fetch('http://localhost:%d/info.json' % server.port)
    response = json.loads(response.body.decode())
    assert response['ncores'] == a.ncores
    assert response['status'] == a.status

    response = yield client.fetch('http://localhost:%d/resources.json' %
            server.port)
    response = json.loads(response.body.decode())

    a.data['x'] = 1

    try:
        import psutil
        assert 0 < response['memory_percent'] < 100
    except ImportError:
        assert response == {}

    endpoints = ['/files.json', '/processing.json', '/nbytes.json',
                 '/nbytes-summary.json']
    for endpoint in endpoints:
        response = yield client.fetch(('http://localhost:%d' % server.port)
                                      + endpoint)
        response = json.loads(response.body.decode())
        assert response

    server.stop()
def test_broadcast(s, a, b):
    ss = HTTPScheduler(s)
    ss.listen(0)
    s.services['http'] = ss

    aa = HTTPWorker(a)
    aa.listen(0)
    a.services['http'] = aa
    a.service_ports['http'] = aa.port
    s.worker_info[a.address]['services']['http'] = aa.port

    bb = HTTPWorker(b)
    bb.listen(0)
    b.services['http'] = bb
    b.service_ports['http'] = bb.port
    s.worker_info[b.address]['services']['http'] = bb.port

    client = AsyncHTTPClient()

    a_response = yield client.fetch('http://localhost:%d/info.json' % aa.port)
    b_response = yield client.fetch('http://localhost:%d/info.json' % bb.port)
    s_response = yield client.fetch('http://localhost:%d/broadcast/info.json'
                                    % ss.port)
    assert (json.loads(s_response.body.decode()) ==
            {a.address: json.loads(a_response.body.decode()),
             b.address: json.loads(b_response.body.decode())})

    ss.stop()
    aa.stop()
    bb.stop()
def test_proxy(s, a, b):
    server = HTTPScheduler(s)
    server.listen(0)
    worker = HTTPWorker(a)
    worker.listen(0)
    client = AsyncHTTPClient()

    c_response = yield client.fetch("http://localhost:%d/info.json" % worker.port)
    s_response = yield client.fetch("http://localhost:%d/proxy/%s:%d/info.json" % (server.port, a.ip, worker.port))
    assert s_response.body.decode() == c_response.body.decode()
Ejemplo n.º 4
0
def test_simple(s, a, b):
    port = 9898
    server = HTTPWorker(a)
    server.listen(port)
    client = AsyncHTTPClient()

    response = yield client.fetch('http://localhost:%d/info.json' % port)
    response = json.loads(response.body.decode())
    assert response['ncores'] == a.ncores
    assert response['status'] == a.status

    response = yield client.fetch('http://localhost:%d/resources.json' % port)
    response = json.loads(response.body.decode())
    assert 0 < response['memory_percent'] < 100
Ejemplo n.º 5
0
def test_nbytes(s, a, b):
    server = HTTPWorker(a)
    server.listen(0)
    client = AsyncHTTPClient()

    a.data['x-1'] = 1
    a.data['x-2'] = 1

    nbytes = yield client.fetch('http://localhost:%d/nbytes.json' % server.port)
    nbytes = json.loads(nbytes.body.decode())
    summary = yield client.fetch('http://localhost:%d/nbytes-summary.json' % server.port)
    summary = json.loads(summary.body.decode())

    assert nbytes == {'x-1': sizeof(1), 'x-2': sizeof(2)}
    assert summary == {'x': sizeof(1) * 2}
Ejemplo n.º 6
0
def test_processing(c, s, a, b):
    server = HTTPWorker(a)
    server.listen(0)
    client = AsyncHTTPClient()

    futures = c.map(slowinc, range(10), delay=1)
    while not a.executing:
        yield gen.sleep(0.01)

    response = yield client.fetch('http://localhost:%d/processing.json' %
                                  server.port)

    response = json.loads(response.body.decode())
    assert response
    assert response['processing']
Ejemplo n.º 7
0
def test_nbytes(s, a, b):
    server = HTTPWorker(a)
    server.listen(0)
    client = AsyncHTTPClient()

    a.data['x-1'] = 1
    a.data['x-2'] = 1

    nbytes = yield client.fetch('http://localhost:%d/nbytes.json' %
                                server.port)
    nbytes = json.loads(nbytes.body.decode())
    summary = yield client.fetch('http://localhost:%d/nbytes-summary.json' %
                                 server.port)
    summary = json.loads(summary.body.decode())

    assert nbytes == {'x-1': sizeof(1), 'x-2': sizeof(2)}
    assert summary == {'x': sizeof(1) * 2}
Ejemplo n.º 8
0
def test_nbytes(c, s, a, b):
    server = HTTPWorker(a)
    server.listen(0)
    client = AsyncHTTPClient()

    futures = yield c._scatter(list(range(10)))

    nbytes = yield client.fetch('http://localhost:%d/nbytes.json' %
                                server.port)
    nbytes = json.loads(nbytes.body.decode())
    summary = yield client.fetch('http://localhost:%d/nbytes-summary.json' %
                                 server.port)
    summary = json.loads(summary.body.decode())

    assert nbytes
    assert summary
    assert len(summary) == 1
    assert len(nbytes) == len(a.data)
Ejemplo n.º 9
0
def test_simple(c, s, a, b):
    server = HTTPWorker(a)
    server.listen(0)
    client = AsyncHTTPClient()

    response = yield client.fetch('http://localhost:%d/info.json' %
                                  server.port)
    response = json.loads(response.body.decode())
    assert response['ncores'] == a.ncores
    assert response['status'] == a.status

    response = yield client.fetch('http://localhost:%d/resources.json' %
                                  server.port)
    response = json.loads(response.body.decode())

    futures = yield c._scatter(list(range(10)))

    try:
        import psutil  # flake8: noqa
        assert 0 < response['memory_percent'] < 100
    except ImportError:
        assert response == {}

    endpoints = [
        '/files.json', '/processing.json', '/nbytes.json',
        '/nbytes-summary.json'
    ]
    for endpoint in endpoints:
        response = yield client.fetch(('http://localhost:%d' % server.port) +
                                      endpoint)
        response = json.loads(response.body.decode())
        assert response

    server.stop()
Ejemplo n.º 10
0
def test_broadcast(s, a, b):
    ss = HTTPScheduler(s)
    ss.listen(0)
    s.services["http"] = ss

    aa = HTTPWorker(a)
    aa.listen(0)
    a.services["http"] = aa
    a.service_ports["http"] = aa.port
    s.worker_services[a.address]["http"] = aa.port

    bb = HTTPWorker(b)
    bb.listen(0)
    b.services["http"] = bb
    b.service_ports["http"] = bb.port
    s.worker_services[b.address]["http"] = bb.port

    client = AsyncHTTPClient()

    a_response = yield client.fetch("http://localhost:%d/info.json" % aa.port)
    b_response = yield client.fetch("http://localhost:%d/info.json" % bb.port)
    s_response = yield client.fetch("http://localhost:%d/broadcast/info.json" % ss.port)
    assert json.loads(s_response.body.decode()) == {
        "%s:%d" % a.address: json.loads(a_response.body.decode()),
        "%s:%d" % b.address: json.loads(b_response.body.decode()),
    }
Ejemplo n.º 11
0
def test_simple(s, a, b):
    server = HTTPWorker(a)
    server.listen(0)
    client = AsyncHTTPClient()

    response = yield client.fetch('http://localhost:%d/info.json' %
                                  server.port)
    response = json.loads(response.body.decode())
    assert response['ncores'] == a.ncores
    assert response['status'] == a.status

    response = yield client.fetch('http://localhost:%d/resources.json' %
                                  server.port)
    response = json.loads(response.body.decode())

    try:
        import psutil
        assert 0 < response['memory_percent'] < 100
    except ImportError:
        assert response == {}

    endpoints = ['/files.json']
    for endpoint in endpoints:
        response = yield client.fetch(('http://localhost:%d' % server.port) +
                                      endpoint)
        response = json.loads(response.body.decode())
        assert response

    server.stop()
Ejemplo n.º 12
0
def test_proxy(s, a, b):
    server = HTTPScheduler(s)
    server.listen(0)
    worker = HTTPWorker(a)
    worker.listen(0)
    client = AsyncHTTPClient()

    c_response = yield client.fetch('http://localhost:%d/info.json' % worker.port)
    s_response = yield client.fetch('http://localhost:%d/proxy/%s:%d/info.json'
                                    % (server.port, a.ip, worker.port))
    assert s_response.body.decode() == c_response.body.decode()
    server.stop()
    worker.stop()
Ejemplo n.º 13
0
def test_broadcast(s, a, b):
    ss = HTTPScheduler(s)
    ss.listen(0)
    s.services['http'] = ss

    aa = HTTPWorker(a)
    aa.listen(0)
    a.services['http'] = aa
    a.service_ports['http'] = aa.port
    s.worker_info[a.address]['services']['http'] = aa.port

    bb = HTTPWorker(b)
    bb.listen(0)
    b.services['http'] = bb
    b.service_ports['http'] = bb.port
    s.worker_info[b.address]['services']['http'] = bb.port

    client = AsyncHTTPClient()

    a_response = yield client.fetch('http://localhost:%d/info.json' % aa.port)
    b_response = yield client.fetch('http://localhost:%d/info.json' % bb.port)
    s_response = yield client.fetch('http://localhost:%d/broadcast/info.json' %
                                    ss.port)
    assert (json.loads(s_response.body.decode()) == {
        a.address: json.loads(a_response.body.decode()),
        b.address: json.loads(b_response.body.decode())
    })

    ss.stop()
    aa.stop()
    bb.stop()