Skip to content

Commit

Permalink
Allow running Java+Ruby tests on Windows separately
Browse files Browse the repository at this point in the history
This commit allows separate running of Java and Ruby tests on Windows
i.e. the same way as we currently do on unix (`unit_tests.sh`)
via a cli argument.

If no argument has been supplied, both tests are run (as it does now).

The wrapper script is also rewritten from old batch style script to
powershell.

Relates elastic#15566
  • Loading branch information
dliappis committed Jan 26, 2024
1 parent 9317052 commit 2ca189b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .buildkite/scripts/exhaustive-tests/generate-steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def compat_linux_step(imagesuffix: str) -> dict[str, typing.Any]:


def compat_windows_step(imagesuffix: str) -> dict[str, typing.Any]:
windows_command = LiteralScalarString(r'''$$env:WORKSPACE=$$PWD.Path ; .\\ci\\unit_tests.bat''')
windows_command = LiteralScalarString(r'''.\\ci\\unit_tests.ps1''')

return compat_step(imagesuffix, command=windows_command)

Expand Down
3 changes: 0 additions & 3 deletions .buildkite/scripts/jdk-matrix-tests/launch-command.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ param (
# expand previous buildkite folded section (command invocation)
Write-Host "^^^ +++"

# the unit test script expects the WORKSPACE env var
$env:WORKSPACE = $PWD.Path

# unset generic JAVA_HOME
if (Test-Path env:JAVA_HOME) {
Remove-Item -Path env:JAVA_HOME
Expand Down
56 changes: 0 additions & 56 deletions ci/unit_tests.bat

This file was deleted.

58 changes: 58 additions & 0 deletions ci/unit_tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<#
.SYNOPSIS
This is a gradle wrapper script to help run the Logstash unit tests on Windows.
.PARAMETER UnnamedArgument1
Optionally allows to specify a subset of tests.
Allows values are "ruby" or "java".
If unset, all tests are executed.
.EXAMPLE
.\ci\unit_tests.ps1
Runs all unit tests.
.\ci\unit_tests.ps1 java
Runs only Java unit tests.
#>

$selectedTestSuite="all"

if ($args.Count -eq 1) {
$selectedTestSuite=$args[0]
}

if (Test-Path Env:BUILD_JAVA_HOME) {
if (Test-Path Env:GRADLE_OPTS) {
$env:GRADLE_OPTS=$env:GRADLE_OPTS + " " + "-Dorg.gradle.java.home=" + $env:BUILD_JAVA_HOME
} else {
$env:GRADLE_OPTS="-Dorg.gradle.java.home=" + $env:BUILD_JAVA_HOME
}
}

$testOpts = "GRADLE_OPTS: $env:GRADLE_OPTS, BUILD_JAVA_HOME: $env:BUILD_JAVA_HOME"

try {
if ($selectedTestSuite -eq "java") {
Write-Host "~~~ :java: Running Java tests via Gradle using $testOpts"
$CIScript = ".\gradlew.bat javaTests --console=plain --no-daemon --info"
Invoke-Expression $CIScript
}
elseif ($selectedTestSuite -eq "ruby") {
Write-Host "~~~ :ruby: Running Ruby tests via Gradle using $testOpts"
$CIScript = ".\gradlew.bat rubyTests --console=plain --no-daemon --info"
Invoke-Expression $CIScript
}
else {
Write-Host "~~~ 🧪 Running all tests via Gradle using $testOpts"
$CIScript = ".\gradlew.bat test --console=plain --no-daemon --info"
Invoke-Expression $CIScript
}

if ($LASTEXITCODE -ne 0) {
throw "Test script $CIScript failed with a non-zero code: $LASTEXITCODE"
}
} catch {
# tests failed
Write-Host "^^^ +++"
exit 1
}

0 comments on commit 2ca189b

Please sign in to comment.