debian-forge/test/mod/test_inputs.py
Michael Vogt 0abdfb9041 jsoncomm: transparently handle huge messages via fds
The existing jsoncomm is a work of beautiy. For very big arguments
however the used `SOCK_SEQPACKET` hits the limitations of the
kernel network buffer size (see also [0]). This lead to various
workarounds in #824,#1331,#1836 where parts of the request are
encoded as part of the json method call and parts are done via
a side-channel via fd-passing.

This commit changes the code so that the fd channel is automatically
and transparently created and the workarounds are removed. A test
is added that ensures that very big messages can be passed.

[0] https://github.com/osbuild/osbuild/pull/1833
2024-09-17 19:27:03 +02:00

40 lines
1.2 KiB
Python

import os
from unittest.mock import call, patch
from osbuild import inputs
class FakeInputService(inputs.InputService):
def __init__(self, args): # pylint: disable=super-init-not-called
# do not call "super().__init__()" here to make it testable
self.map_calls = []
def map(self, store, origin, refs, target, options):
self.map_calls.append([origin, refs, target, options])
return "complex", 2, "reply"
def test_inputs_dispatches_map(tmp_path):
store_api_path = tmp_path / "api-store"
store_api_path.write_text("")
args = {
"api": {
"store": os.fspath(store_api_path),
},
"origin": "some-origin",
"refs": "some-refs",
"target": "some-target",
"options": "some-options",
}
fake_service = FakeInputService(args="some")
with patch.object(inputs, "StoreClient") as mocked_store_client_klass:
r = fake_service.dispatch("map", args, None)
assert mocked_store_client_klass.call_args_list == [
call(connect_to=os.fspath(store_api_path)),
]
assert fake_service.map_calls == [
["some-origin", "some-refs", "some-target", "some-options"],
]
assert r == (("complex", 2, "reply"), None)