explore partial responses

This commit is contained in:
Julius Unverfehrt 2022-04-26 16:34:58 +02:00
parent f6ca9c9ac5
commit 656bc7cd63
3 changed files with 5 additions and 9 deletions

View File

@ -11,18 +11,14 @@ from test.utils.server import bytes_to_string, string_to_bytes
def test_sending_partial_request(url, data_items, metadata): def test_sending_partial_request(url, data_items, metadata):
def pack(metadata: dict, data: bytes): def pack(metadata: dict, data: bytes):
package = {"data": bytes_to_string(data), "metadata": metadata} package = {"data": bytes_to_string(data), "metadata": metadata}
package = string_to_bytes(json.dumps(package)) package = json.dumps(package).encode()
return package return package
packages = starmap(pack, zip(repeat(metadata), data_items)) packages = starmap(pack, zip(repeat(metadata), data_items))
def f():
yield "a"
yield "b"
requests.post(f"{url}/process", data=packages, stream=True) requests.post(f"{url}/process", data=packages, stream=True)
@pytest.fixture @pytest.fixture
def metadata(): def metadata():
return {"idx": [0, 3, 9]} return {"idx": [1, 100, 101], "path": "asd/asd"}

View File

@ -12,4 +12,4 @@ def data(data_type, pdf):
@pytest.fixture @pytest.fixture
def data_items(item_type): def data_items(item_type):
if item_type == "string": if item_type == "string":
return iter([b"content"] * 5) return iter([b"content"] * 4)

View File

@ -7,6 +7,7 @@ from funcy import retry
from waitress import serve from waitress import serve
from test.server import set_up_processing_server from test.server import set_up_processing_server
from test.utils.server import bytes_to_string
@pytest.fixture @pytest.fixture
@ -43,8 +44,7 @@ def processor_fn(item_type, data_items):
def make_string_processor(data_items): def make_string_processor(data_items):
def processor_fn(payload): def processor_fn(payload):
print(111111111111111111111111111111111111) print(payload.stream.read())
print(payload)
# def parse(package) # def parse(package)
# payload = json.load(payload) # payload = json.load(payload)
# data = string_to_bytes(payload["data"]) # data = string_to_bytes(payload["data"])