diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 200cd99259c..8307f0fb11e 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -276,6 +276,10 @@ { "ImportPath": "gopkg.in/tomb.v1", "Rev": "dd632973f1e7218eb1089048e0798ec9ae7dceb8" + }, + { + "ImportPath": "github.com/chriscool/go-sleep", + "Rev": "743ab5f1bb487edf1772bc29ca0bdf572b40785e" } ] } diff --git a/Godeps/_workspace/src/github.com/chriscool/go-sleep/LICENSE b/Godeps/_workspace/src/github.com/chriscool/go-sleep/LICENSE new file mode 100644 index 00000000000..7a6cf794e8a --- /dev/null +++ b/Godeps/_workspace/src/github.com/chriscool/go-sleep/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2014 Juan Batiz-Benet +Copyright (c) 2015 Christian Couder + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/Godeps/_workspace/src/github.com/chriscool/go-sleep/README.md b/Godeps/_workspace/src/github.com/chriscool/go-sleep/README.md new file mode 100644 index 00000000000..09d7cf6f73d --- /dev/null +++ b/Godeps/_workspace/src/github.com/chriscool/go-sleep/README.md @@ -0,0 +1,32 @@ +# go-sleep sleeps for some duration + +This unix tool is a thin wrapper around `time.Sleep()`. +It aims to provide a portable way to sleep for an amount of time that +need not to be a number of seconds. + +See https://godoc.org/time#ParseDuration for how the duration can be +specified. + +### Install + +```sh +go install github.com/chriscool/go-sleep +``` + +### Usage: + +``` +> go-sleep +Usage: go-sleep +Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". +See https://godoc.org/time#ParseDuration for more. +> time go-sleep 100ms + +real 0m0.104s +user 0m0.000s +sys 0m0.007s +``` + +### License + +MIT diff --git a/Godeps/_workspace/src/github.com/chriscool/go-sleep/go-sleep.go b/Godeps/_workspace/src/github.com/chriscool/go-sleep/go-sleep.go new file mode 100644 index 00000000000..be5b6a1485c --- /dev/null +++ b/Godeps/_workspace/src/github.com/chriscool/go-sleep/go-sleep.go @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "os" + "time" +) + +func main() { + if len(os.Args) != 2 { + usageError() + } + d, err := time.ParseDuration(os.Args[1]) + if err != nil { + fmt.Fprintf(os.Stderr, "Could not parse duration: %s\n", err) + usageError() + } + + time.Sleep(d) +} + +func usageError() { + fmt.Fprintf(os.Stderr, "Usage: %s \n", os.Args[0]) + fmt.Fprintln(os.Stderr, `Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".`) + fmt.Fprintln(os.Stderr, "See https://godoc.org/time#ParseDuration for more.") + os.Exit(-1) +} diff --git a/test/Makefile b/test/Makefile index a6d99dab963..cc5e1e933bb 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,11 +1,12 @@ -BINS = bin/random bin/multihash bin/ipfs bin/pollEndpoint bin/iptb +BINS = bin/random bin/multihash bin/ipfs bin/pollEndpoint bin/iptb bin/go-sleep IPFS_ROOT = ../ IPFS_CMD = ../cmd/ipfs RANDOM_SRC = ../Godeps/_workspace/src/github.com/jbenet/go-random MULTIHASH_SRC = ../Godeps/_workspace/src/github.com/jbenet/go-multihash IPTB_SRC = ../Godeps/_workspace/src/github.com/whyrusleeping/iptb POLLENDPOINT_SRC= ../thirdparty/pollEndpoint +GOSLEEP_SRC = ../Godeps/_workspace/src/github.com/chriscool/go-sleep # User might want to override those on the command line GOFLAGS = @@ -41,6 +42,10 @@ bin/iptb: $(call find_go_files, $(IPTB_SRC)) IPFS-BUILD-OPTIONS @echo "*** installing $@ ***" go build $(GOFLAGS) -o bin/iptb $(IPTB_SRC) +bin/go-sleep: $(call find_go_files, $(GOSLEEP_SRC)) IPFS-BUILD-OPTIONS + @echo "*** installing $@ ***" + go build $(GOFLAGS) -o bin/go-sleep $(GOSLEEP_SRC) + test: test_expensive test_expensive: verify_gofmt diff --git a/test/sharness/Makefile b/test/sharness/Makefile index f21e02971c2..100f952c80a 100644 --- a/test/sharness/Makefile +++ b/test/sharness/Makefile @@ -8,7 +8,7 @@ T = $(sort $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)) BINS = bin/random bin/multihash bin/ipfs bin/pollEndpoint \ - bin/iptb + bin/iptb bin/go-sleep SHARNESS = lib/sharness/sharness.sh IPFS_ROOT = ../.. diff --git a/test/sharness/lib/test-lib.sh b/test/sharness/lib/test-lib.sh index d58fef6f005..73b55b343c8 100644 --- a/test/sharness/lib/test-lib.sh +++ b/test/sharness/lib/test-lib.sh @@ -55,38 +55,33 @@ test_cmp_repeat_10_sec() { for i in $(test_seq 1 100) do test_cmp "$1" "$2" >/dev/null && return - sleep 0.1 + go-sleep 100ms done test_cmp "$1" "$2" } test_run_repeat_60_sec() { - for i in 1 2 3 4 5 6 + for i in $(test_seq 1 600) do - for i in 1 2 3 4 5 6 7 8 9 10 - do - (test_eval_ "$1") && return - sleep 1 - done + (test_eval_ "$1") && return + go-sleep 100ms done return 1 # failed } test_wait_output_n_lines_60_sec() { - for i in 1 2 3 4 5 6 + for i in $(test_seq 1 600) do - for i in 1 2 3 4 5 6 7 8 9 10 - do - test $(cat "$1" | wc -l | tr -d " ") -ge $2 && return - sleep 1 - done + test $(cat "$1" | wc -l | tr -d " ") -ge $2 && return + go-sleep 100ms done actual=$(cat "$1" | wc -l | tr -d " ") test_fsh "expected $2 lines of output. got $actual" } test_wait_open_tcp_port_10_sec() { - for i in 1 2 3 4 5 6 7 8 9 10; do + for i in $(test_seq 1 100) + do # this is not a perfect check, but it's portable. # cant count on ss. not installed everywhere. # cant count on netstat using : or . as port delim. differ across platforms. @@ -94,7 +89,7 @@ test_wait_open_tcp_port_10_sec() { if [ $(netstat -aln | egrep "^tcp.*LISTEN" | egrep "[.:]$1" | wc -l) -gt 0 ]; then return 0 fi - sleep 1 + go-sleep 100ms done return 1 } @@ -247,13 +242,13 @@ test_kill_repeat_10_sec() { kill $1 for i in $(test_seq 1 100) do - sleep 0.1 + go-sleep 100ms ! kill -0 $1 2>/dev/null && return done # if not, try once more, which will skip graceful exit kill $1 - sleep 1 + go-sleep 1s ! kill -0 $1 2>/dev/null && return # ok, no hope. kill it to prevent it messing with other tests