diff --git a/node/node.go b/node/node.go index d5f65fbec..94580daa4 100644 --- a/node/node.go +++ b/node/node.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 }) diff --git a/node/node_test.go b/node/node_test.go index 2b93ece56..df52d7649 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -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) }