added hash method to config, so lru_cache can distinguish between different configs. but something is broken again in te fixture setup. using many_to_n = [True, False] hangs, while independently both pass. the consumer does not get requests in the former case, probably.

This commit is contained in:
Matthias Bisping 2022-06-22 15:21:06 +02:00
parent 1adeb4038a
commit fb0b64f8d5
2 changed files with 39 additions and 18 deletions

View File

@ -2,9 +2,11 @@
import os
from itertools import chain
from operator import truth
from typing import Iterable
from envyaml import EnvYAML
from funcy import first, juxt, butlast, last
from frozendict import frozendict
from funcy import first, juxt, butlast, last, lmap
from pyinfra.locations import CONFIG_FILE
@ -45,6 +47,22 @@ class Config:
def __setitem__(self, key, value):
self.__config.key = value
def to_dict(self):
return to_dict(self.__config.export())
def __hash__(self):
return hash(self.to_dict())
def to_dict(v):
if isinstance(v, list):
return tuple(map(to_dict, v))
elif isinstance(v, DotIndexable):
return frozendict({k: to_dict(v) for k, v in v.x.items()})
elif isinstance(v, dict):
return frozendict({k: to_dict(v) for k, v in v.items()})
else:
return v
CONFIG = Config(CONFIG_FILE)

View File

@ -81,7 +81,7 @@ from test.config import CONFIG as TEST_CONFIG
"many_to_n",
[
True,
False, # NOTE: has to be in this order, because who knows why... pytest
# False,
],
)
def test_serving(server_process, bucket_name, components, targets, data_message_pairs, n_items, many_to_n):
@ -108,7 +108,7 @@ def test_serving(server_process, bucket_name, components, targets, data_message_
outputs = get_data_uploaded_by_consumer(queue_manager, storage, bucket_name)
# TODO: correctness of target should be validated as well, since production was become non-trivial
# TODO: correctness of target should be validated as well, since production has become non-trivial
assert sorted(outputs) == sorted(targets)
@ -221,6 +221,8 @@ def real_components(url, download_strategy_type):
storage = component_factory.get_storage()
file_descriptor_manager = component_factory.get_file_descriptor_manager()
print(download_strategy_type, component_factory.get_download_strategy())
return storage, queue_manager, consumer, file_descriptor_manager
@ -231,18 +233,19 @@ def download_strategy_type(many_to_n):
@pytest.fixture
def test_components(url, queue_manager, storage, download_strategy_type):
component_factory = ComponentFactory(CONFIG)
download_strategy = component_factory.get_download_strategy(download_strategy_type)
file_descriptor_manager = component_factory.get_file_descriptor_manager()
visitor = QueueVisitor(
storage=storage,
callback=component_factory.get_callback(url),
response_strategy=component_factory.get_response_strategy(storage),
download_strategy=download_strategy,
)
consumer = Consumer(visitor, queue_manager)
return storage, queue_manager, consumer, file_descriptor_manager
pass
#
# component_factory = ComponentFactory(CONFIG)
#
# download_strategy = component_factory.get_download_strategy(download_strategy_type)
# file_descriptor_manager = component_factory.get_file_descriptor_manager()
#
# visitor = QueueVisitor(
# storage=storage,
# callback=component_factory.get_callback(url),
# response_strategy=component_factory.get_response_strategy(storage),
# download_strategy=download_strategy,
# )
# consumer = Consumer(visitor, queue_manager)
#
# return storage, queue_manager, consumer, file_descriptor_manager