Merge in RR/pyinfra from 2.0.0-documentation to 2.0.0
Squashed commit of the following:
commit 7a794bdcc987631cdc4d89b5620359464e2e018e
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Mon Jul 4 13:05:26 2022 +0200
removed obsolete imports
commit 3fc6a7ef5d0172dbce1c4292d245eced2f378b5a
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Mon Jul 4 11:47:12 2022 +0200
enable docker-compose fixture
commit 36d8d3bc851b06d94cf12a73048a00a67ef79c42
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Mon Jul 4 11:46:53 2022 +0200
renaming
commit 3bf00d11cd041dff325b66f13fcd00d3ce96b8b5
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Thu Jun 30 12:47:57 2022 +0200
refactoring: added cached pipeline factory
commit 90e735852af2f86e35be845fabf28494de952edb
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Wed Jun 29 13:47:08 2022 +0200
renaming
commit 93b3d4b202b41183ed8cabe193a4bfa03f520787
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Wed Jun 29 13:25:03 2022 +0200
further refactored server setup code: moving and decomplecting
commit 8b2ed83c7ade5bd811cb045d56fbfb0353fa385e
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Wed Jun 29 12:53:09 2022 +0200
refactored server setup code: factored out and decoupled operation registry and prometheus summary registry
commit da2dce762bdd6889165fbb320dc9ee8a0bd089b2
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Tue Jun 28 19:40:04 2022 +0200
adjusted test target
commit 70df7911b9b92f4b72afd7d4b33ca2bbf136295e
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Tue Jun 28 19:32:38 2022 +0200
minor refactoring
commit 0937b63dc000346559bde353381304b273244109
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Mon Jun 27 13:59:59 2022 +0200
support for empty operation suffix
commit 5e56917970962a2e69bbd66a324bdb4618c040bd
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Mon Jun 27 12:52:36 2022 +0200
minor refactoring
commit 40665a7815ae5927b3877bda14fb77deef37d667
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Mon Jun 27 10:57:04 2022 +0200
optimization: prefix filtering via storage API for get_all_object_names
commit af0892a899d09023eb0e61eecb63e03dc2fd3b60
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Mon Jun 27 10:55:47 2022 +0200
topological sorting of definitions by caller hierarchy
105 lines
3.7 KiB
Python
105 lines
3.7 KiB
Python
import pytest
|
|
from funcy import rcompose, compose, project, merge
|
|
|
|
from pyinfra.server.buffering.stream import FlatStreamBuffer
|
|
from pyinfra.server.client_pipeline import ClientPipeline
|
|
from pyinfra.server.dispatcher.dispatcher import Nothing
|
|
from pyinfra.server.dispatcher.dispatchers.queue import QueuedStreamFunctionDispatcher
|
|
from pyinfra.server.dispatcher.dispatchers.rest import RestDispatcher
|
|
from pyinfra.server.interpreter.interpreters.identity import IdentityInterpreter
|
|
from pyinfra.server.interpreter.interpreters.rest_callback import RestPickupStreamer
|
|
from pyinfra.server.packer.packers.rest import RestPacker
|
|
from pyinfra.server.packing import unpack
|
|
from pyinfra.server.receiver.receivers.identity import QueuedStreamFunctionReceiver
|
|
from pyinfra.server.receiver.receivers.rest import RestReceiver
|
|
from pyinfra.server.stream.queued_stream_function import QueuedStreamFunction
|
|
from pyinfra.server.utils import make_streamable_and_wrap_in_packing_logic
|
|
from pyinfra.utils.func import lift, llift
|
|
|
|
|
|
def test_mock_pipeline():
|
|
|
|
data = [1, 2, 3]
|
|
|
|
f, g, h, u = map(lift, [lambda x: x ** 2, lambda x: x + 2, lambda x: x / 2, lambda x: x])
|
|
|
|
pipeline = ClientPipeline(f, g, h, u)
|
|
|
|
assert list(pipeline(data)) == list(rcompose(f, g, h, u)(data))
|
|
|
|
|
|
@pytest.mark.parametrize("client_pipeline_type", ["basic", "rest"])
|
|
@pytest.mark.parametrize("server_side_test", [True])
|
|
def test_pipeline(
|
|
core_operation, client_pipeline, input_data_items, metadata, queue_message_metadata, targets, n_items
|
|
):
|
|
assert core_operation is not Nothing
|
|
|
|
metadata = [
|
|
merge(storage_mdt, project(queue_mdt, ["operation", "pages"]))
|
|
for storage_mdt, queue_mdt in zip(metadata, queue_message_metadata)
|
|
]
|
|
|
|
outputs = compose(llift(unpack), client_pipeline)(input_data_items, metadata)
|
|
assert n_items == 0 or len(outputs) > 0
|
|
assert outputs == targets
|
|
|
|
|
|
@pytest.mark.parametrize("item_type", ["string"])
|
|
@pytest.mark.parametrize("n_items", [1])
|
|
def test_pipeline_is_lazy(input_data_items, metadata, basic_client_pipeline, buffer_size):
|
|
def lazy_test_fn(*args, **kwargs):
|
|
probe["executed"] = True
|
|
return b"null", {}
|
|
|
|
probe = {"executed": False}
|
|
stream_function = make_streamable_and_wrap_in_packing_logic(lazy_test_fn, batched=False)
|
|
|
|
client_pipeline = get_basic_client_pipeline(stream_function, buffer_size=buffer_size)
|
|
output = client_pipeline(input_data_items, metadata)
|
|
|
|
assert not probe["executed"]
|
|
list(output)
|
|
assert probe["executed"]
|
|
|
|
|
|
@pytest.fixture
|
|
def client_pipeline(rest_client_pipeline, basic_client_pipeline, client_pipeline_type):
|
|
if client_pipeline_type == "rest":
|
|
return rest_client_pipeline
|
|
elif client_pipeline_type == "basic":
|
|
return basic_client_pipeline
|
|
|
|
|
|
@pytest.fixture
|
|
def rest_client_pipeline(server_process, endpoint, rest_interpreter):
|
|
"""Requires a webserver to listen on `endpoint`"""
|
|
return ClientPipeline(RestPacker(), RestDispatcher(endpoint), RestReceiver(), rest_interpreter)
|
|
|
|
|
|
@pytest.fixture
|
|
def basic_client_pipeline(endpoint, rest_interpreter, server_stream_function, buffer_size):
|
|
return get_basic_client_pipeline(server_stream_function, buffer_size)
|
|
|
|
|
|
def get_basic_client_pipeline(stream_function, buffer_size=3):
|
|
|
|
return ClientPipeline(
|
|
RestPacker(),
|
|
QueuedStreamFunctionDispatcher(
|
|
QueuedStreamFunction(
|
|
FlatStreamBuffer(
|
|
stream_function,
|
|
buffer_size=buffer_size,
|
|
),
|
|
),
|
|
),
|
|
QueuedStreamFunctionReceiver(),
|
|
IdentityInterpreter(),
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def rest_interpreter():
|
|
return rcompose(RestPickupStreamer(), RestReceiver())
|