Mercurial > hg
comparison tests/testlib/wait-on-file @ 44631:1ed6293fc31b
testlib: add a small scrip to help process to synchronise using file
Creating and waiting for files is a robust way to synchronise two processes
running concurrently. We already use this approach in various tests. I am adding
a official script to do so before adding more usage of this.
Differential Revision: https://phab.mercurial-scm.org/D8189
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Fri, 28 Feb 2020 02:23:28 +0100 |
parents | |
children | 82543879b48e |
comparison
equal
deleted
inserted
replaced
44630:4c6189d45d67 | 44631:1ed6293fc31b |
---|---|
1 #!/bin/bash | |
2 # | |
3 # wait up to TIMEOUT seconds until a WAIT_ON_FILE is created. | |
4 # | |
5 # In addition, this script can create CREATE_FILE once it is ready to wait. | |
6 | |
7 if [ $# -lt 2 ] || [ $# -gt 3 ]; then | |
8 echo $# | |
9 echo "USAGE: $0 TIMEOUT WAIT_ON_FILE [CREATE_FILE]" | |
10 fi | |
11 | |
12 timer="$1" | |
13 wait_on="$2" | |
14 create="" | |
15 if [ $# -eq 3 ]; then | |
16 create="$3" | |
17 fi | |
18 | |
19 if [ -n "$create" ]; | |
20 then | |
21 touch "$create" | |
22 create="" | |
23 fi | |
24 while [ "$timer" -gt 0 ] && [ ! -f "$wait_on" ]; | |
25 do | |
26 timer=$(( timer - 1)) | |
27 sleep 0.01 | |
28 done | |
29 if [ "$timer" -le 0 ]; then | |
30 echo "file not created after $1 seconds: $wait_on" >&2 | |
31 exit 1 | |
32 fi |