2fas-server/e2e-tests/scripts/wait-ready/main.go
Krzysztof Dryś 7bf9bfb906
feat: send push to mobile (#49)
feat: send push to mobile
2024-05-27 16:56:05 +02:00

51 lines
984 B
Go

package main
import (
"flag"
"log"
"net"
"strings"
"time"
)
func main() {
addrFlag := flag.String("addr", ":80;:8081;:8082;:8088", "list of addresses to check sep by ;")
flag.Parse()
addresses := strings.Split(*addrFlag, ";")
if len(addresses) < 1 {
log.Fatal("-addr value not provided")
}
for _, address := range addresses {
running := waitForApp(address, 30*time.Second)
if !running {
log.Fatal("App not running on addr: ", address)
}
}
}
// waitForApp returns true if app is listening on provided address.
// If it cannot connect up to specified timeout, it returns false.
func waitForApp(address string, timeout time.Duration) bool {
done := make(chan struct{})
go func() {
for {
_, err := net.DialTimeout("tcp", address, time.Second)
if err != nil {
time.Sleep(time.Second)
continue
}
close(done)
return
}
}()
timeoutCh := time.After(timeout)
select {
case <-done:
return true
case <-timeoutCh:
return false
}
}