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(testutil): fix usage of reaper in exec_test.go #281

Merged
merged 1 commit into from
Aug 18, 2023

Conversation

benhoyt
Copy link
Contributor

@benhoyt benhoyt commented Aug 18, 2023

Currently TestFakeCommandWithReaper is half using the reaper: it's setting the withReaper flag to true, but not using reaper versions of the command-running functions. Do that. Also, only start/stop the reaper in the one test that needs it.

This should fix intermittent failures like this one:

START: exec_test.go:42: fakeCommandSuite.TestFakeCommand
using shellcheck: "/usr/bin/shellcheck"
exec_test.go:46:
    c.Assert(err, check.IsNil)
... value *os.SyscallError = &os.SyscallError{Syscall:"waitid", Err:0xa} ("waitid: no child processes")

FAIL: exec_test.go:42: fakeCommandSuite.TestFakeCommand

Currently TestFakeCommandWithReaper is half using the reaper: it's
setting the withReaper flag to true, but not using reaper versions of
the command-running functions. Do that. Also, only start/stop the
reaper in the one test that needs it.
@benhoyt benhoyt changed the title test(testutil): Fix usage of reaper in exec_test.go test(testutil): fix usage of reaper in exec_test.go Aug 18, 2023
@jnsgruk jnsgruk requested review from flotter and anpep August 18, 2023 09:01
@flotter
Copy link
Contributor

flotter commented Aug 18, 2023

@benhoyt I'm responsible for introducing the regression here. That was a massive oversight, sorry.

I now have a much better understanding of why this reaper option exist, so let me just capture this here for the next person running into issues using FakeCommand:

I only understand now ... FakeCommand was written to be useful both in environments where the reaper exist (such as servstate) and also environmnents without the reaper (other unit tests where the reaper is not implicitly enabled). The fundamental issue is that the Run() command (from Go exec) calls the syscall wait, to reap the child process, but so does the reaper with a hook using SIGCHILD. So both cannot be used at the same time, otherwise one syscall wait will fail to see the child. To be compatible with these environments, the shellcheck script (secretly running behind the scenes) must follow the strategy used by the caller (Run vs. Reaper).

Copy link
Contributor

@flotter flotter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect.

@jnsgruk jnsgruk merged commit 58ec377 into canonical:master Aug 18, 2023
13 checks passed
@benhoyt benhoyt deleted the fix-fakecommand-reaper branch August 20, 2023 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants