Skip to content

Commit

Permalink
Add test for listener's (de)registration of stream handlers.
Browse files Browse the repository at this point in the history
  • Loading branch information
lthibault committed May 25, 2024
1 parent 8693d09 commit 843faf9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
31 changes: 28 additions & 3 deletions vat/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/wetware/go/vat"
)

func TestListener(t *testing.T) {
func TestStreamHandler(t *testing.T) {
t.Parallel()

ctrl := gomock.NewController(t)
Expand All @@ -23,12 +23,14 @@ func TestListener(t *testing.T) {
defer cancel()

c := test_libp2p.NewMockConn(ctrl)
c.EXPECT().RemotePeer().
c.EXPECT().
RemotePeer().
Return(peer.ID("test")).
Times(1)

s := test_libp2p.NewMockStream(ctrl)
s.EXPECT().Conn().
s.EXPECT().
Conn().
Return(c).
Times(1)
s.EXPECT().ID().
Expand All @@ -46,6 +48,29 @@ func TestListener(t *testing.T) {
require.NoError(t, err)
}

func TestListener(t *testing.T) {
t.Parallel()

ctrl := gomock.NewController(t)
defer ctrl.Finish()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

proto := vat.ProtoFromRoot("test")

h := test_libp2p.NewMockHost(ctrl)
h.EXPECT().
SetStreamHandler(proto, gomock.Any()).
Times(1)
h.EXPECT().
RemoveStreamHandler(proto).
Times(1)

l := vat.ListenConfig{Host: h}.Listen(ctx, proto)
defer l.Release() // calls h.RemoveStreamHandler
}

// func TestXXX(t *testing.T) {
// t.Parallel()

Expand Down
8 changes: 6 additions & 2 deletions vat/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import (
"github.com/tetratelabs/wazero/api"
)

func ProtoFromModule(mod api.Module) protocol.ID {
path := filepath.Join(Proto, mod.Name())
func ProtoFromRoot(path string) protocol.ID {
path = filepath.Join(Proto, path)
return protocol.ID(path)
}

func ProtoFromModule(mod api.Module) protocol.ID {
return ProtoFromRoot(mod.Name())
}

0 comments on commit 843faf9

Please sign in to comment.