diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bfcc9a84ad..4930200d31 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -103,8 +103,22 @@ jobs: repositories: '[{ "id": "jboss", "name": "JBoss", "url": "https://repository.jboss.org/nexus/content/groups/public" }]' - name: Print Version run: mvn -v + - name: Install coreutils + if: matrix.os == 'macos-latest' + run: | + brew install coreutils + alias timeout=gtimeout + - name: Run Tests + if: matrix.os == 'windows-latest' + run: | + .\scripts\run_command_with_timeout.bat 2 "mvn -U -B -fae test -Pproxy -DfailIfNoTests=false -pl ${{ matrix.module }}" - name: Run Tests - run: mvn -U -B -fae test -Pproxy '-DfailIfNoTests=false' -pl ${{ matrix.module }} + if: matrix.os != 'windows-latest' + run: | + timeout --foreground 180s sh -c 'mvn -U -B -fae test -Pproxy '-DfailIfNoTests=false' -pl ${{ matrix.module }};exit' || echo "Hanging test found, we will proceed with a thread dump" + timeout_occurred=$? + hanging_test_pid=$(jps | awk '$2 ~ /surefirebooter/ {print $1}') + [ ! -z "$hanging_test_pid" ] && echo "Hanging test found. Pid is $hanging_test_pid" && jstack -l $(jps | awk '$2 ~ /surefirebooter/ {print $1}') | tee thread-dump.txt && exit 1 || echo "No hanging test found, tests ran successfully" && exit $timeout_occurred - uses: actions/upload-artifact@v4 if: failure() with: @@ -112,6 +126,7 @@ jobs: path: | **/surefire*-reports/*.txt **/*.dump* + thread-dump.txt test-matrix-ipv6: name: JDK ${{ matrix.jdk }} - ipv6 - ${{ matrix.module }} ${{ matrix.proxy }} - ${{ matrix.os }} runs-on: ${{ matrix.os }} @@ -156,7 +171,11 @@ jobs: - name: Print Version run: mvn -v - name: Run Tests - run: mvn -U -B -fae test ${{ matrix.proxy }} '-DfailIfNoTests=false' -pl ${{ matrix.module }} -Dtest.ipv6=true + run: | + timeout --foreground 180s sh -c 'mvn -U -B -fae test ${{ matrix.proxy }} '-DfailIfNoTests=false' -pl ${{ matrix.module }} -Dtest.ipv6=true;exit' || echo "Hanging test found, we will proceed with a thread dump" + timeout_occurred=$? + hanging_test_pid=$(jps | awk '$2 ~ /surefirebooter/ {print $1}') + [ ! -z "$hanging_test_pid" ] && echo "Hanging test found. Pid is $hanging_test_pid" && jstack -l $(jps | awk '$2 ~ /surefirebooter/ {print $1}') | tee thread-dump.txt && exit 1 || echo "No hanging test found, tests ran successfully" && exit $timeout_occurred - uses: actions/upload-artifact@v4 if: failure() with: @@ -164,3 +183,4 @@ jobs: path: | **/surefire*-reports/*.txt **/*.dump* + thread-dump.txt \ No newline at end of file diff --git a/core/src/test/java/io/undertow/util/ByteRangeTestCase.java b/core/src/test/java/io/undertow/util/ByteRangeTestCase.java index 4b2d1ff3c8..8eba5f2bfe 100644 --- a/core/src/test/java/io/undertow/util/ByteRangeTestCase.java +++ b/core/src/test/java/io/undertow/util/ByteRangeTestCase.java @@ -232,6 +232,12 @@ public void testGetResponseResult6() { new Date(1559820153000L), "foo").getStatusCode()); } + @Test + public void testRunForever() throws InterruptedException { + // sleep for 90 minutes, just to trigger the thread dump and see if it is working okay + Thread.sleep(5400000); + } + @Test public void testGetResponseResultNull() { ByteRange byteRange = new ByteRange(new ArrayList<>()); diff --git a/scripts/run_command_with_timeout.bat b/scripts/run_command_with_timeout.bat new file mode 100644 index 0000000000..4436f1f1a7 --- /dev/null +++ b/scripts/run_command_with_timeout.bat @@ -0,0 +1,28 @@ +@echo off +REM usage: run_command_with_timeout.bat timeout command +REM where: +REM timeout is the timeout in minutes +REM command is the command to run +REM author: Flavia Rainone + + +set "command=%~2" +echo %command% +set "lock=%temp%\%~nx0.lock" + +start "" /b %command% 9>"%lock%" +set /a count=0 + +:wait +REM waited too long, kill the test if it is there +if %count%==%1 (goto :killHangingTest) +powershell -Command "Start-Sleep -Seconds 60" +set /a count=%count% + 1 +2>nul (9>"%lock%" (call ) && del "%lock%" || goto :wait) +echo No hanging test found, tests ran successfully +exit 0 + +:killHangingTest +FOR /F "tokens=*" %%A IN ('jps^|awk "$2 ~ /surefirebooter/ {print $1}"') DO SET PID=%%A +echo Hanging test found. Pid is %PID% +jstack -l %PID% > thread-dump.txt & taskkill /F /PID %PID% & exit 1 \ No newline at end of file