openmodule 18.5.0__tar.gz → 18.5.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {openmodule-18.5.0 → openmodule-18.5.1}/PKG-INFO +1 -1
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/dispatcher.py +7 -8
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/rpc/client.py +1 -1
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/rpc/server.py +5 -5
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/sentry.py +1 -1
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/utils/vehicle_listener.py +32 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule.egg-info/PKG-INFO +1 -1
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_rpc.py +8 -6
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_sentry.py +13 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/LICENSE +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/README.md +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/__init__.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/alert.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/config.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/connection_status.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/core.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/database/__init__.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/database/custom_types.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/database/database.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/database/env.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/database/migration.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/health.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/logging.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/messaging.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/models/__init__.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/models/access_service.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/models/alert.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/models/base.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/models/io.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/models/kv_store.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/models/pagination.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/models/presence.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/models/privacy.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/models/rpc.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/models/settings.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/models/signals.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/models/validation.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/models/vehicle.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/models/vehicle_listener.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/rpc/__init__.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/rpc/common.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/threading.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/utils/__init__.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/utils/access_service.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/utils/charset.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/utils/cleanup.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/utils/csv_export.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/utils/databox.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/utils/db_helper.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/utils/eventlog.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/utils/io.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/utils/kv_store.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/utils/matching.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/utils/misc_functions.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/utils/package_reader.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/utils/pagination.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/utils/presence.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/utils/schedule.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/utils/settings.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/utils/signal_listener.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/utils/translation.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule/utils/validation.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule.egg-info/SOURCES.txt +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule.egg-info/dependency_links.txt +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule.egg-info/not-zip-safe +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule.egg-info/requires.txt +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/openmodule.egg-info/top_level.txt +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/setup.cfg +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/setup.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_alembic_migrations.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_alert.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_checks.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_config.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_connection_status.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_core.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_database.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_dispatcher.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_health.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_interrupt.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_io_listen.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_logging.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_messaging.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_mockrpcclient.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_model.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_test_alert.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_test_gate.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_test_zeromq.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_utils_access_service.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_utils_charset.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_utils_cleanup.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_utils_csv_export.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_utils_databox.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_utils_eventlog.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_utils_kv_store.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_utils_kv_store_multiple.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_utils_matching.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_utils_misc_functions.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_utils_package_reader.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_utils_pagination.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_utils_presence.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_utils_schedule.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_utils_settings.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_utils_signal.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_utils_validation.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_utils_vehicle.py +0 -0
- {openmodule-18.5.0 → openmodule-18.5.1}/tests/test_vehicle_listener.py +0 -0
|
@@ -20,7 +20,7 @@ from openmodule.config import settings
|
|
|
20
20
|
from openmodule.models.base import ZMQMessage
|
|
21
21
|
|
|
22
22
|
|
|
23
|
-
DispatcherFilterType =
|
|
23
|
+
DispatcherFilterType = Callable[[dict], bool] | None
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
class DummyExecutor(Executor):
|
|
@@ -56,8 +56,7 @@ class Listener:
|
|
|
56
56
|
return False
|
|
57
57
|
|
|
58
58
|
if self.filter_:
|
|
59
|
-
|
|
60
|
-
return self.filter_(message) # type: ignore
|
|
59
|
+
return self.filter_(message)
|
|
61
60
|
else:
|
|
62
61
|
return True
|
|
63
62
|
|
|
@@ -153,10 +152,10 @@ class MessageDispatcher:
|
|
|
153
152
|
"""
|
|
154
153
|
registers a message handler. without any filters all messages from the topic are
|
|
155
154
|
sent to the message handler.
|
|
156
|
-
:param filter_: a
|
|
157
|
-
|
|
158
|
-
:param match_type: if set to true the message_class's type field is used as a filter.
|
|
159
|
-
|
|
155
|
+
:param filter_: a function which receives the raw message dict (before validation) and returns
|
|
156
|
+
True if the message should be further processed
|
|
157
|
+
:param match_type: if set to true the message_class's type field is used as a filter, i.e. only
|
|
158
|
+
messages whose "type" equals message_class.model_fields["type"].default are processed
|
|
160
159
|
"""
|
|
161
160
|
|
|
162
161
|
assert isinstance(topic, str), "topic must be a string"
|
|
@@ -176,7 +175,7 @@ class MessageDispatcher:
|
|
|
176
175
|
listener = Listener(message_class, type_, filter_, handler)
|
|
177
176
|
self.listeners[topic].append(listener)
|
|
178
177
|
|
|
179
|
-
if settings.TESTING and hasattr(handler, "
|
|
178
|
+
if settings.TESTING and hasattr(handler, "__globals__") and "/tests/" not in handler.__globals__['__file__']:
|
|
180
179
|
# only doc string necessary for functions or lambdas (so not for mocks) outside of tests folder
|
|
181
180
|
assert handler.__doc__, f"You need to describe the message handler {handler} with a doc string"
|
|
182
181
|
|
|
@@ -65,7 +65,7 @@ class RPCClient:
|
|
|
65
65
|
if timeout and (timeout > self.timeout):
|
|
66
66
|
warnings.warn("You cannot extend the timeout of an RPC after sending the request. "
|
|
67
67
|
"The timeout will be limited to at most the initial timeout.", stacklevel=2)
|
|
68
|
-
timeout =
|
|
68
|
+
timeout = min(timeout, self.timeout)
|
|
69
69
|
|
|
70
70
|
if self.response is None:
|
|
71
71
|
timeout = timeout or self.timeout
|
|
@@ -13,6 +13,7 @@ from openmodule.config import settings
|
|
|
13
13
|
from openmodule.core import core
|
|
14
14
|
from openmodule.dispatcher import DummyExecutor
|
|
15
15
|
from openmodule.messaging import get_sub_socket, receive_message_from_socket
|
|
16
|
+
from openmodule.models.base import Gateway, OpenModuleModel
|
|
16
17
|
from openmodule.models.rpc import RPCResponse, RPCRequest, RPCServerError
|
|
17
18
|
from openmodule.rpc.common import channel_to_request_topic, channel_to_response_topic
|
|
18
19
|
from openmodule.threading import get_thread_wrapper
|
|
@@ -31,12 +32,11 @@ Each filter function must have 3 parameters:
|
|
|
31
32
|
|
|
32
33
|
|
|
33
34
|
def gateway_filter(gate=None, direction=None):
|
|
34
|
-
def _filter(request, _message, _handler):
|
|
35
|
-
gateway = request
|
|
35
|
+
def _filter(request: OpenModuleModel, _message, _handler):
|
|
36
|
+
gateway: Gateway | None = getattr(request, "gateway", None)
|
|
36
37
|
if not gateway:
|
|
37
38
|
return False
|
|
38
|
-
return (not gate or gate == gateway.
|
|
39
|
-
(not direction or direction == gateway.get("direction"))
|
|
39
|
+
return (not gate or gate == gateway.gate) and (not direction or direction == gateway.direction)
|
|
40
40
|
|
|
41
41
|
return _filter
|
|
42
42
|
|
|
@@ -137,7 +137,7 @@ class RPCServer(object):
|
|
|
137
137
|
traced_handler = sentry.trace(f"rpc_handler.{qualname_from_function(handler)}")(handler)
|
|
138
138
|
self.handlers[(channel, type)] = HandlerEntry(request_class, response_class, traced_handler)
|
|
139
139
|
self.registered_channels = set(x[0] for x in self.handlers.keys())
|
|
140
|
-
if settings.TESTING and hasattr(handler, "
|
|
140
|
+
if settings.TESTING and hasattr(handler, "__globals__") and "/tests/" not in handler.__globals__['__file__']:
|
|
141
141
|
# only doc string necessary for functions or lambdas (so not for mocks) outside of tests folder
|
|
142
142
|
assert handler.__doc__, f"You need to describe the RPC handler {handler} with a doc string"
|
|
143
143
|
|
|
@@ -405,7 +405,7 @@ def _update_sentry_config(kwargs: dict):
|
|
|
405
405
|
kwargs.setdefault("shutdown_timeout", 2)
|
|
406
406
|
kwargs["environment"] = "staging" if settings.DEV_DEVICE else "production"
|
|
407
407
|
kwargs["server_name"] = settings.RESOURCE
|
|
408
|
-
service_name = service_name_without_om = settings.NAME.
|
|
408
|
+
service_name = service_name_without_om = settings.NAME.removeprefix("om_")
|
|
409
409
|
if "_" in service_name_without_om:
|
|
410
410
|
service_name, instance = service_name_without_om.rsplit("_", 1)
|
|
411
411
|
if not instance.isdigit():
|
|
@@ -175,6 +175,10 @@ class VehicleListener:
|
|
|
175
175
|
return []
|
|
176
176
|
|
|
177
177
|
def _on_present_vehicle_init(self, msg: PresentVehicleInitMessage):
|
|
178
|
+
"""
|
|
179
|
+
Compares the present vehicle after a (re)start of the presence service with the known one,
|
|
180
|
+
fakes a leave if the vehicle left meanwhile and requests a trigger if the states differ otherwise.
|
|
181
|
+
"""
|
|
178
182
|
if msg.gate not in self.present_vehicles:
|
|
179
183
|
self.present_vehicles[msg.gate] = None
|
|
180
184
|
present_id = self.present_vehicles[msg.gate] and self.present_vehicles[msg.gate].vehicle_id
|
|
@@ -191,6 +195,9 @@ class VehicleListener:
|
|
|
191
195
|
self.rpc_client.rpc("presence", "trigger", PresenceTriggerRequest(gate=msg.gate), PresenceTriggerResponse)
|
|
192
196
|
|
|
193
197
|
def _on_present_vehicle_enter(self, msg: PresentVehicleEnterMessage | PresentVehicleChangeMessage):
|
|
198
|
+
"""
|
|
199
|
+
Stores the entered vehicle as present (unless the present one is locked) and calls the enter callbacks.
|
|
200
|
+
"""
|
|
194
201
|
if self.present_vehicles.get(msg.gate) is not None:
|
|
195
202
|
vehicle = self.present_vehicles[msg.gate]
|
|
196
203
|
if vehicle.get_primary_lpr() is not None:
|
|
@@ -209,6 +216,9 @@ class VehicleListener:
|
|
|
209
216
|
self._execute_callbacks([FilterType.enter, FilterType.any_enter], self.present_vehicles[msg.gate], msg)
|
|
210
217
|
|
|
211
218
|
def _on_present_vehicle_change(self, msg: PresentVehicleChangeMessage):
|
|
219
|
+
"""
|
|
220
|
+
Updates the present vehicle (unless locked) and calls the plate or lpr update callbacks if those changed.
|
|
221
|
+
"""
|
|
212
222
|
if self.present_vehicles.get(msg.gate) and self.present_vehicles.get(msg.gate).vehicle_id != msg.vehicle_id:
|
|
213
223
|
self.log.error("%s: Received change message with different vehicle id. "
|
|
214
224
|
"Faking leave and, if different plate, forward.", msg.gate)
|
|
@@ -230,6 +240,9 @@ class VehicleListener:
|
|
|
230
240
|
self._execute_callbacks(filter_types, self.present_vehicles[msg.gate], msg)
|
|
231
241
|
|
|
232
242
|
def _on_present_vehicle_leave(self, msg: PresentVehicleLeaveMessage):
|
|
243
|
+
"""
|
|
244
|
+
Calls the leave callbacks and remembers the vehicle for a later forward, backward or re-enter.
|
|
245
|
+
"""
|
|
233
246
|
self.previous_present_vehicles = {k: v for k, v in self.previous_present_vehicles.items()
|
|
234
247
|
if v.leave_time and (utcnow() - v.leave_time) < timedelta(minutes=5)}
|
|
235
248
|
old_present_vehicle = self.present_vehicles.get(msg.gate)
|
|
@@ -254,6 +267,9 @@ class VehicleListener:
|
|
|
254
267
|
self.present_vehicles[msg.gate] = None
|
|
255
268
|
|
|
256
269
|
def _on_present_vehicle_forward(self, msg: PresentVehicleForwardMessage):
|
|
270
|
+
"""
|
|
271
|
+
Calls the forward callbacks for the vehicle that left before.
|
|
272
|
+
"""
|
|
257
273
|
if msg.vehicle_id not in self.previous_present_vehicles:
|
|
258
274
|
self.log.error("%s: Received forward message for unknown vehicle id. Doing nothing.", msg.gate)
|
|
259
275
|
else:
|
|
@@ -262,6 +278,9 @@ class VehicleListener:
|
|
|
262
278
|
self.previous_present_vehicles.pop(msg.vehicle_id)
|
|
263
279
|
|
|
264
280
|
def _on_present_vehicle_backward(self, msg: PresentVehicleBackwardMessage):
|
|
281
|
+
"""
|
|
282
|
+
Calls the backward callbacks for the vehicle that left before.
|
|
283
|
+
"""
|
|
265
284
|
if msg.vehicle_id not in self.previous_present_vehicles:
|
|
266
285
|
self.log.error("%s: Received backward message for unknown vehicle id. Doing nothing.", msg.gate)
|
|
267
286
|
else:
|
|
@@ -270,10 +289,16 @@ class VehicleListener:
|
|
|
270
289
|
self.previous_present_vehicles.pop(msg.vehicle_id)
|
|
271
290
|
|
|
272
291
|
def _on_present_vehicle_passing(self, msg: PresentVehiclePassingMessage):
|
|
292
|
+
"""
|
|
293
|
+
Calls the passing callbacks.
|
|
294
|
+
"""
|
|
273
295
|
self.log.info("%s: Vehicle %s passed.", msg.gate, msg)
|
|
274
296
|
self._execute_callbacks([FilterType.passing], None, msg)
|
|
275
297
|
|
|
276
298
|
def _on_present_vehicle_empty_enter(self, msg: PresentVehicleEmptyEnterMessage):
|
|
299
|
+
"""
|
|
300
|
+
Stores the entered vehicle without LPR as present and calls the empty enter callbacks.
|
|
301
|
+
"""
|
|
277
302
|
if self.present_vehicles.get(msg.gate) is not None:
|
|
278
303
|
self.log.warning("%s: Received empty enter message while vehicle already present. "
|
|
279
304
|
"Faking leave and, if different plate, forward.", msg.gate)
|
|
@@ -285,6 +310,9 @@ class VehicleListener:
|
|
|
285
310
|
msg)
|
|
286
311
|
|
|
287
312
|
def _on_present_vehicle_empty_leave(self, msg: PresentVehicleEmptyLeaveMessage):
|
|
313
|
+
"""
|
|
314
|
+
Removes the present vehicle without LPR and calls the empty leave callbacks.
|
|
315
|
+
"""
|
|
288
316
|
old_present_vehicle = self.present_vehicles.get(msg.gate)
|
|
289
317
|
if old_present_vehicle is None:
|
|
290
318
|
self.log.warning("%s: Received empty leave message while no vehicle present. Doing nothing.", msg.gate)
|
|
@@ -306,6 +334,10 @@ class VehicleListener:
|
|
|
306
334
|
self._execute_callbacks([leave_type, FilterType.any_leave], old_present_vehicle, msg)
|
|
307
335
|
|
|
308
336
|
def _on_present_vehicle_triggered(self, msg: PresentVehicleTriggeredMessage):
|
|
337
|
+
"""
|
|
338
|
+
Syncs the present vehicle with the presence service after a trigger and calls the enter callbacks
|
|
339
|
+
if a new vehicle is present.
|
|
340
|
+
"""
|
|
309
341
|
old_present_vehicle = self.present_vehicles.get(msg.gate)
|
|
310
342
|
if old_present_vehicle and old_present_vehicle.vehicle_id != msg.vehicle_id:
|
|
311
343
|
self.log.warning("%s: Received trigger message with different vehicle id. "
|
|
@@ -12,7 +12,7 @@ import freezegun
|
|
|
12
12
|
from pydantic.types import conint
|
|
13
13
|
|
|
14
14
|
from openmodule.config import settings
|
|
15
|
-
from openmodule.models.base import OpenModuleModel, EmptyModel, OpenModuleRootModel, ZMQMessage
|
|
15
|
+
from openmodule.models.base import OpenModuleModel, EmptyModel, OpenModuleRootModel, ZMQMessage, Gateway
|
|
16
16
|
from openmodule.models.rpc import RPCResponse
|
|
17
17
|
from openmodule.rpc import server
|
|
18
18
|
from openmodule.rpc.client import RPCClient
|
|
@@ -24,6 +24,10 @@ from openmodule_test.rpc import RPCServerTestMixin
|
|
|
24
24
|
from openmodule_test.sentry import SentryTestMixin
|
|
25
25
|
|
|
26
26
|
|
|
27
|
+
class _GatewayRequest(OpenModuleModel):
|
|
28
|
+
gateway: Gateway | None = None
|
|
29
|
+
|
|
30
|
+
|
|
27
31
|
def _fake_request(gate=..., direction=...):
|
|
28
32
|
gateway = {}
|
|
29
33
|
if gate != Ellipsis:
|
|
@@ -31,11 +35,7 @@ def _fake_request(gate=..., direction=...):
|
|
|
31
35
|
if direction != Ellipsis:
|
|
32
36
|
gateway["direction"] = direction
|
|
33
37
|
|
|
34
|
-
|
|
35
|
-
if gateway:
|
|
36
|
-
request["gateway"] = gateway
|
|
37
|
-
|
|
38
|
-
return request
|
|
38
|
+
return _GatewayRequest(gateway=gateway or None)
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
class RPCCommonTestCase(TestCase):
|
|
@@ -580,10 +580,12 @@ class RpcClientTest(RPCServerTestMixin, OpenModuleCoreTestMixin):
|
|
|
580
580
|
|
|
581
581
|
def test_non_blocking_higher_timeout_than_at_request(self):
|
|
582
582
|
result = self.client.rpc_non_blocking("channel", "timeout", EmptyModel(), timeout=1)
|
|
583
|
+
start = time.time()
|
|
583
584
|
with self.assertRaises(RPCClient.TimeoutError):
|
|
584
585
|
with self.assertWarns(UserWarning) as cm:
|
|
585
586
|
result.result(TestRPCResponse2, timeout=2)
|
|
586
587
|
self.assertIn("cannot extend", str(cm.warnings[0].message))
|
|
588
|
+
self.assertLess(time.time() - start, 1.5)
|
|
587
589
|
|
|
588
590
|
def test_non_blocking_no_timeout(self):
|
|
589
591
|
result = self.client.rpc_non_blocking("channel", "timeout", EmptyModel(), timeout=4)
|
|
@@ -195,6 +195,19 @@ class SentryInitTestCase(ZMQTestMixin):
|
|
|
195
195
|
sentry._update_sentry_config(kwargs)
|
|
196
196
|
self.assertEqual(kwargs["release"], "service-test@test-version")
|
|
197
197
|
|
|
198
|
+
@override_settings(NAME="test")
|
|
199
|
+
def test_service_name_generation_keeps_characters_of_om_prefix(self):
|
|
200
|
+
"""only the prefix "om_" is removed, not every leading "o", "m" and "_" of the name"""
|
|
201
|
+
settings.NAME = "om_mobile_access_1"
|
|
202
|
+
kwargs = {}
|
|
203
|
+
sentry._update_sentry_config(kwargs)
|
|
204
|
+
self.assertEqual(kwargs["release"], "mobile-access@test-version")
|
|
205
|
+
|
|
206
|
+
settings.NAME = "mobile_access"
|
|
207
|
+
kwargs = {}
|
|
208
|
+
sentry._update_sentry_config(kwargs)
|
|
209
|
+
self.assertEqual(kwargs["release"], "mobile-access@test-version")
|
|
210
|
+
|
|
198
211
|
def test_sentry_ignore_topics(self):
|
|
199
212
|
self.assertEqual(sentry._topics_to_ignore, ["io"])
|
|
200
213
|
init_openmodule(self.zmq_config(), context=self.zmq_context(), sentry=True, dsn="http://test@test/1",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|