SIENTIAPDE-1646
Add tests for retrain, drift, storage, OPC repo, worker paths - covers csv lookup fallback, drift insufficient-data passthrough, timestamp tz normalization, storage close without engine, OPC watchdog/write_value fallbacks and reconnect reporting, and legacy runtime install in worker main
This commit is contained in:
@@ -248,3 +248,45 @@ async def test_main_worker_gather_error_exits_one(monkeypatch):
|
||||
await worker.main()
|
||||
|
||||
assert m_logger.return_value.custom_error.called
|
||||
|
||||
|
||||
@mark.asyncio
|
||||
async def test_main_legacy_runtime_installs_single(monkeypatch):
|
||||
"""The `legacy` runtime is served by the `single` store runtime."""
|
||||
monkeypatch.setenv('RUNTIME', 'legacy')
|
||||
fake_plugin = MagicMock()
|
||||
fake_plugin.install_runtime = AsyncMock(side_effect=RuntimeError('stop after install'))
|
||||
with (
|
||||
patch('laborious.worker.worker.start_prometheus_server'),
|
||||
patch('laborious.worker.worker.get_logger'),
|
||||
patch(
|
||||
'laborious.worker.worker.build_mongodb_config',
|
||||
return_value={'connection_string': 'cs', 'database_name': 'db'},
|
||||
),
|
||||
patch('laborious.worker.worker.NotificationHandler'),
|
||||
patch('laborious.worker.worker.MetricsController'),
|
||||
patch(
|
||||
'laborious.worker.worker.build_plugin_store_config',
|
||||
return_value={
|
||||
'base_url': '',
|
||||
'owner': '',
|
||||
'repo': '',
|
||||
'username': None,
|
||||
'password': None,
|
||||
'branch': None,
|
||||
'cache_ttl_seconds': None,
|
||||
'pypi_index_url': '',
|
||||
'pypi_username': None,
|
||||
'pypi_password': None,
|
||||
},
|
||||
),
|
||||
patch('laborious.worker.worker.PluginStore', return_value=fake_plugin),
|
||||
patch.object(worker.metrics.APP_UP, 'labels') as labels,
|
||||
patch('laborious.worker.worker.sys.exit', side_effect=SystemExit(1)),
|
||||
):
|
||||
labels.return_value = MagicMock()
|
||||
with raises(SystemExit):
|
||||
await worker.main()
|
||||
|
||||
fake_plugin.install_runtime.assert_awaited_once()
|
||||
assert fake_plugin.install_runtime.await_args.kwargs['runtime_name'] == 'single'
|
||||
|
||||
Reference in New Issue
Block a user