Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround dial error in go test #51

Merged
merged 2 commits into from
Aug 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker/dev.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ RUN apk add git python3 make
RUN go get -d -v .
RUN make deps

CMD ["sh"]
CMD ["sh"]
13 changes: 7 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ import (
)

type ShardIDType = int64
type PBInt = int64

const numShards ShardIDType = 100

func makeKey(seed int64) (ic.PrivKey, peer.ID, error) {
func makeKey(seed int) (ic.PrivKey, peer.ID, error) {
// If the seed is zero, use real cryptographic randomness. Otherwise, use a
// deterministic randomness source to make generated keys stay the same
// across multiple runs
r := mrand.New(mrand.NewSource(seed))
r := mrand.New(mrand.NewSource(int64(seed)))
// r := rand.Reader

// Generate a key pair for this host. We will use it at least
Expand All @@ -57,7 +58,7 @@ func makeKey(seed int64) (ic.PrivKey, peer.ID, error) {
func makeNode(
ctx context.Context,
listenPort int,
randseed int64,
randseed int,
doBootstrapping bool,
bootstrapPeers []pstore.PeerInfo) (*Node, error) {
// FIXME: should be set to localhost if we don't want to expose it to outside
Expand Down Expand Up @@ -117,7 +118,7 @@ func main() {

// Parse options from the command line

seed := flag.Int64("seed", 0, "set random seed for id generation")
seed := flag.Int("seed", 0, "set random seed for id generation")
listenPort := flag.Int(
"port",
defaultListenPort,
Expand Down Expand Up @@ -146,7 +147,7 @@ func main() {

func runServer(
listenPort int,
seed int64,
seed int,
doBootstrapping bool,
bootnodes []pstore.PeerInfo,
rpcAddr string) {
Expand Down Expand Up @@ -178,7 +179,7 @@ func runClient(rpcAddr string, cliArgs []string) {
}
targetIP := rpcArgs[0]
targetPort, err := strconv.Atoi(rpcArgs[1])
targetSeed, err := strconv.ParseInt(rpcArgs[2], 10, 64)
targetSeed, err := strconv.Atoi(rpcArgs[2])
if err != nil {
panic(err)
}
Expand Down
14 changes: 10 additions & 4 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
// gologging "github.com/whyrusleeping/go-logging"
)

var nodeCount int

func makeUnbootstrappedNode(t *testing.T, ctx context.Context, number int) *Node {
return makeTestingNode(t, ctx, number, false, nil)
}
Expand All @@ -22,8 +24,12 @@ func makeTestingNode(
number int,
doBootstrapping bool,
bootstrapPeers []pstore.PeerInfo) *Node {
listeningPort := number + 10000
node, err := makeNode(ctx, listeningPort, int64(number), doBootstrapping, bootstrapPeers)
// FIXME:
// 1. Use 20000 to avoid conflitcs with the running nodes in the environment
// 2. Avoid reuse of listeningPort in the entire test, to avoid `dial error`s
listeningPort := 20000 + nodeCount
nodeCount++
node, err := makeNode(ctx, listeningPort, number, doBootstrapping, bootstrapPeers)
if err != nil {
t.Error("Failed to create node")
}
Expand Down Expand Up @@ -253,12 +259,12 @@ func TestRequestCollation(t *testing.T) {
defer cancel()
node0, node1 := makePeerNodes(t, ctx)
shardID := ShardIDType(1)
period := int64(42)
period := 42
collation, err := node0.requestCollation(ctx, node1.ID(), shardID, period, "2")
if err != nil {
t.Error("request collation failed")
}
if collation.ShardID != shardID || collation.Period != period {
if collation.ShardID != shardID || collation.Period != PBInt(period) {
t.Errorf(
"responded collation does not correspond to the request: collation.ShardID=%v, request.shardID=%v, collation.Period=%v, request.period=%v",
collation.ShardID,
Expand Down
2 changes: 1 addition & 1 deletion node.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

// node client version
const clientVersion = "go-p2p-node/0.0.1"
const clientVersion = "sharding-p2p-node/0.0.1"

// Node type - a p2p host implementing one or more p2p protocols
type Node struct {
Expand Down
140 changes: 94 additions & 46 deletions pb/rpc/rpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions pb/rpc/rpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ service Poc {
// AddPeer
message RPCAddPeerReq {
string ip = 1;
int32 port = 2;
int64 port = 2;
int64 seed = 3;
}

Expand All @@ -37,14 +37,20 @@ message RPCGetSubscribedShardReply {
// BroadcastCollation
message RPCBroadcastCollationReq {
int64 shardID = 1;
int32 number = 2;
int32 size = 3;
int32 period = 4;
int64 number = 2;
int64 size = 3;
int64 period = 4;
}
// RequestCollation
message RPCRequestCollationReq {
int64 shardID = 1;
int64 period = 4;
}
// StopServer
message RPCStopServerReq {
}


message RPCReply {
string message = 1;
bool status = 2;
Expand Down
Loading