-
-
Notifications
You must be signed in to change notification settings - Fork 967
test(e2e): use local HTTP server instead of httpbin.org for tool-stub tests #6488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,35 +6,54 @@ | |||||||||||||||||||||||||
| # Disable GPG verification to avoid test failures | ||||||||||||||||||||||||||
| export MISE_GPG_VERIFY=false | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Find available port | ||||||||||||||||||||||||||
| find_available_port() { | ||||||||||||||||||||||||||
| python3 -c "import socket; s=socket.socket(); s.bind(('',0)); print(s.getsockname()[1]); s.close()" | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Start local HTTP test server | ||||||||||||||||||||||||||
| SERVER_PORT=$(find_available_port) | ||||||||||||||||||||||||||
| python3 "${TEST_ROOT}/helpers/scripts/tool_stub_test_server.py" "$SERVER_PORT" & | ||||||||||||||||||||||||||
| SERVER_PID=$! | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Wait for server to start | ||||||||||||||||||||||||||
| sleep 1 | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Ensure cleanup on exit | ||||||||||||||||||||||||||
| cleanup() { | ||||||||||||||||||||||||||
| kill "$SERVER_PID" 2>/dev/null || true | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| kill "$SERVER_PID" 2>/dev/null || true | |
| kill "$SERVER_PID" 2>/dev/null || true | |
| # Wait up to 5 seconds for process to terminate | |
| for i in {1..10}; do | |
| if ! kill -0 "$SERVER_PID" 2>/dev/null; then | |
| break | |
| fi | |
| sleep 0.5 | |
| done | |
| if kill -0 "$SERVER_PID" 2>/dev/null; then | |
| echo "Warning: server process $SERVER_PID did not terminate after kill" >&2 | |
| fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,65 @@ | ||||||
| #!/usr/bin/env python3 | ||||||
| """ | ||||||
| HTTP Test Server for tool-stub E2E Testing | ||||||
| Serves mock endpoints to avoid external network dependencies | ||||||
| """ | ||||||
|
|
||||||
| import http.server | ||||||
| import socketserver | ||||||
| import sys | ||||||
| import json | ||||||
| from pathlib import Path | ||||||
|
|
||||||
| class ToolStubTestHandler(http.server.SimpleHTTPRequestHandler): | ||||||
| def do_GET(self): | ||||||
| """Handle GET requests for test endpoints""" | ||||||
| if self.path == '/status/200': | ||||||
| self.send_response(200) | ||||||
| self.send_header('Content-Type', 'text/plain') | ||||||
| self.end_headers() | ||||||
| self.wfile.write(b'OK') | ||||||
| elif self.path == '/status/201': | ||||||
| self.send_response(201) | ||||||
| self.send_header('Content-Type', 'text/plain') | ||||||
| self.end_headers() | ||||||
| self.wfile.write(b'Created') | ||||||
| elif self.path == '/status/202': | ||||||
| self.send_response(202) | ||||||
| self.send_header('Content-Type', 'text/plain') | ||||||
| self.end_headers() | ||||||
| self.wfile.write(b'Accepted') | ||||||
| elif self.path == '/json': | ||||||
| self.send_response(200) | ||||||
| self.send_header('Content-Type', 'application/json') | ||||||
| self.end_headers() | ||||||
| content = json.dumps({ | ||||||
| "slideshow": { | ||||||
| "author": "Yours Truly", | ||||||
| "date": "date of publication", | ||||||
| "title": "Sample Slide Show" | ||||||
| } | ||||||
| }) | ||||||
| self.wfile.write(content.encode('utf-8')) | ||||||
| else: | ||||||
| # Return 404 for other paths | ||||||
| self.send_error(404, "File not found") | ||||||
|
|
||||||
| def log_message(self, format, *args): | ||||||
| """Suppress log messages for cleaner test output""" | ||||||
| pass | ||||||
|
|
||||||
| def start_server(port): | ||||||
| """Start the HTTP test server""" | ||||||
| with socketserver.TCPServer(("127.0.0.1", port), ToolStubTestHandler) as httpd: | ||||||
|
||||||
| with socketserver.TCPServer(("127.0.0.1", port), ToolStubTestHandler) as httpd: | |
| with socketserver.ThreadingTCPServer(("127.0.0.1", port), ToolStubTestHandler) as httpd: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fixed sleep duration may be unreliable on slower systems. Consider implementing a proper health check by attempting to connect to the server or checking for a specific response before proceeding with tests.