Generating a dump file when tests hang on a CI machine

 
 
  • Gérald Barré

I recently investigated an issue where tests were hanging on CI. Debugging locally is straightforward since you can attach a debugger and inspect what is happening. On CI, however, attaching a debugger is not an option, so I needed an alternative approach.

dotnet test has many useful options. One of them is --blame-hang, which creates a dump of the process and all child processes when a test hangs. You can configure the timeout and dump type, then upload the dump to your build artifacts for local analysis.

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

When a test hangs, it fails and produces at least two files: a dump file per process and a sequence file. The sequence file lists the tests that ran before the hang:

On a CI system such as GitHub Actions, you can upload the dump files as build artifacts:

.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?