Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Merge #7523
Browse files Browse the repository at this point in the history
7523: Fix rspec stuck problem for large stderr external command r=deivid-rodriguez a=kou

### What was the end-user problem that led to this PR?

This PR doesn't fix any end-user problem.

This PR just fixes a developer problem.

Some specs runs external commands by `sys_exec` in `spec/support/helpers.rb`. They may be stuck when they outputs many text to its stderr.

### What was your diagnosis of the problem?

`sys_exec` uses `open3`. It uses pipe to communicate an external command. If `rspec` process doesn't read stderr of the external command, the external command is stuck when the external command writes many text to its stderr. Because the external command can't write to pipe infinitely.

### What is your fix for the problem, implemented in this PR?

The current `sys_exec` tries to fix this situation but it's incomplete:

```ruby
        command_execution.stdout = Thread.new { stdout.read }.value.strip
        command_execution.stderr = Thread.new { stderr.read }.value.strip
```

`Thread.new { stderr.read ` isn't started until `Thread.new { stdout.read }.value` is finished. Normally, it's finished when the external command is finished. It's late. We should read stderr of the external command while the external command is alive.

### Why did you choose this fix out of the possible options?

I don't have another option.


Co-authored-by: Sutou Kouhei <[email protected]>
  • Loading branch information
bundlerbot and kou committed Dec 31, 2019
2 parents 984bef1 + 026e633 commit 8917d9d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions spec/support/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,10 @@ def sys_exec(cmd, env = {})
yield stdin, stdout, wait_thr if block_given?
stdin.close

command_execution.stdout = Thread.new { stdout.read }.value.strip
command_execution.stderr = Thread.new { stderr.read }.value.strip
stdout_read_thread = Thread.new { stdout.read }
stderr_read_thread = Thread.new { stderr.read }
command_execution.stdout = stdout_read_thread.value.strip
command_execution.stderr = stderr_read_thread.value.strip
command_execution.exitstatus = wait_thr && wait_thr.value.exitstatus
end

Expand Down

0 comments on commit 8917d9d

Please sign in to comment.