mosn

Форк
0
/
wasmproxy_test.go 
91 строка · 2.3 Кб
1
package integrate
2

3
import (
4
	"testing"
5
	"time"
6

7
	v2 "mosn.io/mosn/pkg/config/v2"
8
	"mosn.io/mosn/pkg/protocol"
9
	"mosn.io/mosn/pkg/protocol/xprotocol/bolt"
10
	"mosn.io/mosn/pkg/types"
11
	_ "mosn.io/mosn/pkg/wasm/runtime/wazero"
12
	testutil "mosn.io/mosn/test/util"
13
	"mosn.io/mosn/test/util/mosn"
14
)
15

16
var WasmProtocol types.ProtocolName = "wasm-bolt" // protocol
17

18
type wasmXExtendCase struct {
19
	*XTestCase
20
}
21

22
func TestWasmProtocolProxy(t *testing.T) {
23
	appAddr := "127.0.0.1:30999"
24
	testCases := []*wasmXExtendCase{
25
		// bolt client -> wasm bolt client -> wasm bolt server -> bolt server
26
		{NewXTestCase(t, bolt.ProtocolName, testutil.NewRPCServer(t, appAddr, bolt.ProtocolName))},
27
	}
28
	for i, tc := range testCases {
29
		t.Logf("start wasm case #%d\n", i)
30
		tc.Start(false)
31
		go tc.RunCase(1, 0)
32
		select {
33
		case err := <-tc.C:
34
			if err != nil {
35
				t.Errorf("[ERROR MESSAGE] #%d wasm tcp proxy test failed, protocol: %s, error: %v\n", i, tc.SubProtocol, err)
36
			}
37
		case <-time.After(15 * time.Second):
38
			t.Errorf("[ERROR MESSAGE] #%d wasm tcp proxy hang, protocol: %s\n", i, tc.SubProtocol)
39
		}
40
		tc.FinishCase()
41
	}
42
}
43

44
func (c *wasmXExtendCase) Start(tls bool) {
45
	c.AppServer.GoServe()
46
	appAddr := c.AppServer.Addr()
47
	clientMeshAddr := testutil.CurrentMeshAddr()
48
	c.ClientMeshAddr = clientMeshAddr
49
	serverMeshAddr := testutil.CurrentMeshAddr()
50
	c.ServerMeshAddr = serverMeshAddr
51

52
	// proxy to wasm
53
	cfg := testutil.CreateMeshToMeshConfigWithSub(clientMeshAddr, serverMeshAddr, protocol.Auto, protocol.Auto, WasmProtocol, []string{appAddr}, tls)
54
	// insert wasm plugin config
55
	c.injectWasmConfig(cfg)
56

57
	mesh := mosn.NewMosn(cfg)
58
	go mesh.Start()
59
	go func() {
60
		<-c.Finish
61
		c.AppServer.Close()
62
		mesh.Close()
63
		c.Finish <- true
64
	}()
65
	time.Sleep(5 * time.Second) //wait server and mesh start
66
}
67

68
func (c *wasmXExtendCase) injectWasmConfig(cfg *v2.MOSNConfig) {
69
	cfg.Wasms = []v2.WasmPluginConfig{
70
		{
71
			PluginName: "wasm-bolt-plugin",
72
			VmConfig: &v2.WasmVmConfig{
73
				Engine: "wasmer",
74
				Path:   "../../etc/wasm/bolt-go.wasm",
75
			},
76
		},
77
	}
78
	cfg.ThirdPartCodec = v2.ThirdPartCodecConfig{
79
		Codecs: []v2.ThirdPartCodec{
80
			{
81
				Enable: true,
82
				Type:   v2.Wasm,
83
				Config: map[string]interface{}{
84
					"from_wasm_plugin": "wasm-bolt-plugin",
85
					"protocol":         string(WasmProtocol),
86
					"root_id":          1,
87
				},
88
			},
89
		},
90
	}
91
}
92

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.