Skip to content

Commit

Permalink
fix: xctest
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhouYixun committed Aug 31, 2022
1 parent 9cb559e commit 1ee4b65
Showing 1 changed file with 52 additions and 4 deletions.
56 changes: 52 additions & 4 deletions cmd/run/wda.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"io"
"log"
"net"
"net/http"
"os"
"os/signal"
"regexp"
Expand Down Expand Up @@ -96,15 +97,62 @@ var wdaCmd = &cobra.Command{
signal.Notify(shutWdaDown, os.Interrupt, os.Kill)

go func() {
for s := range output {
fmt.Print(s)
if strings.Contains(s, "ServerURLHere->") {
fmt.Println("WebDriverAgent server start successful")
for {
select {
case s, ok := <-output:
if ok {
fmt.Print(s)
if strings.Contains(s, "ServerURLHere->") {
fmt.Println("WebDriverAgent server start successful")
}
} else {
return
}
case <-shutWdaDown:
return
}
}
shutWdaDown <- os.Interrupt
}()

go func() {
var resp *http.Response
var httpErr error
var checkTime = 0
ticker := time.NewTicker(time.Second * 10)
for {
select {
case <-ticker.C:
resp, httpErr = http.Get(fmt.Sprintf("http://127.0.0.1:%d/health", serverLocalPort))
if httpErr != nil {
fmt.Printf("request fail: %s", httpErr)
continue
}
if resp.StatusCode == 200 {
fmt.Printf("wda server health checked %d times: ok\n", checkTime)
} else {
stopTest()
var upTimes = 0
for {
output, stopTest, err2 = device.XCTest(wdaBundleID, giDevice.WithXCTestEnv(testEnv))
upTimes++
if err2 != nil {
fmt.Printf("WebDriverAgent server start failed in %d times: %s\n", upTimes, err2)
if upTimes >= 3 {
fmt.Printf("WebDriverAgent server start failed more than 3 times, giving up...\n")
os.Exit(0)
}
} else {
break
}
}
}
case <-shutWdaDown:
return
}
}
}()

<-shutWdaDown
stopTest()
fmt.Println("stopped")
Expand Down

0 comments on commit 1ee4b65

Please sign in to comment.