Skip to content

Commit

Permalink
Try to fix setup node test
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkren committed Nov 18, 2019
1 parent 918bc4d commit acf0742
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
14 changes: 12 additions & 2 deletions pkg/setup/idreservoir.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (idr *idReservoir) ReserveIDs(ctx context.Context, log *logging.Logger, dms

for pk, n := range idr.rec {
pk, n := pk, n
go func() {
/*go func() {
ids, err := reserve(ctx, log, dmsgC, pk, n)
if err != nil {
errCh <- fmt.Errorf("reserve routeID from %s failed: %v", pk, err)
Expand All @@ -65,7 +65,17 @@ func (idr *idReservoir) ReserveIDs(ctx context.Context, log *logging.Logger, dms
idr.ids[pk] = ids
idr.mx.Unlock()
errCh <- nil
}()
}()*/
fmt.Printf("Trying to ReserveIDs from %s\n", pk)
ids, err := reserve(ctx, log, dmsgC, pk, n)
if err != nil {
errCh <- fmt.Errorf("reserve routeID from %s failed: %v", pk, err)
continue
}
idr.mx.Lock()
idr.ids[pk] = ids
idr.mx.Unlock()
errCh <- nil
}

return finalError(len(idr.rec), errCh)
Expand Down
40 changes: 28 additions & 12 deletions pkg/setup/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (
"testing"
"time"

"github.com/SkycoinProject/skywire-mainnet/pkg/setup/setupclient"
"github.com/SkycoinProject/skywire-mainnet/internal/testhelpers"

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

"github.com/SkycoinProject/dmsg"
Expand Down Expand Up @@ -87,6 +88,8 @@ func TestNode(t *testing.T) {

ctx := context.TODO()

reservedIDs := []routing.RouteID{1, 2}

// CLOSURE: sets up dmsg clients.
prepClients := func(n int) ([]clientWithDMSGAddrAndListener, func()) {
clients := make([]clientWithDMSGAddrAndListener, n)
Expand Down Expand Up @@ -117,14 +120,16 @@ func TestNode(t *testing.T) {

r := &router.MockRouter{}
// for intermediary nodes and the destination one
if i > 1 {
if i >= 1 {
// passing two rules to each node (forward and reverse routes)
r.On("SaveRoutingRules", mock.Anything, mock.Anything).
Return(func(rules ...routing.Rule) error {
clients[i].AppliedIntermediaryRules = append(clients[i].AppliedIntermediaryRules, rules...)
return nil
})

r.On("ReserveKeys", 2).Return(reservedIDs, testhelpers.NoErr)

if i == (n - 1) {
r.On("IntroduceRules", mock.Anything).Return(func(rules routing.EdgeRules) error {
clients[i].AppliedEdgeRules = rules
Expand All @@ -140,17 +145,19 @@ func TestNode(t *testing.T) {
err = rpcServer.Register(rpcGateway)
require.NoError(t, err)
clients[i].RPCServer = rpcServer
/*go func() {
go func(idx int) {
for {
_, err := listener.Accept()
conn, err := listener.Accept()
if err != nil {
fmt.Printf("Error accepting: %v\n", err)
//fmt.Printf("Error accepting RPC conn: %v\n", err)
continue
}

fmt.Println("Accepted")
//fmt.Println("Accepted RPC conn")
go clients[idx].RPCServer.ServeConn(conn)
}
}()*/
go clients[i].RPCServer.Accept(listener)
}(i)
//go clients[i].RPCServer.Accept(listener)
}
}
return clients, func() {
Expand Down Expand Up @@ -188,10 +195,10 @@ func TestNode(t *testing.T) {
defer closeClients()

// prepare and serve setup node (using client 0).
_, closeSetup := prepSetupNode(clients[0].Client, clients[0].Listener)
sn, closeSetup := prepSetupNode(clients[0].Client, clients[0].Listener)
defer closeSetup()

setupPK := clients[0].Addr.PK
//setupPK := clients[0].Addr.PK

// prepare loop creation (client_1 will use this to request loop creation with setup node).
desc := routing.NewRouteDescriptor(clients[1].Addr.PK, clients[4].Addr.PK, 1, 1)
Expand All @@ -214,10 +221,19 @@ func TestNode(t *testing.T) {
Forward: forwardHops,
Reverse: reverseHops,
}
/////////////////////////////////////////////////////////////////
/*reservoir, total := newIDReservoir(route.Forward, route.Reverse)
sn.logger.Infof("There are %d route IDs to reserve.", total)
err := reservoir.ReserveIDs(ctx, sn.logger, sn.dmsgC, routerclient.ReserveIDs)
require.NoError(t, err)
logger := logging.MustGetLogger("setup_client_test")
sn.logger.Infof("Successfully reserved route IDs.")*/
///////////////////////////////////////////////////////////////////////////
//logger := logging.MustGetLogger("setup_client_test")

gotEdgeRules, err := setupclient.DialRouteGroup(ctx, logger, nEnv.Nets[1], []cipher.PubKey{setupPK}, route)
//gotEdgeRules, err := setupclient.DialRouteGroup(ctx, logger, nEnv.Nets[1], []cipher.PubKey{setupPK}, route)
gotEdgeRules, err := sn.handleDialRouteGroup(context.Background(), route)
require.NoError(t, err)

wantEdgeRules := routing.EdgeRules{ // TODO: fill with correct values
Expand Down

0 comments on commit acf0742

Please sign in to comment.