length of syncing peers should be 1 now

pull/125/head
Minh Doan 6 years ago
parent 39cb555615
commit 46212eb359
  1. 6
      node/node.go
  2. 8
      node/node_test.go

@ -385,11 +385,15 @@ func GetSyncingPort(nodePort string) string {
}
// GetSyncingPeers returns list of peers.
// Right now, the list length is only 1 for testing.
// TODO(mihdoan): fix it later.
func (node *Node) GetSyncingPeers() []p2p.Peer {
res := []p2p.Peer{}
node.Neighbors.Range(func(k, v interface{}) bool {
node.log.Debug("GetSyncingPeers-Range: ", "k", k, "v", v)
res = append(res, v.(p2p.Peer))
if len(res) == 0 {
res = append(res, v.(p2p.Peer))
}
return true
})

@ -70,10 +70,10 @@ func TestGetSyncingPeers(t *testing.T) {
node.Neighbors.Store("minh", peer)
node.Neighbors.Store("mark", peer2)
res := node.GetSyncingPeers()
if len(res) != 2 || !((res[0].IP == peer.IP && res[1].IP == peer2.IP) || (res[1].IP == peer.IP && res[0].IP == peer2.IP)) {
if len(res) != 1 || !(res[0].IP == peer.IP || res[0].IP == peer2.IP) {
t.Error("GetSyncingPeers should return list of {peer, peer2}")
}
if len(res) != 2 || res[0].Port != "1000" || res[1].Port != "1000" {
if len(res) != 1 || res[0].Port != "1000" {
t.Error("Syncing ports should be 1000")
}
}
@ -166,8 +166,8 @@ func sendPongMessage(leader p2p.Peer) {
}
func exitServer() {
fmt.Println("wait 15 seconds to terminate the process ...")
time.Sleep(15 * time.Second)
fmt.Println("wait 5 seconds to terminate the process ...")
time.Sleep(5 * time.Second)
os.Exit(0)
}

Loading…
Cancel
Save