Skip to content

Commit

Permalink
Attempt to fix RPC tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nkryuchkov committed Aug 28, 2019
1 parent 84a8777 commit 8b63241
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
33 changes: 28 additions & 5 deletions pkg/transport/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions pkg/visor/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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())
Expand All @@ -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{
Expand All @@ -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}
Expand Down

0 comments on commit 8b63241

Please sign in to comment.