logstash icon indicating copy to clipboard operation
logstash copied to clipboard

Avoid to run rspec tests directly from Gradle script

Open andsel opened this issue 2 years ago • 1 comments

Running rubyTests with JDK 21 exposes the error:

            should end at the number of generated events (FAILED - 3)
    [2024-02-01T14:18:25,583][ERROR][logstash.javapipeline    ] Pipeline error {:pipeline_id=>"main", :exception=>#<ArgumentError: wrong number of arguments (given 1, expected 0)>, 
:backtrace=>[
"/Users/andrea/workspace/logstash_andsel/logstash-core/lib/logstash/config/lir_serializer.rb:47:in `vertices'", 
"/Users/andrea/workspace/logstash_andsel/logstash-core/lib/logstash/config/lir_serializer.rb:36:in `serialize'", 
"/Users/andrea/workspace/logstash_andsel/logstash-core/lib/logstash/config/lir_serializer.rb:27:in `serialize'", 
"/Users/andrea/workspace/logstash_andsel/logstash-core/lib/logstash/java_pipeline.rb:268:in `start_workers'", 
"/Users/andrea/workspace/logstash_andsel/logstash-core/lib/logstash/java_pipeline.rb:194:in `run'", 
"/Users/andrea/workspace/logstash_andsel/logstash-core/lib/logstash/java_pipeline.rb:146:in `block in start'"
], 
"pipeline.sources"=>[], :thread=>"#<Thread:0x5e2f743e /Users/andrea/workspace/logstash_andsel/logstash-core/lib/logstash/java_pipeline.rb:134 run>"}

To reproduce consider the PR #15719, after set system java to a JDK 21, run with:

SPEC_OPTS="-fd -P logstash-core/spec/logstash/pipeline_reporter_spec.rb" ./gradlew :logstash-core:rubyTests --tests org.logstash.RSpecTests --rerun-tasks

The problem happens at https://github.com/elastic/logstash/blob/8ac55184b8a9d22dea8f61f287a3cd21440fda39/logstash-core/lib/logstash/config/lir_serializer.rb#L47

Where getVertices returns a LinkedHashSet. This error was isolated in JRuby issue https://github.com/jruby/jruby/issues/8061, however originates from the fact that Logstash's rubyTests Gradle tasks, executes a JRuby script engine within the Gradle process itself:

  • https://github.com/elastic/logstash/blob/8ac55184b8a9d22dea8f61f287a3cd21440fda39/logstash-core/build.gradle#L146
  • https://github.com/elastic/logstash/blob/8ac55184b8a9d22dea8f61f287a3cd21440fda39/logstash-core/src/test/java/org/logstash/RSpecTests.java#L67

This issue asks to switch the execution of rubyTest into a separated process, outside of the Gradle daemon, so that the test environment could be more close to what the real environment is, without interference of Gradle internals itself.

andsel avatar Feb 01 '24 13:02 andsel

/cc @roaksoax @jsvd

andsel avatar Feb 01 '24 13:02 andsel