guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[shepherd] 03/03: tests: Make ‘forking-service.sh’ more tolerant of dela


From: Ludovic Courtès
Subject: [shepherd] 03/03: tests: Make ‘forking-service.sh’ more tolerant of delays.
Date: Sat, 6 Jan 2024 17:35:30 -0500 (EST)

civodul pushed a commit to branch main
in repository shepherd.

commit f20758f86b1f72a4e1c56b44026616a1c69a8192
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Sat Jan 6 23:33:12 2024 +0100

    tests: Make ‘forking-service.sh’ more tolerant of delays.
    
    This is helpful for systems without ‘signalfd’, which may react more
    slowly, and when testing on slower machines.
    
    * tests/forking-service.sh: Define ‘within_seconds’ and use it when
    checking service death and respawn.  Set #:respawn-delay for ‘test2’.
---
 tests/forking-service.sh | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/tests/forking-service.sh b/tests/forking-service.sh
index 4b8206a..9742cfe 100644
--- a/tests/forking-service.sh
+++ b/tests/forking-service.sh
@@ -43,6 +43,18 @@ function cleanup
     rm -f $service2_pid
 }
 
+function within_seconds
+{
+    seconds=$1
+    while [ $seconds -gt 0 ]
+    do
+       "$SHELL" -c "$2" && break
+       sleep 1
+       seconds="$(expr $seconds - 1)"
+    done
+    [ $seconds -gt 0 ] || "$SHELL" -c "$2"
+}
+
 trap cleanup EXIT
 
 cat > "$conf"<<EOF
@@ -73,6 +85,7 @@ cat > "$conf"<<EOF
         #:start (make-forkexec-constructor %command2
                                            #:pid-file "$PWD/$service2_pid")
         #:stop  (make-kill-destructor)
+         #:respawn-delay 0
         #:respawn? #t)))
 
 (define %command3
@@ -119,8 +132,7 @@ service_pid_value="`cat $service_pid`"
 kill "$service_pid_value"
 while kill -0 "$service_pid_value"; do sleep 0.3; done
 # shepherd should notice that the service has stopped within one second
-sleep 1
-$herd status test | grep stopped
+within_seconds 3 "$herd status test | grep stopped"
 
 
 
@@ -133,9 +145,8 @@ test "`cat $PWD/$service2_started`" = "started"
 rm -f "$service2_pid"
 kill $service2_pid_value
 while kill -0 "$service2_pid_value"; do sleep 0.3; done
-# shepherd should notice that the service has stopped, and restart it, within 
one second
-sleep 1;
-$herd status test2 | grep running
+# shepherd should notice that the service has stopped, and restart it, within 
seconds
+within_seconds 5 "$herd status test2 | grep 'Last respawned'"
 test "`cat $PWD/$service2_started`" = "started
 started"
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]