Skip to content

Commit

Permalink
test: make integration tests also run for aw-server-rust
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Oct 19, 2023
1 parent 1270209 commit 42187d8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@ test-integration:
# TODO: Move "integration tests" to aw-client
# FIXME: For whatever reason the script stalls on Appveyor
# Example: https://ci.appveyor.com/project/ErikBjare/activitywatch/build/1.0.167/job/k1ulexsc5ar5uv4v
pytest ./scripts/tests/integration_tests.py ./aw-server/tests/ -v
# aw-server-python
@echo "== Integration testing aw-server =="
@pytest ./scripts/tests/integration_tests.py ./aw-server/tests/ -v
# aw-server-rust
@echo "== Integration testing aw-server-rust =="
@export PATH=aw-server-rust/target/release:aw-server-rust/target/debug:${PATH}; \
pytest ./scripts/tests/integration_tests.py ./aw-server/tests/ -v

ICON := "aw-qt/media/logo/logo.png"

Expand Down
29 changes: 22 additions & 7 deletions scripts/tests/integration_tests.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
import os
import platform
import subprocess
from time import sleep
import tempfile
import platform
from time import sleep

import pytest


def _windows_kill_process(pid):
import ctypes

PROCESS_TERMINATE = 1
handle = ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE, False, pid)
ctypes.windll.kernel32.TerminateProcess(handle, -1)
ctypes.windll.kernel32.CloseHandle(handle)


# NOTE: to run tests with a specific server binary,
# set the PATH such that it is the "aw-server" binary.
@pytest.fixture(scope="session")
def server_process():
logfile_stdout = tempfile.NamedTemporaryFile(delete=False)
logfile_stderr = tempfile.NamedTemporaryFile(delete=False)

server_proc = subprocess.Popen(["aw-server", "--testing"], stdout=logfile_stdout, stderr=logfile_stderr)
# find the path of the "aw-server" binary and log it
which_server = subprocess.check_output(["which", "aw-server"], text=True)
print(f"aw-server path: {which_server}")

# if aw-server-rust in PATH, assert that we're picking up the aw-server-rust binary
if "aw-server-rust" in os.environ["PATH"]:
assert "aw-server-rust" in which_server

server_proc = subprocess.Popen(
["aw-server", "--testing"], stdout=logfile_stdout, stderr=logfile_stderr
)

# Wait for server to start up properly
# TODO: Ping the server until it's alive to remove this sleep
Expand All @@ -40,19 +54,20 @@ def server_process():
with open(logfile_stdout.name, "r+b") as f:
stdout = str(f.read(), "utf8")
if any(e in stdout for e in error_indicators):
pytest.fail("Found ERROR indicator in stdout from server: {}".format(stdout))
pytest.fail(f"Found ERROR indicator in stdout from server: {stdout}")

with open(logfile_stderr.name, "r+b") as f:
stderr = str(f.read(), "utf8")
if not stderr:
pytest.fail("No output to stderr from server")
# For some reason, this fails aw-server-rust, but not aw-server-python
# if not stderr:
# pytest.fail("No output to stderr from server")

# Will show in case pytest fails
print(stderr)

for s in error_indicators:
if s in stderr:
pytest.fail("Found ERROR indicator in stderr from server: {}".format(s))
pytest.fail(f"Found ERROR indicator in stderr from server: {s}")

# NOTE: returncode was -9 for whatever reason
# if server_proc.returncode != 0:
Expand Down

0 comments on commit 42187d8

Please sign in to comment.