From 0ba6fc3c30b9cf530faf7fcf5ce7be519ec13fe7 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 24 Jan 2013 23:13:41 +0000 Subject: tests: replace non-portable "date +%s" with ruby equivalent "date +%s" is not in POSIX (it is in GNU, and at least FreeBSD 9.0, possibly earlier). The Ruby equivalent should be sufficiently portable between different Ruby versions. This change was automated via: perl -i -p -e 's/date \+%s/unix_time/' t/*.sh --- t/t0003-reopen-logs.sh | 4 ++-- t/t0004-heartbeat-timeout.sh | 4 ++-- t/t0010-keepalive-timeout-effective.sh | 4 ++-- t/t0011-close-on-exec-set.sh | 4 ++-- t/t0017-keepalive-timeout-zero.sh | 4 ++-- t/t0043-quit-keepalive-disconnect.sh | 6 +++--- t/t0100-rack-input-hammer-chunked.sh | 4 ++-- t/t0100-rack-input-hammer-content-length.sh | 4 ++-- t/t0200-async-response.sh | 4 ++-- t/t0202-async-response-one-oh.sh | 4 ++-- t/t0300-async_sinatra.sh | 4 ++-- t/t0400-em-async-app.sh | 4 ++-- t/t0401-em-async-tailer.sh | 4 ++-- t/t0402-async-keepalive.sh | 24 ++++++++++++------------ t/t0500-cramp-streaming.sh | 6 +++--- t/t9000-rack-app-pool.sh | 4 ++-- t/test-lib.sh | 5 +++++ 17 files changed, 49 insertions(+), 44 deletions(-) (limited to 't') diff --git a/t/t0003-reopen-logs.sh b/t/t0003-reopen-logs.sh index 910a0a5..8e2cdc5 100755 --- a/t/t0003-reopen-logs.sh +++ b/t/t0003-reopen-logs.sh @@ -17,7 +17,7 @@ t_begin "ensure server is responsive" && { } t_begin "start $nr_client concurrent requests" && { - start=$(date +%s) + start=$(unix_time) for i in $(awk "BEGIN{for(i=0;i<$nr_client;++i) print i}" > $curl_out 2>> $curl_err ) & @@ -59,7 +59,7 @@ dbgcat r_err t_begin "wait curl requests to finish" && { wait - t_info elapsed=$(( $(date +%s) - $start )) + t_info elapsed=$(( $(unix_time) - $start )) } t_begin "ensure no errors from curl" && { diff --git a/t/t0004-heartbeat-timeout.sh b/t/t0004-heartbeat-timeout.sh index 53f2bd3..b96584d 100755 --- a/t/t0004-heartbeat-timeout.sh +++ b/t/t0004-heartbeat-timeout.sh @@ -23,9 +23,9 @@ t_begin "sleep for a bit, ensure worker PID does not change" && { t_begin "block the worker process to force it to die" && { rm $ok - t0=$(date +%s) + t0=$(unix_time) err="$(curl -sSf http://$listen/block-forever 2>&1 || > $ok)" - t1=$(date +%s) + t1=$(unix_time) elapsed=$(($t1 - $t0)) t_info "elapsed=$elapsed err=$err" test x"$err" != x"Should never get here" diff --git a/t/t0010-keepalive-timeout-effective.sh b/t/t0010-keepalive-timeout-effective.sh index 0a6236f..3b3fee4 100755 --- a/t/t0010-keepalive-timeout-effective.sh +++ b/t/t0010-keepalive-timeout-effective.sh @@ -16,12 +16,12 @@ t_begin 'check server up' && { t_begin "send keepalive response that does not expect close" && { req='GET / HTTP/1.1\r\nHost: example.com\r\n\r\n' - t0=$(date +%s) + t0=$(unix_time) ( cat $fifo > $tmp & printf "$req" wait - date +%s > $ok + unix_time > $ok ) | socat - TCP:$listen > $fifo now="$(cat $ok)" elapsed=$(( $now - $t0 )) diff --git a/t/t0011-close-on-exec-set.sh b/t/t0011-close-on-exec-set.sh index 9c66575..73f4ede 100755 --- a/t/t0011-close-on-exec-set.sh +++ b/t/t0011-close-on-exec-set.sh @@ -13,12 +13,12 @@ t_begin "setup and start" && { t_begin "send keepalive req expect it to timeout in ~1s" && { req='GET / HTTP/1.1\r\nHost: example.com\r\n\r\n' - t0=$(date +%s) + t0=$(unix_time) ( cat $fifo > $tmp & printf "$req" wait - date +%s > $ok + unix_time > $ok ) | socat - TCP:$listen > $fifo now="$(cat $ok)" elapsed=$(( $now - $t0 )) diff --git a/t/t0017-keepalive-timeout-zero.sh b/t/t0017-keepalive-timeout-zero.sh index b4085e8..a3f27da 100755 --- a/t/t0017-keepalive-timeout-zero.sh +++ b/t/t0017-keepalive-timeout-zero.sh @@ -16,12 +16,12 @@ t_begin 'check server responds with Connection: close' && { t_begin "send keepalive response that does not expect close" && { req='GET / HTTP/1.1\r\nHost: example.com\r\n\r\n' - t0=$(date +%s) + t0=$(unix_time) ( cat $fifo > $tmp & printf "$req" wait - date +%s > $ok + unix_time > $ok ) | socat - TCP:$listen > $fifo now="$(cat $ok)" elapsed=$(( $now - $t0 )) diff --git a/t/t0043-quit-keepalive-disconnect.sh b/t/t0043-quit-keepalive-disconnect.sh index f0a4d22..a98ce7e 100644 --- a/t/t0043-quit-keepalive-disconnect.sh +++ b/t/t0043-quit-keepalive-disconnect.sh @@ -33,13 +33,13 @@ t_begin "wait for response" && { } t_begin "stop Rainbows! gracefully" && { - t0=$(date +%s) + t0=$(unix_time) kill -QUIT $rainbows_pid } t_begin "keepalive client disconnected quickly" && { wait - diff=$(( $(date +%s) - $t0 )) + diff=$(( $(unix_time) - $t0 )) test $diff -le 2 || die "client diff=$diff > 2" } @@ -48,7 +48,7 @@ t_begin "wait for termination" && { do sleep 1 done - diff=$(( $(date +%s) - $t0 )) + diff=$(( $(unix_time) - $t0 )) test $diff -le 4 || die "server diff=$diff > 4" } diff --git a/t/t0100-rack-input-hammer-chunked.sh b/t/t0100-rack-input-hammer-chunked.sh index 42fe68d..efc3a9c 100755 --- a/t/t0100-rack-input-hammer-chunked.sh +++ b/t/t0100-rack-input-hammer-chunked.sh @@ -17,7 +17,7 @@ t_begin "setup and startup" && { } t_begin "send $nr_client concurrent requests" && { - start=$(date +%s) + start=$(unix_time) for i in $(awk "BEGIN{for(i=0;i<$nr_client;++i) print i}" > $curl_err | tee $a) & ( curl --no-buffer -sSf http://$listen/ 2>> $curl_err | tee $b) & ( curl --no-buffer -sSf http://$listen/ 2>> $curl_err | tee $c) & wait - t1=$(date +%s) + t1=$(unix_time) } t_begin "ensure elapsed requests were processed in parallel" && { diff --git a/t/t0202-async-response-one-oh.sh b/t/t0202-async-response-one-oh.sh index 49b6cac..6320d73 100755 --- a/t/t0202-async-response-one-oh.sh +++ b/t/t0202-async-response-one-oh.sh @@ -16,13 +16,13 @@ t_begin "setup and start" && { } t_begin "send async requests off in parallel" && { - t0=$(date +%s) + t0=$(unix_time) curl="curl -0 --no-buffer -vsSf http://$listen/" ( $curl 2>> $a_err | tee $a) & ( $curl 2>> $b_err | tee $b) & ( $curl 2>> $c_err | tee $c) & wait - t1=$(date +%s) + t1=$(unix_time) } t_begin "ensure elapsed requests were processed in parallel" && { diff --git a/t/t0300-async_sinatra.sh b/t/t0300-async_sinatra.sh index ef612b8..ae594eb 100755 --- a/t/t0300-async_sinatra.sh +++ b/t/t0300-async_sinatra.sh @@ -24,7 +24,7 @@ t_begin "setup and start" && { } t_begin "send async requests off in parallel" && { - t0=$(date +%s) + t0=$(unix_time) ( curl --no-buffer -sSf http://$listen/$n 2>> $curl_err | tee $a) & ( curl --no-buffer -sSf http://$listen/$n 2>> $curl_err | tee $b) & ( curl --no-buffer -sSf http://$listen/$n 2>> $curl_err | tee $c) & @@ -32,7 +32,7 @@ t_begin "send async requests off in parallel" && { t_begin "ensure elapsed requests were processed in parallel" && { wait - t1=$(date +%s) + t1=$(unix_time) elapsed=$(( $t1 - $t0 )) echo "elapsed=$elapsed < 30" test $elapsed -lt 30 diff --git a/t/t0400-em-async-app.sh b/t/t0400-em-async-app.sh index 34da2ad..fd21f5b 100755 --- a/t/t0400-em-async-app.sh +++ b/t/t0400-em-async-app.sh @@ -23,7 +23,7 @@ t_begin "setup and start" && { } t_begin "send async requests off in parallel" && { - t0=$(date +%s) + t0=$(unix_time) curl --no-buffer -sSf http://$listen/ > $a 2>> $curl_err & curl --no-buffer -sSf http://$listen/ > $b 2>> $curl_err & curl --no-buffer -sSf http://$listen/ > $c 2>> $curl_err & @@ -31,7 +31,7 @@ t_begin "send async requests off in parallel" && { t_begin "wait for curl terminations" && { wait - t1=$(date +%s) + t1=$(unix_time) elapsed=$(( $t1 - $t0 )) t_info "elapsed=$elapsed" } diff --git a/t/t0401-em-async-tailer.sh b/t/t0401-em-async-tailer.sh index 2c11cc0..2f7191c 100755 --- a/t/t0401-em-async-tailer.sh +++ b/t/t0401-em-async-tailer.sh @@ -27,7 +27,7 @@ t_begin "setup and start" && { } t_begin "send async requests off in parallel" && { - t0=$(date +%s) + t0=$(unix_time) curl --no-buffer -sSf http://$listen/ > $a 2>> $curl_err & curl_a=$! curl --no-buffer -sSf http://$listen/ > $b 2>> $curl_err & @@ -49,7 +49,7 @@ t_begin "generate log output" && { t_begin "kill curls and wait for termination" && { kill $curl_a $curl_b $curl_c wait - t1=$(date +%s) + t1=$(unix_time) elapsed=$(( $t1 - $t0 )) t_info "elapsed=$elapsed" } diff --git a/t/t0402-async-keepalive.sh b/t/t0402-async-keepalive.sh index 7b7b2e7..b5976da 100644 --- a/t/t0402-async-keepalive.sh +++ b/t/t0402-async-keepalive.sh @@ -28,7 +28,7 @@ t_begin "setup and start" && { t_begin "async.callback supports pipelining" && { rm -f $tmp - t0=$(date +%s) + t0=$(unix_time) ( cat $fifo > $tmp & printf 'GET /0 HTTP/1.1\r\nHost: example.com\r\n\r\n' @@ -36,7 +36,7 @@ t_begin "async.callback supports pipelining" && { printf 'GET /2 HTTP/1.0\r\nHost: example.com\r\n\r\n' wait ) | socat - TCP:$listen > $fifo - t1=$(date +%s) + t1=$(unix_time) elapsed=$(( $t1 - $t0 )) t_info "elapsed=$elapsed $model.$0 ($t_current)" test 3 -eq "$(fgrep 'HTTP/1.1 200 OK' $tmp | wc -l)" @@ -46,7 +46,7 @@ t_begin "async.callback supports pipelining" && { t_begin "async.callback supports delayed pipelining" && { rm -f $tmp - t0=$(date +%s) + t0=$(unix_time) ( cat $fifo > $tmp & printf 'GET /0 HTTP/1.1\r\nHost: example.com\r\n\r\n' @@ -56,7 +56,7 @@ t_begin "async.callback supports delayed pipelining" && { printf 'GET /2 HTTP/1.0\r\nHost: example.com\r\n\r\n' wait ) | socat - TCP:$listen > $fifo - t1=$(date +%s) + t1=$(unix_time) elapsed=$(( $t1 - $t0 )) t_info "elapsed=$elapsed $model.$0 ($t_current)" test 3 -eq "$(fgrep 'HTTP/1.1 200 OK' $tmp | wc -l)" @@ -66,7 +66,7 @@ t_begin "async.callback supports delayed pipelining" && { t_begin "async.callback supports pipelining with delay $DELAY" && { rm -f $tmp - t0=$(date +%s) + t0=$(unix_time) ( cat $fifo > $tmp & printf 'GET /0 HTTP/1.1\r\nX-Delay: %d\r\n' $DELAY @@ -77,7 +77,7 @@ t_begin "async.callback supports pipelining with delay $DELAY" && { printf 'Host: example.com\r\n\r\n' wait ) | socat - TCP:$listen > $fifo - t1=$(date +%s) + t1=$(unix_time) elapsed=$(( $t1 - $t0 )) min=$(( $DELAY * 3 )) t_info "elapsed=$elapsed $model.$0 ($t_current) min=$min" @@ -88,9 +88,9 @@ t_begin "async.callback supports pipelining with delay $DELAY" && { } t_begin "async.callback supports keepalive" && { - t0=$(date +%s) + t0=$(unix_time) curl -v --no-buffer -sSf http://$listen/[0-2] > $tmp 2>> $curl_err - t1=$(date +%s) + t1=$(unix_time) elapsed=$(( $t1 - $t0 )) t_info "elapsed=$elapsed $model.$0 ($t_current)" cmp $expect $tmp @@ -99,10 +99,10 @@ t_begin "async.callback supports keepalive" && { } t_begin "async.callback supports keepalive with delay $DELAY" && { - t0=$(date +%s) + t0=$(unix_time) curl -v --no-buffer -sSf -H "X-Delay: $DELAY" \ http://$listen/[0-2] > $tmp 2>> $curl_err - t1=$(date +%s) + t1=$(unix_time) elapsed=$(( $t1 - $t0 )) min=$(( $DELAY * 3 )) t_info "elapsed=$elapsed $model.$0 ($t_current) min=$min" @@ -113,7 +113,7 @@ t_begin "async.callback supports keepalive with delay $DELAY" && { } t_begin "send async requests off in parallel" && { - t0=$(date +%s) + t0=$(unix_time) curl --no-buffer -sSf http://$listen/[0-2] > $a 2>> $curl_err & curl --no-buffer -sSf http://$listen/[0-2] > $b 2>> $curl_err & curl --no-buffer -sSf http://$listen/[0-2] > $c 2>> $curl_err & @@ -121,7 +121,7 @@ t_begin "send async requests off in parallel" && { t_begin "wait for curl terminations" && { wait - t1=$(date +%s) + t1=$(unix_time) elapsed=$(( $t1 - $t0 )) t_info "elapsed=$elapsed" } diff --git a/t/t0500-cramp-streaming.sh b/t/t0500-cramp-streaming.sh index 81fd55d..fe798d3 100755 --- a/t/t0500-cramp-streaming.sh +++ b/t/t0500-cramp-streaming.sh @@ -32,7 +32,7 @@ check () { i=0 while read hello world do - t1=$(date +%s) + t1=$(unix_time) diff=$(($t1 - $t0)) t_info "i=$i diff=$diff hello=$hello world=$world" test $diff -ge 1 || echo "$i: diff: $diff < 1 second" @@ -46,7 +46,7 @@ check () { } t_begin "send async requests off in parallel" && { - t0=$(date +%s) + t0=$(unix_time) curl --no-buffer -sSf http://$listen/ 2>> $curl_err | check >$a 2>&1 & curl --no-buffer -sSf http://$listen/ 2>> $curl_err | check >$b 2>&1 & curl --no-buffer -sSf http://$listen/ 2>> $curl_err | check >$c 2>&1 & @@ -54,7 +54,7 @@ t_begin "send async requests off in parallel" && { t_begin "wait for curl terminations" && { wait - t1=$(date +%s) + t1=$(unix_time) elapsed=$(( $t1 - $t0 )) t_info "elapsed=$elapsed (should be 4-5s)" } diff --git a/t/t9000-rack-app-pool.sh b/t/t9000-rack-app-pool.sh index ecb8aeb..5170b67 100755 --- a/t/t9000-rack-app-pool.sh +++ b/t/t9000-rack-app-pool.sh @@ -19,14 +19,14 @@ t_begin "configure and start" && { } t_begin "launch $nr_client requests" && { - start=$(date +%s) + start=$(unix_time) seq="$(awk "BEGIN{for(i=0;i<$nr_client;++i) print i}" > $curl_out 2>> $curl_err & done wait - t_info elapsed=$(( $(date +%s) - $start )) + t_info elapsed=$(( $(unix_time) - $start )) } t_begin "kill server" && { diff --git a/t/test-lib.sh b/t/test-lib.sh index 55deb41..8921da6 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -38,6 +38,11 @@ require_check () { fi } +# "date +%s" is not in POSIX, but in GNU, and FreeBSD 9.0 (possibly earlier) +unix_time () { + $RUBY -e 'puts Time.now.to_i' +} + skip_models () { for i in "$@" do -- cgit v1.2.3-24-ge0c7