Skip to content

Commit

Permalink
TESTS: Improve Gradle Test Configuration
Browse files Browse the repository at this point in the history
* `clean` actually cleans all dynamically created files, in particular it now properly cleans the generated Gemfile so
that changes to the Gemfile.template reflect in a rerun of `bundler`
* `rubyTests` and `test` are now one-off and will automatically bootstrap JRuby and Gems required by the tests if necessary
* Fixed Readme to document the now much simpler test targets
* All rake tasks remain unchanged and still work exactly as they did before

Fixes elastic#8583
  • Loading branch information
original-brownbear committed Nov 6, 2017
1 parent 86e3cd2 commit c8d704c
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RUN /opt/logstash/gradlew wrapper
ADD versions.yml /opt/logstash/versions.yml
ADD LICENSE /opt/logstash/LICENSE
ADD CONTRIBUTORS /opt/logstash/CONTRIBUTORS
ADD Gemfile.template /opt/logstash/Gemfile
ADD Gemfile.template /opt/logstash/Gemfile.template
ADD Rakefile /opt/logstash/Rakefile
ADD build.gradle /opt/logstash/build.gradle
ADD rakelib /opt/logstash/rakelib
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,20 @@ Most of the unit tests in Logstash are written using [rspec](http://rspec.info/)

### Core tests

1- In order to run the core tests, a small set of plugins must first be installed:
1- To run the core tests you can use the Gradle task:

rake test:install-core

2- To run the core tests you can use the rake task:

rake test:core
./gradlew test

or use the `rspec` tool to run all tests or run a specific test:

bin/rspec
bin/rspec spec/foo/bar_spec.rb

3- To run the subset of tests covering the Java codebase only run:
Note that before running the `rspec` command for the first time you need to set up the RSpec test dependencies by running:

./gradlew bootstrap

2- To run the subset of tests covering the Java codebase only run:

./gradlew javaTests

Expand Down
36 changes: 35 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,24 @@ if (versionMap["jruby-runtime-override"]) {
}

// Tasks

clean {
delete "${projectDir}/Gemfile"
delete "${projectDir}/Gemfile.lock"
delete "${projectDir}/vendor"
delete "${projectDir}/NOTICE.TXT"
}

task bootstrap {}

project(":logstash-core") {
["rubyTests", "test"].each { tsk ->
tasks.getByPath(":logstash-core:" + tsk).configure {
dependsOn bootstrap
}
}
}

task downloadJRuby(type: Download) {
description "Download JRuby artifact from this specific URL: ${jRubyURL}"
src jRubyURL
Expand All @@ -108,6 +124,8 @@ task verifyFile(dependsOn: downloadJRuby, type: Verify) {

task downloadAndInstallJRuby(dependsOn: verifyFile, type: Copy) {
description "Install JRuby in the vendor directory"
inputs.files file("${projectDir}/versions.yml")
outputs.files fileTree("${projectDir}/vendor/jruby")
from tarTree(downloadJRuby.dest)
eachFile { f ->
f.path = f.path.replaceFirst("^jruby-${jRubyVersion}", '')
Expand All @@ -117,6 +135,22 @@ task downloadAndInstallJRuby(dependsOn: verifyFile, type: Copy) {
into "${projectDir}/vendor/jruby"
}

task installTestGems(dependsOn: downloadAndInstallJRuby, type: Exec) {
workingDir projectDir
inputs.files file("${projectDir}/Gemfile.template")
inputs.files fileTree("${projectDir}/rakelib")
inputs.files file("${projectDir}/versions.yml")
outputs.files file("${projectDir}/Gemfile")
outputs.files file("${projectDir}/Gemfile.lock")
outputs.files fileTree("${projectDir}/vendor/bundle/gems")
outputs.files fileTree("${projectDir}/vendor/jruby")
commandLine './vendor/jruby/bin/jruby', "${projectDir}/vendor/jruby/bin/rake".toString(), "test:install-core"
standardOutput = new ByteArrayOutputStream()
ext.output = {
standardOutput.toString()
}
}

// If you are running a JRuby snapshot we will skip the integrity check.
verifyFile.onlyIf { doChecksum }
bootstrap.dependsOn downloadAndInstallJRuby
bootstrap.dependsOn installTestGems
9 changes: 1 addition & 8 deletions ci/unit_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,12 @@ if [[ $SELECTED_TEST_SUITE == $"core-fail-fast" ]]; then
echo "Running test:core-fail-fast"
rake test:core-fail-fast
elif [[ $SELECTED_TEST_SUITE == $"java" ]]; then
echo "Running Java unit tests"
echo "Running Java Tests"
./gradlew javaTests
elif [[ $SELECTED_TEST_SUITE == $"ruby" ]]; then
echo "Running Ruby unit tests"
echo "Running test:install-core"
rake test:install-core
echo "Running Ruby Tests"
./gradlew rubyTests
else
echo "Running Java and Ruby unit tests"
echo "Running test:install-core"
rake test:install-core
echo "Running test:core"
rake test:core
./gradlew test
fi
2 changes: 1 addition & 1 deletion rakelib/vendor.rake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace "vendor" do
end

task "jruby" do |task, args|
system('./gradlew bootstrap')
system('./gradlew downloadAndInstallJRuby')
end # jruby

task "all" => "jruby"
Expand Down

0 comments on commit c8d704c

Please sign in to comment.