Skip to content

Commit 6dce28f

Browse files
committed
Deal with the case when await_request() returns None
…indicating "there are no more requests this session". It's an `optional` in the WIT, though it never returned `None` before. I suspect multi-request is never happening anymore. Perhaps something changed in Viceroy, but this crash happens in Viceroy's `erik/python-sdk-compatible-2` and `main` (80c9e1486e5bbe559ec0194714bb668988984993). The crash happens *after* the request is served, so CI didn't catch it. It does now. Also add tests for Game Of Life.
1 parent d515dda commit 6dce28f

3 files changed

Lines changed: 53 additions & 3 deletions

File tree

examples/game-of-life.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ def decompressed_board(compressed: str) -> str:
4343

4444
@app.route("/board/<compressed_board>")
4545
def board(compressed_board: str):
46-
"""Return the next frame of the Game Of Life, given the current one. If a ""
47-
board is given, return a new random board.
48-
"""
46+
"""Return the next frame of the Game Of Life, given the current one. If "none"
47+
is given instead, return a new random board."""
4948
cells = decompressed_board(compressed_board)
5049

5150
# Random board on start:

fastly_compute/wsgi.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ def handle(self, request: Any, body: Any) -> None:
208208
# Something went wrong.
209209
raise
210210
else:
211+
if not result:
212+
break
211213
request, body = result
212214
serve_wsgi_request(
213215
request,

tests/test_game_of_life_example.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import re
2+
from time import sleep
3+
4+
from fastly_compute.testing import ViceroyTestBase
5+
6+
7+
class TestGameOfLife(ViceroyTestBase):
8+
"""Integration tests for the Game Of Life example"""
9+
10+
WASM_FILE = "build/game-of-life.composed.wasm"
11+
12+
def test_root(self):
13+
"""Show that the page full of JS at least loads."""
14+
response = self.get("/")
15+
assert response.status_code == 200
16+
assert "async function startAnimation" in response.text
17+
18+
def test_random_board(self):
19+
"""Show that random boards are generated for the first frame."""
20+
response = self.get("/board/none")
21+
assert response.status_code == 200
22+
assert re.match(r"[01]+", response.text)
23+
24+
def test_evolved_board(self):
25+
"""Show that a new board is correctly computed from an old one."""
26+
response = self.get(
27+
"/board/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAcAAAAAAAAAAAAAAAAEAAAAAAABAAAAAHAAQAAAAAAAAAAAAAAAcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAKAAAAAAAEgAAAAAAAwAADAAAAAAAN6AAAAAACscAAAAAAoOAGAAAAGACBgAAAAAAgAAAAAAAgAAAAAAAsAAAAAAAIAwAAAAAAgSAAAAAAAEgAAAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHAAAAAAAAQAAAAAAAOADAAAAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="
28+
)
29+
assert response.status_code == 200
30+
assert (
31+
response.text
32+
== "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000001210000000000000000000000000000000002000000000000000000000000000000000000000000000000010000000000010000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000202000000000000000000000000000000000000000000000020020000000000000000000000000000000000000000000000022000000000000000000010010000000000000000000000000000000000000000000231000300110000000000000000000000000000000000000003030001100020000000000000000000000000000000000000020300000200100000000033000000000000000000000000000032000000100000000000330000000000000000000000000000000000000000100000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000220000000000000000000000000000000000000000000000001100000022000000000000000000000000000000000000000000000002002000000000000000000000000000000000000000000000020020000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000003200000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000232000000000003300000000000000000000000000000000000100000000000033000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
33+
)
34+
35+
def test_reuse_sandboxes(self):
36+
"""Make sure attempting to issue multiple requests to a single sandbox doesn't crash.
37+
38+
This does not test whether a single sandbox actually served multiple
39+
requests; 2 sandboxes could have served 1 request each.
40+
"""
41+
response = self.get("/board/none")
42+
assert response.status_code == 200
43+
response = self.get("/board/none")
44+
assert response.status_code == 200
45+
46+
# The error about failed sandbox reuse comes *after* the request has
47+
# succeeded. And it seems to take forever to show up.
48+
sleep(4) # 2 is not enough. I am sad.
49+
assert "WebAssembly trapped" not in "\n".join(self.server.output_lines)

0 commit comments

Comments
 (0)