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"
16
var WasmProtocol types.ProtocolName = "wasm-bolt" // protocol
18
type wasmXExtendCase struct {
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))},
28
for i, tc := range testCases {
29
t.Logf("start wasm case #%d\n", i)
35
t.Errorf("[ERROR MESSAGE] #%d wasm tcp proxy test failed, protocol: %s, error: %v\n", i, tc.SubProtocol, err)
37
case <-time.After(15 * time.Second):
38
t.Errorf("[ERROR MESSAGE] #%d wasm tcp proxy hang, protocol: %s\n", i, tc.SubProtocol)
44
func (c *wasmXExtendCase) Start(tls bool) {
46
appAddr := c.AppServer.Addr()
47
clientMeshAddr := testutil.CurrentMeshAddr()
48
c.ClientMeshAddr = clientMeshAddr
49
serverMeshAddr := testutil.CurrentMeshAddr()
50
c.ServerMeshAddr = serverMeshAddr
53
cfg := testutil.CreateMeshToMeshConfigWithSub(clientMeshAddr, serverMeshAddr, protocol.Auto, protocol.Auto, WasmProtocol, []string{appAddr}, tls)
54
// insert wasm plugin config
55
c.injectWasmConfig(cfg)
57
mesh := mosn.NewMosn(cfg)
65
time.Sleep(5 * time.Second) //wait server and mesh start
68
func (c *wasmXExtendCase) injectWasmConfig(cfg *v2.MOSNConfig) {
69
cfg.Wasms = []v2.WasmPluginConfig{
71
PluginName: "wasm-bolt-plugin",
72
VmConfig: &v2.WasmVmConfig{
74
Path: "../../etc/wasm/bolt-go.wasm",
78
cfg.ThirdPartCodec = v2.ThirdPartCodecConfig{
79
Codecs: []v2.ThirdPartCodec{
83
Config: map[string]interface{}{
84
"from_wasm_plugin": "wasm-bolt-plugin",
85
"protocol": string(WasmProtocol),