forked from wapc/wapc-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pool_test.go
43 lines (33 loc) · 942 Bytes
/
pool_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package wapc_test
import (
"context"
"io/ioutil"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/wapc/wapc-go"
)
func TestPool(t *testing.T) {
ctx := context.Background()
code, err := ioutil.ReadFile("testdata/hello.wasm")
require.NoError(t, err)
hostCall := func(ctx context.Context, binding, namespace, operation string, payload []byte) ([]byte, error) {
return []byte("test"), nil
}
module, err := wapc.New(code, hostCall)
require.NoError(t, err)
defer module.Close()
pool, err := wapc.NewPool(module, 10)
require.NoError(t, err)
defer pool.Close()
for i := 0; i < 100; i++ {
instance, err := pool.Get(10 * time.Millisecond)
require.NoError(t, err)
result, err := instance.Invoke(ctx, "hello", []byte("waPC"))
require.NoError(t, err)
assert.Equal(t, "Hello, waPC", string(result))
err = pool.Return(instance)
require.NoError(t, err)
}
}