From 8b63241762813842d27f6953f335e06478645548 Mon Sep 17 00:00:00 2001 From: nkryuchkov Date: Wed, 28 Aug 2019 03:33:10 +0300 Subject: [PATCH] Attempt to fix RPC tests --- pkg/transport/mock.go | 33 ++++++++++++++++++++++++++++----- pkg/visor/rpc_test.go | 5 +++-- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/pkg/transport/mock.go b/pkg/transport/mock.go index 78fd209a60..57f3c62c09 100644 --- a/pkg/transport/mock.go +++ b/pkg/transport/mock.go @@ -7,7 +7,9 @@ import ( "net" "time" + "github.com/skycoin/dmsg" "github.com/skycoin/dmsg/cipher" + "github.com/skycoin/dmsg/disc" "github.com/skycoin/skywire/pkg/snet" ) @@ -179,13 +181,34 @@ func MockTransportManagersPair() (pk1, pk2 cipher.PubKey, m1, m2 *Manager, errCh mc1 := &ManagerConfig{PubKey: pk1, SecKey: sk1, DiscoveryClient: discovery, LogStore: logs} mc2 := &ManagerConfig{PubKey: pk2, SecKey: sk2, DiscoveryClient: discovery, LogStore: logs} - //f1, f2 := NewMockFactoryPair(pk1, pk2) + nc1 := snet.Config{PubKey: pk1, SecKey: sk1, TpNetworks: []string{snet.DmsgType}, DmsgMinSrvs: 1} + nc2 := snet.Config{PubKey: pk2, SecKey: sk2, TpNetworks: []string{snet.DmsgType}, DmsgMinSrvs: 1} - nc1 := snet.Config{PubKey: pk1, SecKey: sk1} - nc2 := snet.Config{PubKey: pk2, SecKey: sk2} + dmsgD := disc.NewMock() - net1 := snet.New(nc1) - net2 := snet.New(nc2) + if err = dmsgD.SetEntry(context.TODO(), disc.NewClientEntry(pk1, 0, []cipher.PubKey{})); err != nil { + return + } + + // l, err := nettest.NewLocalListener("tcp") + // if err != nil { + // return + // } + // srv, err := dmsg.NewServer(pk1, sk1, "", l, dmsgD) + // if err != nil { + // return + // } + // + // go func() { + // errCh <- srv.Serve() + // close(errCh) + // }() + + dmsgC1 := dmsg.NewClient(pk1, sk1, dmsgD) + dmsgC2 := dmsg.NewClient(pk2, sk2, dmsgD) + + net1 := snet.NewRaw(nc1, dmsgC1) + net2 := snet.NewRaw(nc2, dmsgC2) if m1, err = NewManager(net1, mc1); err != nil { return diff --git a/pkg/visor/rpc_test.go b/pkg/visor/rpc_test.go index 9472d4f361..beb146814e 100644 --- a/pkg/visor/rpc_test.go +++ b/pkg/visor/rpc_test.go @@ -15,6 +15,7 @@ import ( "github.com/stretchr/testify/require" "github.com/skycoin/skywire/pkg/routing" + "github.com/skycoin/skywire/pkg/snet" "github.com/skycoin/skywire/pkg/transport" "github.com/skycoin/skywire/pkg/util/pathutil" ) @@ -103,6 +104,7 @@ func TestRPC(t *testing.T) { }() pk1, _, tm1, tm2, errCh, err := transport.MockTransportManagersPair() + require.NoError(t, err) defer func() { require.NoError(t, tm1.Close()) @@ -111,7 +113,7 @@ func TestRPC(t *testing.T) { require.NoError(t, <-errCh) }() - _, err = tm2.SaveTransport(context.TODO(), pk1, "mock") + _, err = tm2.SaveTransport(context.TODO(), pk1, snet.DmsgType) require.NoError(t, err) apps := []AppConfig{ @@ -138,7 +140,6 @@ func TestRPC(t *testing.T) { }() require.NoError(t, node.StartApp("foo")) - require.NoError(t, node.StartApp("bar")) time.Sleep(time.Second) gateway := &RPC{node: node}