Generating a dump file when tests hang on a CI machine

 
 
  • Gérald Barré

I recently investigated an issue where the tests hang on the CI. It's easier to debug when issues happen on your machine as you can easily attach a debugger and see what's going on. But in this case, the tests were hanging on the CI and I couldn't attach a debugger. I had to find an alternative way to debug the issue.

dotnet test has many useful options. One of them is --blame-hang which creates a dump of the process and all the child processes when a test hangs. You can configure the desired timeout and the kind of dump you want to take. Then, you can upload the dump to the build artifacts and analyze it locally.

Shell
dotnet test --blame-hang-timeout 5m --blame-hang-dump-type full

If a test hangs, it will fail and output at least two files: a dump file per process and a sequence file. The sequence file contains the list of tests that were executed before the hang:

If you are on a CI such as GitHub Actions, you can upload the dump file as an artifact:

.github/workflows/sample.yml (YAML)
name: sample
on:
  workflow_dispatch:
  push:
    branches:
      - '*'

jobs:
  run_test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - name: Run tests
      run: dotnet test a.sln --configuration Debug --blame-hang-timeout 30s

    - uses: actions/upload-artifact@v3
      if: always()
      with:
        name: results
        retention-days: 1
        path: TestResults/**/*

#Additional resources

Do you have a question or a suggestion about this post? Contact me!

Follow me:
Enjoy this blog?Buy Me A Coffee💖 Sponsor on GitHub