diff options
author | David Howells <dhowells@redhat.com> | 2011-09-05 14:38:43 +0100 |
---|---|---|
committer | David Howells <dhowells@redhat.com> | 2011-11-15 18:44:33 +0000 |
commit | b73ed3db719f44e9b34be22f304d96b9149450de (patch) | |
tree | 4334d7068121390eddf2535d340de75c0d9b6bfa | |
parent | 9fff5e86992c81b23f14fcb94c2b6d2e4c888ac5 (diff) | |
download | keyutils-b73ed3db719f44e9b34be22f304d96b9149450de.tar.gz |
TEST: Handle timeouts better
Make sure that when we're waiting for a timeout to expire, we don't undersleep
- lest we start analysing the state too early and rule that a test is broken.
This can be seen just occasionally by the key timeout test when the sleep
command sleeps for less than the amount of time specified.
Reported-by: Jan Stancek <jstancek@redhat.com>
Signed-off-by: David Howells <dhowells@redhat.com>
-rw-r--r-- | tests/keyctl/timeout/valid/runtest.sh | 4 | ||||
-rw-r--r-- | tests/toolbox.inc.sh | 17 |
2 files changed, 19 insertions, 2 deletions
diff --git a/tests/keyctl/timeout/valid/runtest.sh b/tests/keyctl/timeout/valid/runtest.sh index 1102536..0674826 100644 --- a/tests/keyctl/timeout/valid/runtest.sh +++ b/tests/keyctl/timeout/valid/runtest.sh @@ -47,7 +47,7 @@ marker "SET SMALL TIMEOUT" timeout_key $keyid 2 marker "WAIT FOR TIMEOUT" -sleep 2 +sleep_at_least 2 # check the key has expired marker "CHECK NO READ PAYLOAD" @@ -96,7 +96,7 @@ marker "TIMEOUT KEYRING" timeout_key $keyringid 1 marker "WAIT FOR KEYRING TIMEOUT" -sleep 1 +sleep_at_least 1 # listing the session keyring should fail marker "CHECK NO LIST SESSION KEYRING" diff --git a/tests/toolbox.inc.sh b/tests/toolbox.inc.sh index 058e398..998cf1f 100644 --- a/tests/toolbox.inc.sh +++ b/tests/toolbox.inc.sh @@ -1060,3 +1060,20 @@ function timeout_key () failed fi } + +############################################################################### +# +# Make sure we sleep at least N seconds +# +############################################################################### +function sleep_at_least () +{ + my_now=`date +%s` + my_done_at=$(($my_now+$1+1)) + sleep $1 + while [ `date +%s` -lt $my_done_at ] + do + # Sleep in 1/50th of a second bursts till the time catches up + sleep .02 + done +} |