55 "encoding/binary"
66 "fmt"
77 "math/big"
8+ "net"
89 "net/http"
910 "time"
1011
@@ -114,6 +115,11 @@ func RunTest(testName string, ttd *big.Int, slotsToSafe *big.Int, slotsToFinaliz
114115 }
115116 }()
116117
118+ // Before running the test, make sure Eth and Engine ports are open for the client
119+ if err := CheckEthEngineLive (c ); err != nil {
120+ t .Fatalf ("FAIL (%s): Ports were never open for client: %v" , env .TestName , err )
121+ }
122+
117123 // Setup timeouts
118124 env .Timeout = time .After (timeout )
119125 clMocker .Timeout = time .After (timeout )
@@ -136,10 +142,40 @@ func (t *TestEnv) MainTTD() *big.Int {
136142
137143func (t * TestEnv ) StartClient (clientType string , params hivesim.Params , ttd * big.Int ) (* hivesim.Client , * EngineClient , error ) {
138144 c := t .T .StartClient (clientType , params , hivesim .WithStaticFiles (t .ClientFiles ))
145+ if err := CheckEthEngineLive (c ); err != nil {
146+ return nil , nil , fmt .Errorf ("Engine/Eth ports were never open for client: %v" , err )
147+ }
139148 ec := NewEngineClient (t .T , c , ttd )
140149 return c , ec , nil
141150}
142151
152+ func CheckEthEngineLive (c * hivesim.Client ) error {
153+ ctx , cancel := context .WithTimeout (context .Background (), time .Second * 5 )
154+ defer cancel ()
155+ var (
156+ ticker = time .NewTicker (100 * time .Millisecond )
157+ dialer net.Dialer
158+ )
159+ defer ticker .Stop ()
160+ for _ , checkport := range []int {EthPortHTTP , EnginePortHTTP } {
161+ addr := fmt .Sprintf ("%s:%d" , c .IP , checkport )
162+ portcheckloop:
163+ for {
164+ select {
165+ case <- ctx .Done ():
166+ return ctx .Err ()
167+ case <- ticker .C :
168+ conn , err := dialer .DialContext (ctx , "tcp" , addr )
169+ if err == nil {
170+ conn .Close ()
171+ break portcheckloop
172+ }
173+ }
174+ }
175+ }
176+ return nil
177+ }
178+
143179func (t * TestEnv ) makeNextTransaction (recipient common.Address , amount * big.Int , payload []byte ) * types.Transaction {
144180
145181 gasLimit := uint64 (75000 )
0 commit comments