Skip to content

Commit c239fcc

Browse files
committed
Cleanup app and tests
A lot of the extra stuff we had for logging exceptions and such aren't required any longer as the WASI bits are working as they ought to, so we can gut all of that. Also, fixed vcpu_time which does return an integer number of milliseconds in the viceroy impl, so assert on that.
1 parent 0474116 commit c239fcc

2 files changed

Lines changed: 4 additions & 62 deletions

File tree

app.py

Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
from bottle import Bottle
44
from wit_world.exports import HttpIncoming as BaseHttpIncoming
5-
from wit_world.imports import http_body, http_resp, log
5+
from wit_world.imports import compute_runtime, http_body, http_resp, log
66
from wit_world.imports.http_resp import send_downstream
77

88
# Enable a bit more debug logging from the framework.
99
app = Bottle()
10-
app.catchall = False # bottle backtrace causes issues; use our own.
1110

1211

1312
@app.route("/hello/<name>")
@@ -21,13 +20,7 @@ def info():
2120
from bottle import request
2221

2322
# Get some runtime info we can test
24-
vcpu_time = None
25-
try:
26-
from wit_world.imports import compute_runtime
27-
28-
vcpu_time = compute_runtime.get_vcpu_ms()
29-
except Exception:
30-
pass
23+
vcpu_time = compute_runtime.get_vcpu_ms()
3124

3225
return {
3326
"service": "fastly-compute-python",
@@ -39,18 +32,6 @@ def info():
3932
}
4033

4134

42-
def print(*args):
43-
# hack to allow print locally; so far, monkeypatching
44-
# sys.stdout/sys.stderr hasn't panned out, so more
45-
# research required.
46-
log_ep.write(" ".join(args).encode())
47-
48-
49-
def init():
50-
global log_ep
51-
log_ep = log.Endpoint.get("")
52-
53-
5435
class StdErr:
5536
"""File-like object to receive errors and direct them to our logging endpoint"""
5637

@@ -98,33 +79,4 @@ def start_response(status: str, headers: list[tuple], exc_info=None):
9879

9980
class HttpIncoming(BaseHttpIncoming):
10081
def handle(self, request, body):
101-
init()
102-
try:
103-
serve_wsgi_request(request, body, app)
104-
except Exception as e:
105-
log_exception(e)
106-
107-
108-
def log_exception(e):
109-
"""Pretty-print an exception to our logging endpoint.
110-
111-
Do it without callling format_exc(), which calls stat() to determine whether
112-
we're in a tty and what its width is. stat() and other fd routines currently
113-
crash when they try to access stdout or stderr, probably because they are
114-
not in the preopens.
115-
"""
116-
try:
117-
print(f"Exception {type(e).__name__} - {e}")
118-
print("--- Traceback Follows ---")
119-
120-
current_tb = e.__traceback__
121-
while current_tb:
122-
frame = current_tb.tb_frame
123-
print(
124-
f" File: {frame.f_code.co_filename}, "
125-
f"Function: {frame.f_code.co_name}, "
126-
f"Line: {frame.f_lineno}"
127-
)
128-
current_tb = current_tb.tb_next
129-
except Exception as e2:
130-
print(f"print_exc failed {e2}")
82+
serve_wsgi_request(request, body, app)

tests/test_integration.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def test_info_endpoint(self, viceroy_server):
161161

162162
# Check WIT API data
163163
assert "vcpu_time_ms" in data
164-
assert isinstance(data["vcpu_time_ms"], int | type(None))
164+
assert isinstance(data["vcpu_time_ms"], int)
165165

166166
# Check request data
167167
assert data["request_method"] == "GET"
@@ -172,13 +172,3 @@ def test_nonexistent_endpoint(self, viceroy_server):
172172
response = self._get("/nonexistent", viceroy_server)
173173

174174
assert response.status_code == 404
175-
176-
def test_service_health(self, viceroy_server):
177-
"""Test that the service is healthy and responsive."""
178-
# Make multiple requests to ensure stability
179-
for _ in range(3):
180-
response = self._get("/info", viceroy_server)
181-
assert response.status_code == 200
182-
183-
data = response.json()
184-
assert data["status"] == "ok"

0 commit comments

Comments
 (0)