@@ -37,21 +37,30 @@ func TestGG18_4Node(t *testing.T) {
3737 for i := range ports {
3838 ports [i ] = getRandomPort (t )
3939 }
40- log . Info ( "TestGG18Integration4Node" , "ports" , ports , "channel" , channel , "name" , t . Name ())
40+
4141 mock1 , cli1 := startTestNode (t , ports [0 ], channel , nil )
4242 defer mock1 .Close ()
4343
4444 selfID := waitSelfPeerID (t , cli1 , 10 * time .Second )
4545 seed := fmt .Sprintf ("/ip4/127.0.0.1/tcp/%d/p2p/%s" , ports [0 ], selfID )
46+ log .Info ("TestGG18Integration4Node" , "ports" , ports , "channel" , channel , "seed" , seed )
4647
47- // rank 0, 1,1,1
48+ cmds := make ([] * childProc , 0 , 3 )
4849 for i := 1 ; i <= 3 ; i ++ {
4950 role := fmt .Sprintf ("node%d" , i + 1 )
50- cmd := startChildNode ( t , role , ports [i ], seed )
51- defer waitChildExit ( t , cmd , role )
51+ log . Info ( "TestGG18_4Node start child node" , " role" , role , "port" , ports [i ])
52+ cmds = append ( cmds , startChildNode ( t , role , ports [ i ], seed ) )
5253 }
53-
5454 runNodeFlow (t , cli1 , 0 , "node1" )
55+ wg := sync.WaitGroup {}
56+ for _ , cmd := range cmds {
57+ wg .Add (1 )
58+ go func (cmd * childProc ) {
59+ waitChildExit (t , cmd , cmd .role )
60+ wg .Done ()
61+ }(cmd )
62+ }
63+ wg .Wait ()
5564}
5665
5766func getRandomPort (t * testing.T ) int {
@@ -130,7 +139,7 @@ func runNodeFlow(t *testing.T, cli queue.Client, rank uint32, role string) {
130139 select {
131140 case <- c :
132141 case <- time .After (30 * time .Second ):
133- require . FailNow ( t , "test 3 node concurrent sign timeout" )
142+ t . Fatalf ( "test 3 node concurrent sign timeout, role=%s" , role )
134143 }
135144}
136145
@@ -166,16 +175,17 @@ func startTestNode(t *testing.T, port int, channel int32, seeds []string) (*test
166175}
167176
168177type childProc struct {
169- cmd * exec.Cmd
170- out * bytes.Buffer
178+ cmd * exec.Cmd
179+ out * bytes.Buffer
180+ role string
171181}
172182
173183func startChildNode (t * testing.T , role string , port int , seed string ) * childProc {
174184 testName := "TestGG18Node"
175185 args := []string {"test" , "./" , "-run" , "^" + testName + "$" , "-count=1" }
176186 cmd := exec .Command ("go" , args ... )
177187 cmd .Env = append (os .Environ (), "TSS_ROLE=" + role ,
178- "TSS_PORT=" + strconv .Itoa (port ), "TSS_SEEDS =" + seed ,
188+ "TSS_PORT=" + strconv .Itoa (port ), "TSS_SEED =" + seed ,
179189 )
180190 var out bytes.Buffer
181191 cmd .Stdout = & out
@@ -186,31 +196,42 @@ func startChildNode(t *testing.T, role string, port int, seed string) *childProc
186196 _ = cmd .Process .Kill ()
187197 }
188198 })
189- return & childProc {cmd : cmd , out : & out }
199+ return & childProc {cmd : cmd , out : & out , role : role }
190200}
191201
192- func waitChildExit (t * testing.T , child * childProc , label string ) {
193- err := child .cmd .Wait ()
194- if err != nil {
195- t .Fatalf ("%s process failed: %v\n %s" , label , err , child .out .String ())
202+ func waitChildExit (t * testing.T , child * childProc , role string ) {
203+ log .Info ("waitChildExit" , "role" , role )
204+ c := make (chan error )
205+ go func () {
206+ c <- child .cmd .Wait ()
207+ }()
208+ select {
209+ case err := <- c :
210+ if err != nil {
211+ t .Fatalf ("child exit with error: %v, role %s, output: %s" , err , role , child .out .String ())
212+ }
213+ case <- time .After (30 * time .Second ):
214+ t .Fatalf ("timeout waiting for child exit, role %s, output: %s" , role , child .out .String ())
196215 }
216+ log .Info ("waitChildExit end" , "role" , role )
197217}
198218
199219func waitPeerIDs (t * testing.T , cli queue.Client , want int , timeout time.Duration , role string ) []string {
200220 deadline := time .Now ().Add (timeout )
201- peers , err := tss . FetchConnectedPeers ( cli , 3 * time . Second )
221+
202222 for time .Now ().Before (deadline ) {
223+ peers , err := tss .FetchConnectedPeers (cli , 3 * time .Second )
203224 if err == nil && len (peers ) == want {
204225 ids := make ([]string , 0 , len (peers ))
205226 for _ , peer := range peers {
206227 ids = append (ids , peer .Name )
207228 }
208229 return ids
209230 }
210- time . Sleep ( time . Second )
211- peers , err = tss . FetchConnectedPeers ( cli , 3 * time .Second )
231+ log . Info ( "waitPeerIDs" , "role" , role , "want" , want , "actual" , len ( peers ), "err" , err )
232+ time . Sleep ( time .Second * 3 )
212233 }
213- t .Fatalf ("timeout waiting for %d peers, actual=%d, role %s" , want , len ( peers ) , role )
234+ t .Fatalf ("timeout waiting for %d peers, role %s" , want , role )
214235 return nil
215236}
216237
0 commit comments