Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use github.com/chriscool/go-sleep #1341

Merged
merged 3 commits into from
Jun 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions Godeps/_workspace/src/github.com/chriscool/go-sleep/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions Godeps/_workspace/src/github.com/chriscool/go-sleep/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions Godeps/_workspace/src/github.com/chriscool/go-sleep/go-sleep.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion test/Makefile
Original file line number Diff line number Diff line change
@@ -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 =
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/sharness/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ../..

Expand Down
29 changes: 12 additions & 17 deletions test/sharness/lib/test-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,46 +55,41 @@ 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.
echo $(netstat -aln | egrep "^tcp.*LISTEN" | egrep "[.:]$1" | wc -l) -gt 0
if [ $(netstat -aln | egrep "^tcp.*LISTEN" | egrep "[.:]$1" | wc -l) -gt 0 ]; then
return 0
fi
sleep 1
go-sleep 100ms
done
return 1
}
Expand Down Expand Up @@ -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
Expand Down