Skip to content

Commit

Permalink
Fix tests that are not commented out
Browse files Browse the repository at this point in the history
  • Loading branch information
nkryuchkov committed Dec 12, 2019
1 parent f26e2fd commit 29ed1d4
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
2 changes: 2 additions & 0 deletions pkg/app/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func TestListener_Accept(t *testing.T) {
rpc.On("Accept", acceptConnID).Return(acceptConnID, acceptRemote, acceptErr)

lis := &Listener{
log: l,
id: lisID,
rpc: rpc,
addr: local,
Expand Down Expand Up @@ -143,6 +144,7 @@ func TestListener_Accept(t *testing.T) {
rpc.On("Accept", lisID).Return(acceptConnID, acceptRemote, acceptErr)

lis := &Listener{
log: l,
id: lisID,
rpc: rpc,
addr: local,
Expand Down
6 changes: 5 additions & 1 deletion pkg/router/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ func Test_router_AcceptRoutes(t *testing.T) {
require.Equal(t, []routing.Rule{fwdRule}, rg.fwd)
require.Equal(t, []routing.Rule{cnsmRule}, rg.rvs)
require.Len(t, rg.tps, 1)
require.Equal(t, []routing.Rule{fwdRule, cnsmRule}, rg.rt.AllRules())

allRules := rg.rt.AllRules()
assert.Len(t, allRules, 2)
assert.Contains(t, allRules, fwdRule)
assert.Contains(t, allRules, cnsmRule)
}

// Ensure that received packets are handled properly in `(*Router).Serve()`.
Expand Down
11 changes: 8 additions & 3 deletions pkg/router/rpc_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,19 @@ func TestRPCGateway_AddEdgeRules(t *testing.T) {

var ok bool
err := gateway.AddEdgeRules(rules, &ok)
require.Equal(t, testhelpers.Err, err)

wantErr := routing.Failure{
Code: routing.FailureAddRules,
Msg: testhelpers.Err.Error(),
}

require.Equal(t, wantErr, err)
require.False(t, ok)
})

t.Run("fail saving rules", func(t *testing.T) {
r := &MockRouter{}
r.On("IntroduceRules", rules).Return(testhelpers.NoErr)
r.On("SaveRoutingRules", rules.Forward, rules.Reverse).Return(testhelpers.Err)
r.On("IntroduceRules", rules).Return(testhelpers.Err)

gateway := NewRPCGateway(r)

Expand Down
12 changes: 8 additions & 4 deletions pkg/snet/snettest/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,14 @@ func NewEnv(t *testing.T, keys []KeyPair, networks []string) *Env {
dmsgD := disc.NewMock()
dmsgS, dmsgSErr := createDmsgSrv(t, dmsgD)

table := stcp.NewTable(map[cipher.PubKey]string{
keys[0].PK: "127.0.0.1:7033",
keys[1].PK: "127.0.0.1:7034",
})
const baseSTCPPort = 7033

tableEntries := make(map[cipher.PubKey]string)
for i, pair := range keys {
tableEntries[pair.PK] = "127.0.0.1:" + strconv.Itoa(baseSTCPPort+i)
}

table := stcp.NewTable(tableEntries)

var hasDmsg, hasStcp bool

Expand Down
18 changes: 17 additions & 1 deletion pkg/visor/rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/SkycoinProject/skywire-mainnet/pkg/app"
"github.com/SkycoinProject/skywire-mainnet/pkg/router"
"github.com/SkycoinProject/skywire-mainnet/pkg/snet/snettest"

"github.com/SkycoinProject/dmsg/cipher"
"github.com/SkycoinProject/skycoin/src/util/logging"
Expand Down Expand Up @@ -252,39 +253,53 @@ func NewMockRPCClient(r *rand.Rand, maxTps int, maxRules int) (cipher.PubKey, RP
}
log.Infof("tp[%2d]: %v", i, tps[i])
}

rt := routing.NewTable(routing.DefaultConfig())
ruleKeepAlive := router.DefaultRouteKeepAlive

for i := 0; i < r.Intn(maxRules+1); i++ {
remotePK, _ := cipher.GenerateKeyPair()
var lpRaw, rpRaw [2]byte

if _, err := r.Read(lpRaw[:]); err != nil {
return cipher.PubKey{}, nil, err
}

if _, err := r.Read(rpRaw[:]); err != nil {
return cipher.PubKey{}, nil, err
}

lp := routing.Port(binary.BigEndian.Uint16(lpRaw[:]))
rp := routing.Port(binary.BigEndian.Uint16(rpRaw[:]))

fwdRID, err := rt.ReserveKeys(1)
if err != nil {
panic(err)
}
fwdRule := routing.IntermediaryForwardRule(ruleKeepAlive, fwdRID[0], routing.RouteID(r.Uint32()), uuid.New())

keys := snettest.GenKeyPairs(2)

fwdRule := routing.ForwardRule(ruleKeepAlive, fwdRID[0], routing.RouteID(r.Uint32()), uuid.New(), keys[0].PK, keys[1].PK, 0, 0)
if err := rt.SaveRule(fwdRule); err != nil {
panic(err)
}

appRID, err := rt.ReserveKeys(1)
if err != nil {
panic(err)
}

consumeRule := routing.ConsumeRule(ruleKeepAlive, appRID[0], localPK, remotePK, lp, rp)
if err := rt.SaveRule(consumeRule); err != nil {
panic(err)
}

log.Infof("rt[%2da]: %v %v", i, fwdRID, fwdRule.Summary().ForwardFields)
log.Infof("rt[%2db]: %v %v", i, appRID[0], consumeRule.Summary().ConsumeFields)
}

log.Printf("rtCount: %d", rt.Count())

client := &mockRPCClient{
s: &Summary{
PubKey: localPK,
Expand All @@ -301,6 +316,7 @@ func NewMockRPCClient(r *rand.Rand, maxTps int, maxRules int) (cipher.PubKey, RP
rt: rt,
startedAt: time.Now(),
}

return localPK, client, nil
}

Expand Down

0 comments on commit 29ed1d4

Please sign in to comment.