diff --git a/tests/test-debugcommands.t b/tests/test-debugcommands.t
index 4b347e9429e7f2127d27ac904cc979bec9d38061_dGVzdHMvdGVzdC1kZWJ1Z2NvbW1hbmRzLnQ=..f0bee30af890abe02002eb3a78fc917011074ba8_dGVzdHMvdGVzdC1kZWJ1Z2NvbW1hbmRzLnQ= 100644
--- a/tests/test-debugcommands.t
+++ b/tests/test-debugcommands.t
@@ -523,19 +523,5 @@
 
 * Test setting the lock
 
-waitlock <file> will wait for file to be created. If it isn't in a reasonable
-amount of time, displays error message and returns 1
-  $ waitlock() {
-  >     start=`date +%s`
-  >     timeout=5
-  >     while [ \( ! -f $1 \) -a \( ! -L $1 \) ]; do
-  >         now=`date +%s`
-  >         if [ "`expr $now - $start`" -gt $timeout ]; then
-  >             echo "timeout: $1 was not created in $timeout seconds"
-  >             return 1
-  >         fi
-  >         sleep 0.1
-  >     done
-  > }
   $ dolock() {
   >     {
@@ -540,8 +526,8 @@
   $ dolock() {
   >     {
-  >         waitlock .hg/unlock
+  >         "$RUNTESTDIR/testlib/wait-on-file" 5 .hg/unlock
   >         rm -f .hg/unlock
   >         echo y
   >     } | hg debuglocks "$@" > /dev/null
   > }
   $ dolock -s &
@@ -543,9 +529,9 @@
   >         rm -f .hg/unlock
   >         echo y
   >     } | hg debuglocks "$@" > /dev/null
   > }
   $ dolock -s &
-  $ waitlock .hg/store/lock
+  $ "$RUNTESTDIR/testlib/wait-on-file" 5 .hg/store/lock
 
   $ hg debuglocks
   lock:  user *, process * (*s) (glob)
@@ -559,7 +545,7 @@
 * Test setting the wlock
 
   $ dolock -S &
-  $ waitlock .hg/wlock
+  $ "$RUNTESTDIR/testlib/wait-on-file" 5 .hg/wlock
 
   $ hg debuglocks
   lock:  free
@@ -573,7 +559,8 @@
 * Test setting both locks
 
   $ dolock -Ss &
-  $ waitlock .hg/wlock && waitlock .hg/store/lock
+  $ "$RUNTESTDIR/testlib/wait-on-file" 5 .hg/wlock
+  $ "$RUNTESTDIR/testlib/wait-on-file" 5 .hg/store/lock
 
   $ hg debuglocks
   lock:  user *, process * (*s) (glob)
@@ -600,7 +587,7 @@
 * Test forcing the lock
 
   $ dolock -s &
-  $ waitlock .hg/store/lock
+  $ "$RUNTESTDIR/testlib/wait-on-file" 5 .hg/store/lock
 
   $ hg debuglocks
   lock:  user *, process * (*s) (glob)
@@ -619,7 +606,7 @@
 * Test forcing the wlock
 
   $ dolock -S &
-  $ waitlock .hg/wlock
+  $ "$RUNTESTDIR/testlib/wait-on-file" 5 .hg/wlock
 
   $ hg debuglocks
   lock:  free