Skip to content

KAFKA-17479 Fail the whole pipeline if junit step times out [4/n]#17121

Merged
mumrah merged 13 commits into
trunkfrom
gh-fix-junit-timeout
Sep 7, 2024
Merged

KAFKA-17479 Fail the whole pipeline if junit step times out [4/n]#17121
mumrah merged 13 commits into
trunkfrom
gh-fix-junit-timeout

Conversation

@mumrah

@mumrah mumrah commented Sep 6, 2024

Copy link
Copy Markdown
Member

Follow up from #17106, this patch fixes a bug in the workflow where the tests timeout but no JUnit errors are found. Since the test report is incomplete, this is a false positive for a build being green. We should fail the whole workflow if the JUnit tests timeout.

@mumrah mumrah added the build Gradle build or GitHub Actions label Sep 6, 2024
@mumrah
mumrah force-pushed the gh-fix-junit-timeout branch from 173da2f to 042b94c Compare September 6, 2024 21:09
@mumrah
mumrah force-pushed the gh-fix-junit-timeout branch from 042b94c to 380192c Compare September 6, 2024 21:11
@mumrah

mumrah commented Sep 6, 2024

Copy link
Copy Markdown
Member Author

I have tested the timeout case on mumrah/kafka here https://github.com/mumrah/kafka/actions/runs/10745303070/job/29804106047?pr=13#step:6:71

This is a perfect example since we do actually see some test reports being processed

Did not find done file 'build/junit-xml/done'. These are partial results!
1057 tests cases run in 31s. 1057 PASSED ✅, 0 FAILED ❌, 0 FLAKY ⚠️ , 0 SKIPPED 🙈, and 0 errors.
Failing this step because done file was missing.

The timeout error is coalesced into the Parse JUnit Tests step:

image

And, most importantly, the link from the PR takes us to the JUnit summary instead of the actual Test step. This is important because the Test step usually has 10s of thousands of log lines and often gets truncated in the UI. Linking to the summary step is much more user friendly.

Screen.Recording.2024-09-06.at.5.32.07.PM.mp4

@mumrah
mumrah requested a review from chia7712 September 6, 2024 21:34

@chia7712 chia7712 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mumrah thanks for this patch. one small question PTAL

Comment thread .github/scripts/junit.py Outdated

parser.add_argument("--done-file",
required=False,
default="",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of curiosity, why not set default value like build/junit-xml/done?

@mumrah mumrah Sep 7, 2024

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted this to be an optional argument so its easier to test locally. I don't feel too strongly about this, either way seems fine

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "--path" has default value, so that is why I raise this comment 😃

For another trivial reason, we can simplify the command passed to junit parser if it has default value.

@mumrah

mumrah commented Sep 7, 2024

Copy link
Copy Markdown
Member Author

Adding a finalizer to the default "test" task did not work as expected. I can't find a simple way to add task to run after all the subproject ":test" tasks, so I changed this to have the GH workflow explicitly call createDoneFile

@chia7712

chia7712 commented Sep 7, 2024

Copy link
Copy Markdown
Member

Adding a finalizer to the default "test" task did not work as expected. I can't find a simple way to add task to run after all the subproject ":test" tasks, so I changed this to have the GH workflow explicitly call createDoneFile

Could we check the create time of build/.../xml instead?

  1. If there is no xml file -> timeout
  2. If any xml's creation time is too old -> timeout

@mumrah

mumrah commented Sep 7, 2024

Copy link
Copy Markdown
Member Author

Could we check the create time of build/.../xml instead?

The trouble is, we may have some of the copied XML files, but not all of them. For example, if all the tests finished except for :core we would have several XML files in build/junit-xml, but not any from core.


The whole problem we're working around here is that there's no easy way to distinguish between a timeout and some other failure in a GitHub step (a major limitation, IMO). Another solution could be to use the Linux timeout command to do our own timeout. With this approach, we just watch for a particular exit code from timeout to determine if Gradle had an error or if it timed out.

It would be something like:

timeout 180 ./gradlew ...
RET=$?
if [[ $RET == 124 ]]; then 
  echo "timed out";
elif [[ $RET == 0 ]]; then 
  echo "ok"; 
else 
  echo "failed"; 
fi

Maybe we could capture the exit code and store it as a step output to be read by the Parse JUnit step. WDYT?

@chia7712

chia7712 commented Sep 7, 2024

Copy link
Copy Markdown
Member

The trouble is, we may have some of the copied XML files, but not all of them. For example, if all the tests finished except for :core we would have several XML files in build/junit-xml, but not any from core.

I meant we can check creation time of xml file (from finished tests) in parsing and throw error if one of them has "too old" creation time.

Maybe we could capture the exit code and store it as a step output to be read by the Parse JUnit step. WDYT?

Sound good. Overall it would be better to avoid complicating build.gradle 😄

@mumrah
mumrah requested a review from chia7712 September 7, 2024 15:55
@mumrah

mumrah commented Sep 7, 2024

Copy link
Copy Markdown
Member Author

@chia7712 I took advice from this thread https://github.com/orgs/community/discussions/46992#discussioncomment-4961541 to capture the exit code. I tested it with a 5s timeout here https://github.com/apache/kafka/actions/runs/10752630233/job/29821166851, seems to work.

I think this is a better solution than fiddling with files.

@chia7712 chia7712 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but it would be better to test timeout again before merging :)

@mumrah
mumrah merged commit 040ae26 into trunk Sep 7, 2024
@mumrah
mumrah deleted the gh-fix-junit-timeout branch September 9, 2024 17:00
tedyu pushed a commit to tedyu/kafka that referenced this pull request Jan 6, 2025
…ache#17121)

Fixes an issue where the CI workflow could appear to be successful in the event of a timeout and no failing tests. Instead of using Github Action's timeout, this patch makes use of the linux `timeout` command. This lets us capture the exit code and handle timeouts separately from a failed execution.

Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Gradle build or GitHub Actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants