Repository navigation
Named logger support and various server management enhancements - #132
Conversation
… depends on clients closing their logging handlers
| finally: | ||
| if server_proc.poll() is None: | ||
| server_proc.kill() | ||
| server_proc.wait(timeout=5) |
There was a problem hiding this comment.
Looks weird waiting on a subprocess you've just killed, but I've read a bit around this, and this looks like it is to avoid the subprocess becoming a zombie.
| time.sleep(1) # wait for db write to complete | ||
| server_proc.terminate() | ||
| server_proc.wait(timeout=5) | ||
| assert server_proc.returncode == 0, "Server process did not exit normally" |
There was a problem hiding this comment.
This failed once when running pytest:
> assert server_proc.returncode == 0, "Server process did not exit normally"
E AssertionError: Server process did not exit normally
E assert -15 == 0
E + where -15 = <Popen: returncode: -15 args: ['/data/users/eppdev/conda/envs/scitools-2025_...>.returncode
dagrunner/tests/utils/logging/test_integration.py:98: AssertionError
but a subsequent pytest run passed - weird.
Note that -15 means process was terminated with a SIGTERM
Maybe the assert should allow for 0 or -15 ?
There was a problem hiding this comment.
Thanks Rob Purvis (@mo-robert-purvis), I'll investigate.
There was a problem hiding this comment.
I think it may be that the 5s timeout was not enough, so the OS had to SIGTERM it.
There was a problem hiding this comment.
Multiple servers are being started concurrently by different tests. One of those tests intentionally sends a SIGTERM to its server, but because the servers are not distinguishable from one another, the signal can inadvertently affect servers belonging to other tests. Those tests then fail unexpectedly because their server has been terminated rather than being cleanly shut down.
| records and customise logging events. | ||
| """ | ||
|
|
||
| def _recv(self, size): |
There was a problem hiding this comment.
This is not covered by ptests
There was a problem hiding this comment.
_recv is tested indirectly through integration tests, rather than by calling the method directly.
test_sqlitedb and test_named_logger in test_integration.py send records to the server, terminate it, and verify that the records were persisted. More specifically, test_process_termination in test_start_logging_server.py keeps a client connected while testing shutdown with no data, an incomplete header, and an incomplete record body. It checks that the server exits and saves earlier complete records. Those cases exercise the shutdown behaviour implemented by _recv.
There was a problem hiding this comment.
verbose is not used in the function.
There was a problem hiding this comment.
done
| - `sqlite_filepath`: The file path to the SQLite database. Optional. | ||
| - `host`: The host name of the server. Optional. | ||
| - `port`: The port number the server is listening on. Optional. | ||
| - `verbose`: Whether to print verbose output. Optional. |
There was a problem hiding this comment.
verbose is not used in the function and should be removed.
There was a problem hiding this comment.
done
| # Logic around default values belong in the functions which use them. | ||
| _INI_PARAMETERS = { | ||
| "dagrunner_logging": {"host": None, "port": None, "enabled": None}, | ||
| "dagrunner_logging": { |
There was a problem hiding this comment.
ruff suggests these shouldn't be defined here
There was a problem hiding this comment.
why? I'm not sure I agree in this particular case of a singleton which is instantiated within this same module. Either way not in scope here.
Ruff is run as part of pre-commit and is passed fine there:
https://github.com/MetOffice/dagrunner/actions/runs/39392634239/job/118527595887#step:9:1
Rob Purvis (mo-robert-purvis)
left a comment
There was a problem hiding this comment.
Some comments to consider
|
The non-zero error is I suspect caused by pytest running tests in parallel. Multiple tests start logging servers simultaneously, and those servers are not uniquely identifiable, leading to conflicts. The fix is to configure the server port as 0, allowing the operating system to automatically allocate an available port. Each test can then retrieve the assigned port and connect its client to the corresponding logging server, ensuring that parallel test executions do not interfere with one another. |
|
|
474d545 to
6bb1f99
Compare
Rob Purvis (mo-robert-purvis)
left a comment
There was a problem hiding this comment.
Looks good.
Closes #125