-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It blocks until a background process prints a matching line to stdout. Any given env var names are set to the subexpression strings as well. This is useful to wait for a background process to be ready before running more commands to interact with it, such as waiting for an HTTP server to listen on a TCP port before sending it the first request. In fact, our interrupt tests already had this problem; we only worked around it by having the process create a file when it's ready, and adding a custom command which would wait for the file by polling. It's much nicer and faster to use waitmatch instead, and as a bonus, we can refactor existing tests rather than adding more.
- Loading branch information
Showing
5 changed files
with
159 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,20 @@ | ||
[windows] skip | ||
|
||
signalcatcher & | ||
waitfile catchsignal | ||
# Start a background process, wait for it to be ready by printing a line, | ||
# send it an interrupt to stop, and wait for it to stop. | ||
|
||
signalcatcher &sigc& | ||
waitmatch sigc '^Ready to catch signals; the magic word is (.*)$' MAGIC_WORD | ||
printargs ${MAGIC_WORD} | ||
cmp stdout args.want | ||
|
||
interrupt | ||
wait | ||
stdout 'caught interrupt' | ||
# Make sure the entire stdout still contains what waitmatch read. | ||
cmp stdout stdout.want | ||
|
||
-- args.want -- | ||
["printargs" "Huzzah!"] | ||
-- stdout.want -- | ||
Ready to catch signals; the magic word is Huzzah! | ||
caught interrupt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Let testscript stop signalcatcher at the end of the testscript. | ||
|
||
signalcatcher & | ||
waitfile catchsignal | ||
signalcatcher &sigc& | ||
waitmatch sigc '^Ready to catch signals' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters