Skip to content

Commit

Permalink
Add kiosk smoke test for secondary platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
knuton committed May 3, 2024
1 parent 48509e6 commit 06fe495
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ jobs:
- uses: DeterminateSystems/magic-nix-cache-action@v4
- run: cd kiosk && nix-shell --run bin/test

kiosk-smoke-tests:
# While the smoke test should run on other platforms, it does not currently
# run on GitHub's Ubuntu runners, as they don't support GUI applications.
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.8'
- uses: cachix/install-nix-action@v18
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: Smoke Test
run: cd kiosk && nix-shell --run "python test/platform-smoke.py"

build-vm:
runs-on: ubuntu-latest
steps:
Expand Down
65 changes: 65 additions & 0 deletions kiosk/test/platform-smoke.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import http.server
import socket
import socketserver
import threading
import subprocess
import time

PORT = 45678
request_count = 0

def main():
"""Checks that the kiosk-browser does not crash immediately on start and makes a request to the provided URL.
This serves as a minimal test to make sure the kiosk can run on different platforms.
"""

# Start dummy web server in thread, with signal to stop
keep_running = threading.Event()
keep_running.set()
server_thread = threading.Thread(target=run_server, args=(keep_running,))
server_thread.start()
time.sleep(1)

try:
browser_process = subprocess.Popen(['bin/kiosk-browser', f'http://localhost:{PORT}', f'http://localhost:{PORT}'])
time.sleep(5)

# Minimal expectations
assert browser_process.poll() is None, "Browser process has crashed."
assert request_count >= 1, "No requests were made to the server."

print("Smoke test passed successfully.")

finally:
# Send signal to stop web server and wait for completion
keep_running.clear()
server_thread.join()

# Terminate the browser process
browser_process.terminate()

class RequestHandler(http.server.SimpleHTTPRequestHandler):
"""Default request handler with added counter."""
def do_GET(self):
global request_count
request_count += 1
# Call superclass method to actually serve the request
super().do_GET()

def run_server(keep_running):
"""Run the web server, checking whether to keep running frequently."""
with socketserver.TCPServer(("", PORT), RequestHandler, bind_and_activate=False) as httpd:
# Let address be reused to avoid failure on repeated runs
httpd.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
httpd.server_bind()
httpd.server_activate()
# Timeout frequently to check if killed
httpd.timeout = 0.5
try:
while keep_running.is_set():
httpd.handle_request()
finally:
httpd.server_close()

main()

0 comments on commit 06fe495

Please sign in to comment.