Skip to content

Commit 3b628a4

Browse files
authored
add more stream/future/resource tests (#175)
* switch examples to use Wasmtime 38 39 has not yet been released and is not needed for these examples, anyway. Signed-off-by: Joel Dice <joel.dice@fermyon.com> * add more stream/future/resource tests This addresses some gaps in the test coverage and fixes the issued uncovered (e.g. not handling drops of exported resources and not restoring payload ownership after a failed `future.write`). Signed-off-by: Joel Dice <joel.dice@fermyon.com> --------- Signed-off-by: Joel Dice <joel.dice@fermyon.com>
1 parent dbb80b6 commit 3b628a4

File tree

14 files changed

+343
-32
lines changed

14 files changed

+343
-32
lines changed

bundled/componentize_py_async_support/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ class _FutureState:
2626
handles: list[asyncio.Handle]
2727
pending_count: int
2828

29+
class _ReturnCode:
30+
COMPLETED = 0
31+
DROPPED = 1
32+
CANCELLED = 2
33+
2934
class _CallbackCode:
3035
EXIT = 0
3136
YIELD = 1

bundled/componentize_py_async_support/futures.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from typing import TypeVar, Generic, cast, Self, Any, Callable
66
from types import TracebackType
7+
from componentize_py_async_support import _ReturnCode
78

89
T = TypeVar('T')
910

@@ -13,7 +14,7 @@ def __init__(self, type_: int, handle: int):
1314
self.handle: int | None = handle
1415
self.finalizer = weakref.finalize(self, componentize_py_runtime.future_drop_readable, type_, handle)
1516

16-
async def read(self) -> T | None:
17+
async def read(self) -> T:
1718
self.finalizer.detach()
1819
handle = self.handle
1920
self.handle = None
@@ -57,15 +58,25 @@ def __init__(self, type_: int, handle: int, default: Callable[[], T]):
5758
self.default = default
5859
self.finalizer = weakref.finalize(self, write_default, type_, handle, default)
5960

60-
async def write(self, value: T) -> None:
61+
async def write(self, value: T) -> bool:
6162
self.finalizer.detach()
6263
handle = self.handle
6364
self.handle = None
6465
if handle is not None:
65-
await componentize_py_async_support.await_result(
66+
code, _ = await componentize_py_async_support.await_result(
6667
componentize_py_runtime.future_write(self.type_, handle, value)
6768
)
6869
componentize_py_runtime.future_drop_writable(self.type_, handle)
70+
match code:
71+
case _ReturnCode.COMPLETED:
72+
return True
73+
case _ReturnCode.DROPPED:
74+
return False
75+
case _ReturnCode.CANCELLED:
76+
# todo
77+
raise NotImplementedError
78+
case _:
79+
raise AssertionError
6980
else:
7081
raise AssertionError
7182

bundled/componentize_py_async_support/streams.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44

55
from typing import TypeVar, Generic, Self, cast
66
from types import TracebackType
7-
8-
class _ReturnCode:
9-
COMPLETED = 0
10-
DROPPED = 1
11-
CANCELLED = 2
7+
from componentize_py_async_support import _ReturnCode
128

139
class ByteStreamReader:
1410
def __init__(self, type_: int, handle: int):

bundled/componentize_py_runtime.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def promise_get_result(event: int, promise: int) -> Any: ...
1919

2020
def future_read(ty: int, future: int) -> Result[Any, tuple[int, int]]: ...
2121

22-
def future_write(ty: int, future: int, value: Any) -> Result[None, tuple[int, int]]: ...
22+
def future_write(ty: int, future: int, value: Any) -> Result[tuple[int, int], tuple[int, int]]: ...
2323

2424
def future_drop_readable(ty: int, future: int) -> None: ...
2525

examples/cli/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ run a Python-based component targetting the [wasi-cli] `command` world.
99

1010
## Prerequisites
1111

12-
* `Wasmtime` 39.0.0 or later
12+
* `Wasmtime` 38.0.0 or later
1313
* `componentize-py` 0.19.0
1414

1515
Below, we use [Rust](https://rustup.rs/)'s `cargo` to install `Wasmtime`. If
1616
you don't have `cargo`, you can download and install from
17-
https://github.com/bytecodealliance/wasmtime/releases/tag/v39.0.0.
17+
https://github.com/bytecodealliance/wasmtime/releases/tag/v38.0.0.
1818

1919
```
20-
cargo install --version 39.0.0 wasmtime-cli
20+
cargo install --version 38.0.0 wasmtime-cli
2121
pip install componentize-py==0.19.0
2222
```
2323

examples/http-p3/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ run a Python-based component targetting version `0.3.0-rc-2025-09-16` of the
1010

1111
## Prerequisites
1212

13-
* `Wasmtime` 39.0.0 or later
13+
* `Wasmtime` 38.0.0 or later
1414
* `componentize-py` 0.19.0
1515

1616
Below, we use [Rust](https://rustup.rs/)'s `cargo` to install `Wasmtime`. If
1717
you don't have `cargo`, you can download and install from
18-
https://github.com/bytecodealliance/wasmtime/releases/tag/v39.0.0.
18+
https://github.com/bytecodealliance/wasmtime/releases/tag/v38.0.0.
1919

2020
```
21-
cargo install --version 39.0.0 wasmtime-cli
21+
cargo install --version 38.0.0 wasmtime-cli
2222
pip install componentize-py==0.19.0
2323
```
2424

examples/http/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ run a Python-based component targetting the [wasi-http] `proxy` world.
99

1010
## Prerequisites
1111

12-
* `Wasmtime` 39.0.0 or later
12+
* `Wasmtime` 38.0.0 or later
1313
* `componentize-py` 0.19.0
1414

1515
Below, we use [Rust](https://rustup.rs/)'s `cargo` to install `Wasmtime`. If
1616
you don't have `cargo`, you can download and install from
17-
https://github.com/bytecodealliance/wasmtime/releases/tag/v39.0.0.
17+
https://github.com/bytecodealliance/wasmtime/releases/tag/v38.0.0.
1818

1919
```
20-
cargo install --version 39.0.0 wasmtime-cli
20+
cargo install --version 38.0.0 wasmtime-cli
2121
pip install componentize-py==0.19.0
2222
```
2323

examples/matrix-math/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ within a guest component.
1010

1111
## Prerequisites
1212

13-
* `wasmtime` 39.0.0 or later
13+
* `wasmtime` 38.0.0 or later
1414
* `componentize-py` 0.19.0
1515
* `NumPy`, built for WASI
1616

@@ -19,10 +19,10 @@ not yet publish WASI builds.
1919

2020
Below, we use [Rust](https://rustup.rs/)'s `cargo` to install `Wasmtime`. If
2121
you don't have `cargo`, you can download and install from
22-
https://github.com/bytecodealliance/wasmtime/releases/tag/v39.0.0.
22+
https://github.com/bytecodealliance/wasmtime/releases/tag/v38.0.0.
2323

2424
```
25-
cargo install --version 39.0.0 wasmtime-cli
25+
cargo install --version 38.0.0 wasmtime-cli
2626
pip install componentize-py==0.19.0
2727
curl -OL https://github.com/dicej/wasi-wheels/releases/download/v0.0.2/numpy-wasi.tar.gz
2828
tar xf numpy-wasi.tar.gz

examples/sandbox/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ sandboxed Python code snippets from within a Python app.
77

88
## Prerequisites
99

10-
* `wasmtime-py` 39.0.0 or later
10+
* `wasmtime-py` 38.0.0 or later
1111
* `componentize-py` 0.19.0
1212

1313
```
14-
pip install componentize-py==0.19.0 wasmtime==39.0.0
14+
pip install componentize-py==0.19.0 wasmtime==38.0.0
1515
```
1616

1717
## Running the demo

examples/tcp/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ making an outbound TCP request using `wasi-sockets`.
1010

1111
## Prerequisites
1212

13-
* `Wasmtime` 39.0.0 or later
13+
* `Wasmtime` 38.0.0 or later
1414
* `componentize-py` 0.19.0
1515

1616
Below, we use [Rust](https://rustup.rs/)'s `cargo` to install `Wasmtime`. If
1717
you don't have `cargo`, you can download and install from
18-
https://github.com/bytecodealliance/wasmtime/releases/tag/v39.0.0.
18+
https://github.com/bytecodealliance/wasmtime/releases/tag/v38.0.0.
1919

2020
```
21-
cargo install --version 39.0.0 wasmtime-cli
21+
cargo install --version 38.0.0 wasmtime-cli
2222
pip install componentize-py==0.19.0
2323
```
2424

0 commit comments

Comments
 (0)