Skip to content

Commit

Permalink
More test output
Browse files Browse the repository at this point in the history
  • Loading branch information
Lennart Regebro committed Oct 9, 2024
1 parent 7b5924b commit 8be2c57
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
os: [ubuntu-20.04, ubuntu-22.04]
fail-fast: true
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install Package
run: |
python -m pip install virtualenv
Expand All @@ -33,4 +33,4 @@ jobs:
- name: Test with pytest
run: |
source ve/bin/activate
make test
pytest -s
25 changes: 25 additions & 0 deletions src/unoserver/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ def signal_handler(signum, frame):
raise

if self.xmlrcp_server is not None:
logger.error("A")
self.stop() # Ensure the server stops
logger.error("B")

signal.signal(signal.SIGTERM, signal_handler)
signal.signal(signal.SIGINT, signal_handler)
Expand All @@ -115,7 +117,9 @@ def signal_handler(signum, frame):
# Check if it succeeded
if not self.xmlrcp_thread.is_alive():
logger.info("Failed to start servers")
logger.error("C")
self.stop()
logger.error("D")
return None

return self.libreoffice_process
Expand Down Expand Up @@ -195,22 +199,33 @@ def compare(
server.serve_forever()

def stop(self):
logger.info("STOP1")
if self.libreoffice_process:
logger.info("STOP2")
self.libreoffice_process.terminate()
if self.xmlrcp_server is not None:
logger.info("STOP2")
self.xmlrcp_server.shutdown()
# Make a dummy connection to unblock accept() - otherwise it will
# hang indefinitely in the accept() call.
# noinspection PyBroadException
try:
logger.info("STOP4")
with socket.create_connection(
(self.interface, int(self.port)), timeout=1
):
logger.info("STOP5")
pass

except Exception:
logger.info("STOP6")
pass # Ignore any except
logger.info("STOP7")
if self.xmlrcp_thread is not None:
logger.info("STOP8")
self.xmlrcp_thread.join()
logger.info("STOP9")
logger.info("STOP10")


def main():
Expand Down Expand Up @@ -298,29 +313,39 @@ def main():
with open(args.libreoffice_pid_file, "wt") as upf:
upf.write(f"{pid}")

logger.error("wait!")
process.wait()
logger.error("waited!")

if not server.intentional_exit:
logger.error(f"Looks like LibreOffice died. PID: {pid}")

# The RPC thread needs to be stopped before the process can exit
logger.error("E")
server.stop()
logger.error("F")

logger.error("OK?")

if args.libreoffice_pid_file:
# Remove the PID file
os.unlink(args.libreoffice_pid_file)

try:
# Make sure it's really dead
logger.error("Hmm?")
os.kill(pid, 0)
logger.error("OK!")

if server.intentional_exit:
return 0
else:
logger.error("NO!")
return 1
except OSError as e:
if e.errno == 3:
# All good, it was already dead.
logger.error("Yes")
return 0
raise

Expand Down
6 changes: 3 additions & 3 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_multiple_servers(server_fixture):
# Now kill the process
process.terminate()
# Wait for it to terminate
process.wait()
process.wait(10)
# And verify that it was killed
assert process.returncode == 0

Expand Down Expand Up @@ -222,7 +222,7 @@ def test_convert_not_local():
# Now kill the process
process.terminate()
# Wait for it to terminate
process.wait()
process.wait(timeout=10)
# And verify that it was killed
assert process.returncode == 0

Expand Down Expand Up @@ -262,6 +262,6 @@ def skip_test_compare_not_local():
# Now kill the process
process.terminate()
# Wait for it to terminate
process.wait()
process.wait(10)
# And verify that it was killed
assert process.returncode == 0

0 comments on commit 8be2c57

Please sign in to comment.