tests: remove flakiness in test-nointerrupt.t stable
authorArseniy Alekseyev <aalekseyev@janestreet.com>
Fri, 26 Aug 2022 11:36:20 +0100
branchstable
changeset 49446 8c75ae3f0eea
parent 49437 e4e33b779fa2
child 49448 5579a5e18a9b
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.
tests/test-nointerrupt.t
--- 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