diff options
Diffstat (limited to 'testing/web-platform/tests/tools/third_party/websockets/example/deployment')
21 files changed, 393 insertions, 0 deletions
diff --git a/testing/web-platform/tests/tools/third_party/websockets/example/deployment/fly/Procfile b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/fly/Procfile new file mode 100644 index 0000000000..2e35818f67 --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/fly/Procfile @@ -0,0 +1 @@ +web: python app.py diff --git a/testing/web-platform/tests/tools/third_party/websockets/example/deployment/fly/app.py b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/fly/app.py new file mode 100644 index 0000000000..4ca34d23bb --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/fly/app.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python + +import asyncio +import http +import signal + +import websockets + + +async def echo(websocket): + async for message in websocket: + await websocket.send(message) + + +async def health_check(path, request_headers): + if path == "/healthz": + return http.HTTPStatus.OK, [], b"OK\n" + + +async def main(): + # Set the stop condition when receiving SIGTERM. + loop = asyncio.get_running_loop() + stop = loop.create_future() + loop.add_signal_handler(signal.SIGTERM, stop.set_result, None) + + async with websockets.serve( + echo, + host="", + port=8080, + process_request=health_check, + ): + await stop + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/testing/web-platform/tests/tools/third_party/websockets/example/deployment/fly/fly.toml b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/fly/fly.toml new file mode 100644 index 0000000000..5290072ed2 --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/fly/fly.toml @@ -0,0 +1,16 @@ +app = "websockets-echo" +kill_signal = "SIGTERM" + +[build] + builder = "paketobuildpacks/builder:base" + +[[services]] + internal_port = 8080 + protocol = "tcp" + + [[services.http_checks]] + path = "/healthz" + + [[services.ports]] + handlers = ["tls", "http"] + port = 443 diff --git a/testing/web-platform/tests/tools/third_party/websockets/example/deployment/fly/requirements.txt b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/fly/requirements.txt new file mode 100644 index 0000000000..14774b465e --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/fly/requirements.txt @@ -0,0 +1 @@ +websockets diff --git a/testing/web-platform/tests/tools/third_party/websockets/example/deployment/haproxy/app.py b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/haproxy/app.py new file mode 100644 index 0000000000..360479b8eb --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/haproxy/app.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python + +import asyncio +import os +import signal + +import websockets + + +async def echo(websocket): + async for message in websocket: + await websocket.send(message) + + +async def main(): + # Set the stop condition when receiving SIGTERM. + loop = asyncio.get_running_loop() + stop = loop.create_future() + loop.add_signal_handler(signal.SIGTERM, stop.set_result, None) + + async with websockets.serve( + echo, + host="localhost", + port=8000 + int(os.environ["SUPERVISOR_PROCESS_NAME"][-2:]), + ): + await stop + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/testing/web-platform/tests/tools/third_party/websockets/example/deployment/haproxy/haproxy.cfg b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/haproxy/haproxy.cfg new file mode 100644 index 0000000000..e63727d1c0 --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/haproxy/haproxy.cfg @@ -0,0 +1,17 @@ +defaults + mode http + timeout connect 10s + timeout client 30s + timeout server 30s + +frontend websocket + bind localhost:8080 + default_backend websocket + +backend websocket + balance leastconn + server websockets-test_00 localhost:8000 + server websockets-test_01 localhost:8001 + server websockets-test_02 localhost:8002 + server websockets-test_03 localhost:8003 + diff --git a/testing/web-platform/tests/tools/third_party/websockets/example/deployment/haproxy/supervisord.conf b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/haproxy/supervisord.conf new file mode 100644 index 0000000000..76a664d91b --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/haproxy/supervisord.conf @@ -0,0 +1,7 @@ +[supervisord] + +[program:websockets-test] +command = python app.py +process_name = %(program_name)s_%(process_num)02d +numprocs = 4 +autorestart = true diff --git a/testing/web-platform/tests/tools/third_party/websockets/example/deployment/heroku/Procfile b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/heroku/Procfile new file mode 100644 index 0000000000..2e35818f67 --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/heroku/Procfile @@ -0,0 +1 @@ +web: python app.py diff --git a/testing/web-platform/tests/tools/third_party/websockets/example/deployment/heroku/app.py b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/heroku/app.py new file mode 100644 index 0000000000..d4ba3edb51 --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/heroku/app.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python + +import asyncio +import signal +import os + +import websockets + + +async def echo(websocket): + async for message in websocket: + await websocket.send(message) + + +async def main(): + # Set the stop condition when receiving SIGTERM. + loop = asyncio.get_running_loop() + stop = loop.create_future() + loop.add_signal_handler(signal.SIGTERM, stop.set_result, None) + + async with websockets.serve( + echo, + host="", + port=int(os.environ["PORT"]), + ): + await stop + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/testing/web-platform/tests/tools/third_party/websockets/example/deployment/heroku/requirements.txt b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/heroku/requirements.txt new file mode 100644 index 0000000000..14774b465e --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/heroku/requirements.txt @@ -0,0 +1 @@ +websockets diff --git a/testing/web-platform/tests/tools/third_party/websockets/example/deployment/kubernetes/Dockerfile b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/kubernetes/Dockerfile new file mode 100644 index 0000000000..83ed8722c0 --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/kubernetes/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.9-alpine + +RUN pip install websockets + +COPY app.py . + +CMD ["python", "app.py"] diff --git a/testing/web-platform/tests/tools/third_party/websockets/example/deployment/kubernetes/app.py b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/kubernetes/app.py new file mode 100644 index 0000000000..a8bcef6881 --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/kubernetes/app.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python + +import asyncio +import http +import signal +import sys +import time + +import websockets + + +async def slow_echo(websocket): + async for message in websocket: + # Block the event loop! This allows saturating a single asyncio + # process without opening an impractical number of connections. + time.sleep(0.1) # 100ms + await websocket.send(message) + + +async def health_check(path, request_headers): + if path == "/healthz": + return http.HTTPStatus.OK, [], b"OK\n" + if path == "/inemuri": + loop = asyncio.get_running_loop() + loop.call_later(1, time.sleep, 10) + return http.HTTPStatus.OK, [], b"Sleeping for 10s\n" + if path == "/seppuku": + loop = asyncio.get_running_loop() + loop.call_later(1, sys.exit, 69) + return http.HTTPStatus.OK, [], b"Terminating\n" + + +async def main(): + # Set the stop condition when receiving SIGTERM. + loop = asyncio.get_running_loop() + stop = loop.create_future() + loop.add_signal_handler(signal.SIGTERM, stop.set_result, None) + + async with websockets.serve( + slow_echo, + host="", + port=80, + process_request=health_check, + ): + await stop + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/testing/web-platform/tests/tools/third_party/websockets/example/deployment/kubernetes/benchmark.py b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/kubernetes/benchmark.py new file mode 100644 index 0000000000..22ee4c5bd7 --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/kubernetes/benchmark.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python + +import asyncio +import sys +import websockets + + +URI = "ws://localhost:32080" + + +async def run(client_id, messages): + async with websockets.connect(URI) as websocket: + for message_id in range(messages): + await websocket.send(f"{client_id}:{message_id}") + await websocket.recv() + + +async def benchmark(clients, messages): + await asyncio.wait([ + asyncio.create_task(run(client_id, messages)) + for client_id in range(clients) + ]) + + +if __name__ == "__main__": + clients, messages = int(sys.argv[1]), int(sys.argv[2]) + asyncio.run(benchmark(clients, messages)) diff --git a/testing/web-platform/tests/tools/third_party/websockets/example/deployment/kubernetes/deployment.yaml b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/kubernetes/deployment.yaml new file mode 100644 index 0000000000..ba58dd62bf --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/kubernetes/deployment.yaml @@ -0,0 +1,35 @@ +apiVersion: v1 +kind: Service +metadata: + name: websockets-test +spec: + type: NodePort + ports: + - port: 80 + nodePort: 32080 + selector: + app: websockets-test +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: websockets-test +spec: + selector: + matchLabels: + app: websockets-test + template: + metadata: + labels: + app: websockets-test + spec: + containers: + - name: websockets-test + image: websockets-test:1.0 + livenessProbe: + httpGet: + path: /healthz + port: 80 + periodSeconds: 1 + ports: + - containerPort: 80 diff --git a/testing/web-platform/tests/tools/third_party/websockets/example/deployment/nginx/app.py b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/nginx/app.py new file mode 100644 index 0000000000..24e6089756 --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/nginx/app.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python + +import asyncio +import os +import signal + +import websockets + + +async def echo(websocket): + async for message in websocket: + await websocket.send(message) + + +async def main(): + # Set the stop condition when receiving SIGTERM. + loop = asyncio.get_running_loop() + stop = loop.create_future() + loop.add_signal_handler(signal.SIGTERM, stop.set_result, None) + + async with websockets.unix_serve( + echo, + path=f"{os.environ['SUPERVISOR_PROCESS_NAME']}.sock", + ): + await stop + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/testing/web-platform/tests/tools/third_party/websockets/example/deployment/nginx/nginx.conf b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/nginx/nginx.conf new file mode 100644 index 0000000000..67aa0086d5 --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/nginx/nginx.conf @@ -0,0 +1,25 @@ +daemon off; + +events { +} + +http { + server { + listen localhost:8080; + + location / { + proxy_http_version 1.1; + proxy_pass http://websocket; + proxy_set_header Connection $http_connection; + proxy_set_header Upgrade $http_upgrade; + } + } + + upstream websocket { + least_conn; + server unix:websockets-test_00.sock; + server unix:websockets-test_01.sock; + server unix:websockets-test_02.sock; + server unix:websockets-test_03.sock; + } +} diff --git a/testing/web-platform/tests/tools/third_party/websockets/example/deployment/nginx/supervisord.conf b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/nginx/supervisord.conf new file mode 100644 index 0000000000..76a664d91b --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/nginx/supervisord.conf @@ -0,0 +1,7 @@ +[supervisord] + +[program:websockets-test] +command = python app.py +process_name = %(program_name)s_%(process_num)02d +numprocs = 4 +autorestart = true diff --git a/testing/web-platform/tests/tools/third_party/websockets/example/deployment/render/app.py b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/render/app.py new file mode 100644 index 0000000000..4ca34d23bb --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/render/app.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python + +import asyncio +import http +import signal + +import websockets + + +async def echo(websocket): + async for message in websocket: + await websocket.send(message) + + +async def health_check(path, request_headers): + if path == "/healthz": + return http.HTTPStatus.OK, [], b"OK\n" + + +async def main(): + # Set the stop condition when receiving SIGTERM. + loop = asyncio.get_running_loop() + stop = loop.create_future() + loop.add_signal_handler(signal.SIGTERM, stop.set_result, None) + + async with websockets.serve( + echo, + host="", + port=8080, + process_request=health_check, + ): + await stop + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/testing/web-platform/tests/tools/third_party/websockets/example/deployment/render/requirements.txt b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/render/requirements.txt new file mode 100644 index 0000000000..14774b465e --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/render/requirements.txt @@ -0,0 +1 @@ +websockets diff --git a/testing/web-platform/tests/tools/third_party/websockets/example/deployment/supervisor/app.py b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/supervisor/app.py new file mode 100644 index 0000000000..bf61983ef7 --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/supervisor/app.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python + +import asyncio +import signal + +import websockets + + +async def echo(websocket): + async for message in websocket: + await websocket.send(message) + + +async def main(): + # Set the stop condition when receiving SIGTERM. + loop = asyncio.get_running_loop() + stop = loop.create_future() + loop.add_signal_handler(signal.SIGTERM, stop.set_result, None) + + async with websockets.serve( + echo, + host="", + port=8080, + reuse_port=True, + ): + await stop + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/testing/web-platform/tests/tools/third_party/websockets/example/deployment/supervisor/supervisord.conf b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/supervisor/supervisord.conf new file mode 100644 index 0000000000..76a664d91b --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/supervisor/supervisord.conf @@ -0,0 +1,7 @@ +[supervisord] + +[program:websockets-test] +command = python app.py +process_name = %(program_name)s_%(process_num)02d +numprocs = 4 +autorestart = true |