Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test:Capture output on fork test failures #3052

Merged
merged 1 commit into from
Aug 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion spec/support/synchronization_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,24 @@ def expect_in_fork(fork_expectations: nil, timeout_seconds: 10)
# Enforce timeout to ensure test fork doesn't hang the test suite.
_, status = try_wait_until(seconds: timeout_seconds) { Process.wait2(pid, Process::WNOHANG) }

stdout = File.read(fork_stdout.path)
stderr = File.read(fork_stderr.path)

# Capture forked execution information
result = { status: status, stdout: File.read(fork_stdout.path), stderr: File.read(fork_stderr.path) }
result = { status: status, stdout: stdout, stderr: stderr }

# Expect fork and assertions to have completed successfully.
fork_expectations.call(**result)

result
rescue => e
stdout ||= File.read(fork_stdout.path)
stderr ||= File.read(fork_stderr.path)

puts stdout
warn stderr

raise e
ensure
fork_stdout.unlink
fork_stderr.unlink
Expand Down
Loading