Example #1
0
def test_imagenet(request):
    """
    Check the imagenet service from Neptune with a known image

    Args:
        request (fixture): get the cmdline options
    """
    server_addr = get_server_addr(request.config)

    # create Neptune service and start it
    service = NeptuneService(server_addr, 'imagenet')
    service.start()

    # submit job to service
    post_data = {
        'url':
        'https://www-tc.pbs.org/wnet/nature/files/2018/07/Bear133-1280x720.jpg',
        'dtype': 'uint8'
    }
    r = requests.post('%s/serve/imagenet' % server_addr, post_data)
    assert r.status_code == 200, r.text

    response = r.json()
    assert type(response) is dict

    assert 'img' in response
    assert response['url'] == post_data['url']
    assert "predictions" in response
    assert "boxes" in response
    predictions = response["predictions"]

    #TODO verify output response

    service.stop()
Example #2
0
def test_ping_benchmark(request, args_ping):
    """
    Benchmarks ping times using args_ping to configure the ping service

    Args:
        request (fixture): get the cmdline options
        args_ping (NeptuneServiceArgs): a Neptune service args object
    """
    server_addr = get_server_addr(request.config)
    service = NeptuneService(server_addr, 'ping')
    ITERATION_COUNT = 1
    THREAD_COUNT = 8

    service.start(args_ping)
    processes_count = args_ping.get_add_arg('ping', 'processes')
    threads = []

    for i in range(THREAD_COUNT):
        thread = threading.Thread(target=_run_test_ping_benchmark,
                                  args=(server_addr, ITERATION_COUNT))
        threads.append(thread)

    start_time = time.time()
    for thread in threads:
        thread.start()

    for thread in threads:
        thread.join()

    end_time = time.time()

    logging.info("ping_benchmark: %d pings took %fs with %d processes" % \
        (ITERATION_COUNT*THREAD_COUNT, (end_time - start_time), processes_count))

    service.stop()
Example #3
0
def test_sface(request):
    """
    Check the streaming facedetect service from Neptune with a known video

    Args:
        request (fixture): get the cmdline options
    """
    server_addr = get_server_addr(request.config)
    ws_addr = get_ws_addr(request.config)

    service = NeptuneService(server_addr, 'sface')

    service.start()

    ws = create_connection(ws_addr)
    response = json.loads(ws.recv())
    assert isinstance(response, dict)
    assert response['topic'] == 'id'
    assert 'message' in response

    client_id = response['message']

    post_data = {
        'url': 'https://www.youtube.com/watch?v=f5NJQiY9AuY',
        'dtype': 'uint8',
        'callback_id': client_id
    }

    r = requests.post('%s/serve/sface' % server_addr, post_data)
    assert r.status_code == 200, r.text

    response = r.json()
    assert type(response) is dict
    # TODO should this response be checked?

    # collect some number of frames
    for i in range(20):
        for j in range(10):
            response = json.loads(ws.recv())
            assert isinstance(response, dict)
            assert response['topic'] == 'callback'
            assert 'message' in response

            response = json.loads(response['message'])
            assert isinstance(response, dict)
            assert 'img' in response
            assert 'boxes' in response
            assert response['callback_id'] == client_id

            # in this video, there should be a face (i.e. boxes) in all frames
            assert response['boxes']

        # issue keepalive request every so often
        r = requests.post('%s/serve/sface' % server_addr, post_data)
        assert r.status_code == 200, r.text

    ws.close()
    service.stop()
Example #4
0
def test_construct(request, new_service):
    """
    Constructs a new service and makes sure it's added. Then it destroys the
    new service and makes sure it's deleted

    Args:
        request (fixture): get the cmdline options
        new_service (fixture): a Recipe object
    """

    server_addr = get_server_addr(request.config)

    session = NeptuneSession(server_addr)

    # get a list of services and make sure TEST_NAME isn't there
    response = session.get_services()

    for service in response['services']:
        assert service['name'] != TEST_NAME
        assert service['url'] != "/serve/" + TEST_NAME

    # construct the new service
    r = requests.post('%s/services/construct' % server_addr, json=new_service)
    assert r.status_code == 200, r.text

    # check if the new service exists in the service manager
    response = session.query_service(TEST_NAME)
    assert 'url' in response
    assert response['url'] == "/serve/" + TEST_NAME

    recipe_cache = os.environ[
        'VAI_HOME'] + '/demo/neptune/recipes/recipe_%s.bak' % TEST_NAME
    assert os.path.exists(recipe_cache)

    # destroy the service
    r = requests.post('%s/services/destruct' % server_addr, {
        'url': TEST_NAME,
        'name': TEST_NAME
    })
    assert r.status_code == 200, r.text

    # make sure the service is gone
    response = session.get_services()
    for service in response['services']:
        assert service['name'] != TEST_NAME
        assert service['url'] != "/serve/" + TEST_NAME

    assert not os.path.exists(recipe_cache)
Example #5
0
def test_coco(request):
    """
    Check the coco service from Neptune with a known image

    Args:
        request (fixture): get the cmdline options
    """
    server_addr = get_server_addr(request.config)

    # create Neptune service and start it
    service = NeptuneService(server_addr, 'coco')
    service.start()

    # submit job to service
    post_data = {
        'url': 'http://farm1.staticflickr.com/26/50531313_4422f0787e_z.jpg',
        'dtype': 'uint8'
    }
    r = requests.post('%s/serve/coco' % server_addr, post_data)
    assert r.status_code == 200, r.text

    response = r.json()
    assert type(response) is dict

    # for this known image, validate the expected response
    for i, j in zip(response['resized_shape'], [149, 224, 3]):
        assert i == j
    assert 'img' in response
    assert response['url'] == post_data['url']
    assert len(response['boxes']) == 2
    tolerance = 5
    for i, j in zip(response['boxes'][0], [85, 18, 149, 118, "giraffe"]):
        if isinstance(j, int):
            assert j - tolerance <= i <= j + tolerance
        else:
            assert i == j
    for i, j in zip(response['boxes'][1], [21, 90, 65, 148, "zebra"]):
        if isinstance(j, int):
            assert j - tolerance <= i <= j + tolerance
        else:
            assert i == j

    service.stop()
Example #6
0
def test_ping(request):
    """
    Gets n pings from Neptune using the ping service

    Args:
        request (fixture): get the cmdline options
    """
    server_addr = get_server_addr(request.config)
    service = NeptuneService(server_addr, 'ping')

    service.start()

    r = requests.get('%s/serve/ping' % server_addr)
    assert r.status_code == 200

    response = r.json()
    # verify both the id and pong keys are present in the response
    assert type(response) is dict
    assert 'pong' in response
    assert 'id' in response

    float(response['pong'])  # check if pong is a float

    service.stop()