|
| 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