File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
mlp-ea-decentralized/common/ga Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ package ga
2+
3+ import (
4+ "testing"
5+ "time"
6+ )
7+
8+ func TestCluster (t * testing.T ) {
9+ recvBestChan := make (chan Individual , 100 )
10+
11+ peer1 := MakeCluster (9998 , 100 , nil , []string {})
12+ peer2 := MakeCluster (9999 , 100 , recvBestChan , []string {"127.0.0.1:9998" })
13+
14+ // Launch First peer and wait for it to be ready
15+ go peer1 .Start (NodeMetadata {})
16+ time .Sleep (2 * time .Second )
17+
18+ // Peer2 will connect to peer1
19+ go peer2 .Start (NodeMetadata {})
20+ time .Sleep (2 * time .Second )
21+
22+ if peer1 .GetNumNodes () != 2 {
23+ t .Errorf ("Peer1 could not discover peer2" )
24+ }
25+
26+ if peer2 .GetNumNodes () != 2 {
27+ t .Errorf ("Peer2 could not discover peer2" )
28+ }
29+
30+ // Test individual broadcast
31+ peer1 .BroadcastBestIndividual <- Individual {
32+ IndividualID : "Test" ,
33+ }
34+
35+ // Wait for gossip the individual
36+ time .Sleep (5 * time .Second )
37+
38+ indiv := <- peer2 .ReceiveBestIndividual
39+ t .Logf ("Got indiv broadcasted with ID: %s" , indiv .IndividualID )
40+
41+ if indiv .IndividualID != "Test" {
42+ t .Errorf ("Error on broadcast" )
43+ }
44+
45+ peer1 .Shutdown ()
46+ peer2 .Shutdown ()
47+ }
You can’t perform that action at this time.
0 commit comments