|
1 | | -if RUBY_VERSION.start_with?("3.") |
2 | | - RSpec.describe "Ractor" do |
3 | | - let(:wat) { <<~WAT } |
4 | | - (module |
5 | | - (func $module/hello (result i32 i64 f32 f64) |
6 | | - i32.const 1 |
7 | | - i64.const 2 |
8 | | - f32.const 3.0 |
9 | | - f64.const 4.0 |
10 | | - ) |
11 | | -
|
12 | | - (export "hello" (func $module/hello)) |
| 1 | +RSpec.describe "Ractor", ractor: true do |
| 2 | + let(:wat) { <<~WAT } |
| 3 | + (module |
| 4 | + (func $module/hello (result i32 i64 f32 f64) |
| 5 | + i32.const 1 |
| 6 | + i64.const 2 |
| 7 | + f32.const 3.0 |
| 8 | + f64.const 4.0 |
13 | 9 | ) |
14 | | - WAT |
15 | | - |
16 | | - it "supports running inside Ractors" do |
17 | | - r = Ractor.new(wat) do |wat| |
18 | | - engine = Wasmtime::Engine.new |
19 | | - mod = Wasmtime::Module.new(engine, wat) |
20 | | - store_data = Object.new |
21 | | - store = Wasmtime::Store.new(engine, store_data) |
22 | | - Wasmtime::Instance.new(store, mod).invoke("hello") |
23 | | - end |
24 | 10 |
|
25 | | - result = r.take |
26 | | - expect(result).to eq([1, 2, 3.0, 4.0]) |
27 | | - end |
| 11 | + (export "hello" (func $module/hello)) |
| 12 | + ) |
| 13 | + WAT |
28 | 14 |
|
29 | | - it "supports sharing Engine & Module with Ractors" do |
| 15 | + it "supports running inside Ractors" do |
| 16 | + r = Ractor.new(wat) do |wat| |
30 | 17 | engine = Wasmtime::Engine.new |
31 | 18 | mod = Wasmtime::Module.new(engine, wat) |
| 19 | + store_data = Object.new |
| 20 | + store = Wasmtime::Store.new(engine, store_data) |
| 21 | + Wasmtime::Instance.new(store, mod).invoke("hello") |
| 22 | + end |
32 | 23 |
|
33 | | - Ractor.make_shareable(engine) |
34 | | - Ractor.make_shareable(mod) |
| 24 | + result = r.take |
| 25 | + expect(result).to eq([1, 2, 3.0, 4.0]) |
| 26 | + end |
35 | 27 |
|
36 | | - ractors = [] |
37 | | - 3.times do |
38 | | - ractors << Ractor.new(engine, mod) do |engine, mod| |
39 | | - store_data = Object.new |
40 | | - store = Wasmtime::Store.new(engine, store_data) |
41 | | - Wasmtime::Instance.new(store, mod).invoke("hello") |
42 | | - end |
43 | | - end |
| 28 | + it "supports sharing Engine & Module with Ractors" do |
| 29 | + engine = Wasmtime::Engine.new |
| 30 | + mod = Wasmtime::Module.new(engine, wat) |
44 | 31 |
|
45 | | - ractors.each do |ractor| |
46 | | - expect(ractor.take).to eq([1, 2, 3.0, 4.0]) |
| 32 | + Ractor.make_shareable(engine) |
| 33 | + Ractor.make_shareable(mod) |
| 34 | + |
| 35 | + ractors = [] |
| 36 | + 3.times do |
| 37 | + ractors << Ractor.new(engine, mod) do |engine, mod| |
| 38 | + store_data = Object.new |
| 39 | + store = Wasmtime::Store.new(engine, store_data) |
| 40 | + Wasmtime::Instance.new(store, mod).invoke("hello") |
47 | 41 | end |
48 | 42 | end |
| 43 | + |
| 44 | + ractors.each do |ractor| |
| 45 | + expect(ractor.take).to eq([1, 2, 3.0, 4.0]) |
| 46 | + end |
49 | 47 | end |
50 | 48 | end |
0 commit comments