mirror of
https://github.com/golang/go
synced 2024-11-25 09:37:56 -07:00
doc/articles/wiki: fix racy test
R=golang-dev, r CC=golang-dev https://golang.org/cl/6853069
This commit is contained in:
parent
e070aeae77
commit
09f3c2f10f
@ -13,11 +13,13 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
post = flag.String("post", "", "urlencoded form data to POST")
|
post = flag.String("post", "", "urlencoded form data to POST")
|
||||||
addr = flag.Bool("addr", false, "find open address and print to stdout")
|
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() {
|
func main() {
|
||||||
@ -37,11 +39,18 @@ func main() {
|
|||||||
}
|
}
|
||||||
var r *http.Response
|
var r *http.Response
|
||||||
var err error
|
var err error
|
||||||
if *post != "" {
|
loopUntil := time.Now().Add(*wait)
|
||||||
b := strings.NewReader(*post)
|
for {
|
||||||
r, err = http.Post(url, "application/x-www-form-urlencoded", b)
|
if *post != "" {
|
||||||
} else {
|
b := strings.NewReader(*post)
|
||||||
r, err = http.Get(url)
|
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 {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -18,9 +18,7 @@ go build -o final-test.bin final-test.go
|
|||||||
(./final-test.bin) &
|
(./final-test.bin) &
|
||||||
wiki_pid=$!
|
wiki_pid=$!
|
||||||
|
|
||||||
sleep 1
|
./get.bin --wait_for_port=5s http://$addr/edit/Test > test_edit.out
|
||||||
|
|
||||||
./get.bin http://$addr/edit/Test > test_edit.out
|
|
||||||
diff -u test_edit.out test_edit.good
|
diff -u test_edit.out test_edit.good
|
||||||
./get.bin -post=body=some%20content http://$addr/save/Test
|
./get.bin -post=body=some%20content http://$addr/save/Test
|
||||||
diff -u Test.txt test_Test.txt.good
|
diff -u Test.txt test_Test.txt.good
|
||||||
|
Loading…
Reference in New Issue
Block a user