Skip to content

Commit

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

kiosk-smoke-tests:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8'
- uses: cachix/install-nix-action@v18
with:
nix_path: nixpkgs=channel:nixos-unstable
- uses: DeterminateSystems/magic-nix-cache-action@v4
- name: Run Smoke Test
run: cd kiosk && nix-shell --run "python smoke_test.py"

build-vm:
runs-on: ubuntu-latest
steps:
Expand Down
65 changes: 65 additions & 0 deletions kiosk/test/smoke_test.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 8efdc83

Please sign in to comment.