Issue Type: Bug Bug
Affects Versions: JRuby 1.7.0.RC2
Assignee: Unassigned
Components: Embedding
Created: 15/Oct/12 7:30 PM
Description:

We have various unit tests which instantiate a ScriptingContainer, run tests against it and then terminate it. Various other people report a similar issue of Errno::EBADF from JRuby when embedding it, but in their cases their issue was resolved by properly terminating the container. In our case, the test is already terminating the container during tearDown().

org.jruby.embed.EvalFailedException: (Errno::EBADF) Bad file descriptor
	at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:133)
	at org.jruby.embed.ScriptingContainer.runUnit(ScriptingContainer.java:1263)
	at org.jruby.embed.ScriptingContainer.runScriptlet(ScriptingContainer.java:1256)
	at com.acme.integration.vendor.jruby.TestScriptingContainer.runScriptlet(TestScriptingContainer.java:126)
	at com.acme.integration.vendor.jruby.TestScriptingContainer.testMiniTestAutoRun(TestScriptingContainer.java:60)
[omitting test framework stuff]
Caused by: org.jruby.exceptions.RaiseException: (Errno::EBADF) Bad file descriptor
	at org.jruby.RubyIO.write(org/jruby/RubyIO.java:1401)
	at org.jruby.RubyIO.write(org/jruby/RubyIO.java:2378)
	at org.jruby.RubyIO.puts(org/jruby/RubyIO.java:2333)
	at org.jruby.RubyKernel.puts(org/jruby/RubyKernel.java:552)
	at RUBY.(root)(<script>:7)

The common thing with all the tests is that they print output and then assert it once back in Java land. Here's an example of the sort of test we run (I just simplified the test itself down to print a literal value. Everything else is the same.)

ScriptingContainer container;
String errorOutput;
String output;

@Test
public void testNumber() throws Exception {
    runScriptlet("puts 3")
    assertEquals("Wrong result printed", "3", output.trim());
    assertEquals("Wrong result printed", "", errorOutput.trim());
}

private Object runScriptlet(String script) {
    StringWriter writer = new StringWriter();
    container.setWriter(writer);
    StringWriter errorWriter = new StringWriter();
    container.setErrorWriter(errorWriter);
    Object result = container.runScriptlet(script);
    output = writer.toString();
    errorOutput = errorWriter.toString();
    return result;
}

@Before
public void setUp() throws Exception {
    container = new ScriptingContainer();
}

@After
public void tearDown() throws Exception {
    if (container != null) {
        container.terminate();
    }
}

I have never seen the same sort failure in TestScriptEngine, which suggests that this is some kind of embedding issue specific to ScriptingContainer.

Project: JRuby
Priority: Minor Minor
Reporter: Trejkaz
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira
--------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email

Reply via email to