Beispiel #1
0
def test_v2_async_mode():
    # model loading is async
    os.environ["SERVING_SPEC_ENV"] = json.dumps(asyncspec)
    context = GraphContext()
    nuclio_init_hook(context, globals(), serving_subkind)
    context.logger.info("model initialized")

    context.logger.info("test not ready, should return err 408")
    event = MockEvent("", path="/v2/models/m5/ready", method="GET")
    resp = context.mlrun_handler(context, event)
    assert (
        resp.status_code == 408
    ), f"didnt get proper ready resp, expected 408, got {resp.status_code}"

    event = MockEvent(testdata, path="/v2/models/m5/infer")
    resp = context.mlrun_handler(context, event)
    context.logger.info("model responded")
    logger.info(resp)
    assert (resp.status_code !=
            200), f"expected failure, got {resp.status_code} {resp.body}"

    event = MockEvent('{"model": "m5", "inputs": [5]}')
    event.trigger = "stream"
    resp = context.mlrun_handler(context, event)
    context.logger.info("model responded")
    logger.info(resp)
    data = json.loads(resp.body)
    assert data["outputs"] == 5, f"wrong model response {data}"
Beispiel #2
0
def test_v2_raised_err():
    os.environ["SERVING_SPEC_ENV"] = json.dumps(raiser_spec)
    context = GraphContext()
    nuclio_init_hook(context, globals(), serving_subkind)

    event = MockEvent(testdata, path="/v2/models/m6/infer")
    resp = context.mlrun_handler(context, event)
    context.logger.info(f"model responded: {resp}")
    assert resp.status_code == 400, "expecting Response() with status_code 400"