-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change to handle timeout correctly and prevent zombie processes and b…
…roken pipes
- Loading branch information
1 parent
56a8371
commit 9dee32b
Showing
3 changed files
with
55 additions
and
25 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
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# encoding: utf-8 | ||
|
||
RSpec.describe TTY::Command, '#run' do | ||
|
||
it "times out after a specified period" do | ||
output = StringIO.new | ||
cmd = TTY::Command.new(output: output) | ||
expect { | ||
cmd.run("while test 1; do echo 'hello'; sleep 0.1; done", timeout: 0.1) | ||
}.to raise_error(TTY::Command::ExitError) | ||
end | ||
|
||
it "reads user input data until timeout" do | ||
cli = tmp_path('cli') | ||
output = StringIO.new | ||
cmd = TTY::Command.new(output: output) | ||
|
||
expect { | ||
cmd.run(cli, input: "Piotr\n", timeout: 0.01) | ||
}.to raise_error(TTY::Command::ExitError) | ||
end | ||
end |