Skip to content

Commit

Permalink
Merge branch 'mainnet-milestone1' into bug/fix-tests
Browse files Browse the repository at this point in the history
# Conflicts:
#	pkg/setup/node_test.go
  • Loading branch information
nkryuchkov committed Sep 3, 2019
2 parents cc9ca84 + dc8ce92 commit c924b6e
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions pkg/setup/node_test.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
package setup

import (
"context"
"encoding/json"
"errors"
"fmt"
"log"
"os"
"sync"
"sync/atomic"
"testing"
"time"

"github.com/google/uuid"
"github.com/skycoin/dmsg"
"github.com/skycoin/dmsg/cipher"
"github.com/skycoin/dmsg/disc"
"github.com/skycoin/skycoin/src/util/logging"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/net/nettest"

"github.com/skycoin/skywire/pkg/metrics"
"github.com/skycoin/skywire/pkg/routing"
"github.com/skycoin/skywire/pkg/snet"
)

func TestMain(m *testing.M) {
Expand All @@ -41,7 +30,22 @@ func TestMain(m *testing.M) {
os.Exit(m.Run())
}

func TestNode(t *testing.T) {
// TODO(Darkren): fix this test. Explanation below
// Test may finish in 3 different ways:
// 1. Pass
// 2. Fail
// 3. Hang
// Adding `time.Sleep` at the start of `Write` operation in the DMSG makes it less possible to hang
// From observations seems like something's wrong in the DMSG, probably writing right after `Dial/Accept`
// causes this.
// 1. Test has possibility to pass, this means the test itself is correct
// 2. Test failure always comes with unexpected `context deadline exceeded`. In `read` operation of
// `setup proto` we ensure additional timeout, that's where this error comes from. This fact proves that
// DMSG has a related bug
// 3. Hanging may be not the problem of the DMSG. Probably some of the communication part here is wrong.
// The reason I think so is that - if we ensure read timeouts, why doesn't this test constantly fail?
// Maybe some wrapper for DMSG is wrong, or some internal operations before the actual communication behave bad
/*func TestNode(t *testing.T) {
// Prepare mock dmsg discovery.
discovery := disc.NewMock()
Expand Down Expand Up @@ -162,53 +166,53 @@ func TestNode(t *testing.T) {
// CLOSURE: emulates how a visor node should react when expecting an AddRules packet.
expectAddRules := func(client int, expRule routing.RuleType) {
conn, err := clients[client].Listener.Accept()
assert.NoError(t, err)
require.NoError(t, err)
fmt.Printf("client %v:%v accepted\n", client, clients[client].Addr)
proto := NewSetupProtocol(conn)
pt, _, err := proto.ReadPacket()
assert.NoError(t, err)
assert.Equal(t, PacketRequestRouteID, pt)
require.NoError(t, err)
require.Equal(t, PacketRequestRouteID, pt)
fmt.Printf("client %v:%v got PacketRequestRouteID\n", client, clients[client].Addr)
routeID := atomic.AddUint32(&nextRouteID, 1)
err = proto.WritePacket(RespSuccess, []routing.RouteID{routing.RouteID(routeID)})
assert.NoError(t, err)
require.NoError(t, err)
fmt.Printf("client %v:%v responded to with registration ID: %v\n", client, clients[client].Addr, routeID)
assert.NoError(t, conn.Close())
require.NoError(t, conn.Close())
conn, err = clients[client].Listener.Accept()
assert.NoError(t, err)
require.NoError(t, err)
fmt.Printf("client %v:%v accepted 2nd time\n", client, clients[client].Addr)
proto = NewSetupProtocol(conn)
pt, pp, err := proto.ReadPacket()
assert.NoError(t, err)
assert.Equal(t, PacketAddRules, pt)
require.NoError(t, err)
require.Equal(t, PacketAddRules, pt)
fmt.Printf("client %v:%v got PacketAddRules\n", client, clients[client].Addr)
var rs []routing.Rule
assert.NoError(t, json.Unmarshal(pp, &rs))
require.NoError(t, json.Unmarshal(pp, &rs))
for _, r := range rs {
assert.Equal(t, expRule, r.Type())
require.Equal(t, expRule, r.Type())
}
// TODO: This error is not checked due to a bug in dmsg.
_ = proto.WritePacket(RespSuccess, nil) //nolint:errcheck
fmt.Printf("client %v:%v responded for PacketAddRules\n", client, clients[client].Addr)
assert.NoError(t, conn.Close())
require.NoError(t, conn.Close())
addRuleDone.Done()
}
Expand Down Expand Up @@ -329,7 +333,7 @@ func TestNode(t *testing.T) {
// TODO: This error is not checked due to a bug in dmsg.
_ = proto.WritePacket(RespSuccess, nil) //nolint:errcheck
})
}
}*/

func createServer(t *testing.T, dc disc.APIClient) (srv *dmsg.Server, srvErr <-chan error) {
pk, sk, err := cipher.GenerateDeterministicKeyPair([]byte("s"))
Expand Down

0 comments on commit c924b6e

Please sign in to comment.