1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-07-01 02:30:39 +08:00

misc: add test for api readiness

This commit is contained in:
Brian Tiger Chow
2015-02-06 12:09:10 -07:00
parent 8ef61e7704
commit 87c6604b56

34
test/api-startup/main.go Normal file
View File

@ -0,0 +1,34 @@
package main
import (
"fmt"
"log"
"net/http"
"sync"
"time"
)
func main() {
when := make(chan (time.Time), 2)
var wg sync.WaitGroup
wg.Add(2)
for _, port := range []string{"5001", "8080"} {
go func(port string) {
defer wg.Done()
for {
r, err := http.Get(fmt.Sprintf("http://127.0.0.1:%s", port))
if err != nil {
continue
}
t := time.Now()
when <- t
log.Println(port, t, r.StatusCode)
break
}
}(port)
}
wg.Wait()
first := <-when
second := <-when
log.Println(second.Sub(first))
}