Skip to content

Output unreliable from spawned processes #779

@dmarcotte

Description

@dmarcotte

(This is probably a known issue, but I didn't see a issue for it. I wanted to document it here so that I can refer to in the tags I'm going to add to the specs it affects.)

There seems to be a race to capture the output of spawned processes in the tests. The race is lost much more often on Linux, but can also manifest itself on Mac.

Looking at the code, it smells like this might be due to how the output_to_fd matcher works in combination with the known race conditions which also lead to the inappropriate echild errors. Haven't been able to prove that yet though...

Anyhow, here's a summary of how exactly this manifests in the tests:

Here's a case from Travis where the output goes to the test's stdout rather than being consumed by the test
(from this log). Note how the foo the test is outputting is appended to the test output (element to a Stringfoo) rather than being received by the test matcher, which gets "":

[java] Kernel#spawn with a command array
[java] - does not subject the arguments to shell expansion
[java] - preserves whitespace in passed arguments
[java] - calls #to_str to convert the first element to a String
[java] - calls #to_str to convert the second element to a Stringfoo
[java]  (FAILED - 1)
    ---SNIP---
[java] 1)
[java] Kernel#spawn with a command array calls #to_str to convert the second element to a String FAILED
[java] Expected (STDOUT): "foo\n"
[java]           but got: ""

Alternatively, there are also cases where a previous test's output is still around to be consumed by the next test (from this log). Note how the directory listing which is the output of subjects the specified command to shell expansion (which passed) interferes with the foo that calls #to_str to convert the argument to a String is trying to validate:

[java] Process.spawn with a single argument
[java] - subjects the specified command to shell expansion
[java] - calls #to_str to convert the argument to a String (FAILED - 1)
    ---SNIP---
[java] 1)
[java] Process.spawn with a single argument calls #to_str to convert the argument to a String FAILED
[java] Expected (STDOUT): "foo\n"
[java]          but got: "COPYING LEGAL LICENSE.RUBY README.md Rakefile antlib bench bin build build.xml build_lib cext default.build.properties docs docs.iml findbugs.xml gems install ivy jruby-common.iml jruby-complete.iml jruby-core.iml jruby-dist.iml jruby-rake-plugin.iml jruby-stdlib.iml jruby.bnd.template jruby.iml lib man.iml maven nbproject netbeans-ant.xml pom.xml rakelib rubyspec_temp samples shared.iml spec spi src test tool\nfoo\n"

Hopefully that isn't too verbose and helps a bit... a pull tagging specs which are susceptible to this is on its way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions