changeset 49405:8c75ae3f0eea stable

tests: remove flakiness in test-nointerrupt.t The problem was that the reaction to the signal was racing against the completion of the command. Since reaction to the signal is to print a line of warning, we can fix this by waiting for that warning to appear before allowing the command to complete.
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Fri, 26 Aug 2022 11:36:20 +0100
parents e4e33b779fa2
children 5579a5e18a9b
files tests/test-nointerrupt.t
diffstat 1 files changed, 17 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/tests/test-nointerrupt.t	Tue Jul 19 18:32:40 2022 -0700
+++ b/tests/test-nointerrupt.t	Fri Aug 26 11:36:20 2022 +0100
@@ -27,8 +27,6 @@
   >     with ui.uninterruptible():
   >         testing.write_file(sync_file, b'%d' % os.getpid())
   >         testing.wait_file(done_file)
-  >         # make sure we get rescheduled and the signal get a chance to be handled
-  >         time.sleep(0.1)
   >         ui.warn(b"end of unsafe operation\n")
   >     ui.warn(b"%d second(s) passed\n" % int(time.time() - start))
   > EOF
@@ -42,14 +40,26 @@
   > fi
   > "$RUNTESTDIR/testlib/wait-on-file" 10 "$SYNC_FILE" || exit 2
   > kill -s \$SIG \`cat "$SYNC_FILE"\`
-  > sleep 1
-  > touch "$DONE_FILE"
   > EOF
 
 #if no-windows
   $ chmod +x send-signal.sh
 #endif
 
+  $ cat > wait-signal.sh << 'EOF'
+  > #!/bin/sh
+  > (hg wait-signal 2>&1; echo [$?]) | {
+  >     read line
+  >     touch "$DONE_FILE"
+  >     echo "$line"
+  >     cat
+  > }
+  > EOF
+
+#if no-windows
+  $ chmod +x wait-signal.sh
+#endif
+
 Kludge to emulate timeout(1) which is not generally available.
 
 Set up repository
@@ -60,11 +70,10 @@
   > wait_ext = $TESTTMP/wait_ext.py
   > EOF
 
-
 Test ctrl-c
   $ rm -f $SYNC_FILE $DONE_FILE
   $ sh -c "../send-signal.sh INT" &
-  $ hg wait-signal
+  $ ../wait-signal.sh
   interrupted!
   [255]
 
@@ -75,7 +84,7 @@
 
   $ rm -f $SYNC_FILE $DONE_FILE
   $ sh -c "../send-signal.sh INT" &
-  $ hg wait-signal
+  $ ../wait-signal.sh
   interrupted!
   [255]
 
@@ -86,7 +95,7 @@
 
   $ rm -f $SYNC_FILE $DONE_FILE
   $ sh -c "../send-signal.sh INT" &
-  $ hg wait-signal
+  $ ../wait-signal.sh
   shutting down cleanly
   press ^C again to terminate immediately (dangerous)
   end of unsafe operation