Commit 09f3c2f1 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

doc/articles/wiki: fix racy test

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/6853069
parent e070aeae
......@@ -13,11 +13,13 @@ import (
"net/http"
"os"
"strings"
"time"
)
var (
post = flag.String("post", "", "urlencoded form data to POST")
addr = flag.Bool("addr", false, "find open address and print to stdout")
wait = flag.Duration("wait_for_port", 0, "if non-zero, the amount of time to wait for the address to become available")
)
func main() {
......@@ -37,11 +39,18 @@ func main() {
}
var r *http.Response
var err error
if *post != "" {
b := strings.NewReader(*post)
r, err = http.Post(url, "application/x-www-form-urlencoded", b)
} else {
r, err = http.Get(url)
loopUntil := time.Now().Add(*wait)
for {
if *post != "" {
b := strings.NewReader(*post)
r, err = http.Post(url, "application/x-www-form-urlencoded", b)
} else {
r, err = http.Get(url)
}
if err == nil || *wait == 0 || time.Now().After(loopUntil) {
break
}
time.Sleep(100 * time.Millisecond)
}
if err != nil {
log.Fatal(err)
......
......@@ -18,9 +18,7 @@ go build -o final-test.bin final-test.go
(./final-test.bin) &
wiki_pid=$!
sleep 1
./get.bin http://$addr/edit/Test > test_edit.out
./get.bin --wait_for_port=5s http://$addr/edit/Test > test_edit.out
diff -u test_edit.out test_edit.good
./get.bin -post=body=some%20content http://$addr/save/Test
diff -u Test.txt test_Test.txt.good
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment