Skip to content

Instantly share code, notes, and snippets.

@leonj1
Created May 3, 2017 11:16
Show Gist options
  • Save leonj1/4ad522b593e65c6e930b828c88dd0b08 to your computer and use it in GitHub Desktop.
Save leonj1/4ad522b593e65c6e930b828c88dd0b08 to your computer and use it in GitHub Desktop.
Stress test your Go packages
Source: https://dave.cheney.net/2013/06/19/stress-test-your-go-packages
Stress test your Go packages
This is a short post on stress testing your Go packages.
Concurrency or memory correctness errors are more likely to show up
at higher concurrency levels (higher values of GOMAXPROCS).
I use this script when testing my packages, or when reviewing code that goes into the standard library.
#!/usr/bin/env bash -e
go test -c
# comment above and uncomment below to enable the race builder
# go test -c -race
PKG=$(basename $(pwd))
while true ; do
export GOMAXPROCS=$[ 1 + $[ RANDOM % 128 ]]
./$PKG.test $@ 2>&1
done
I keep this script in $HOME/bin so usage is
$ cd $SOMEPACKAGE
$ stress.bash
PASS
PASS
PASS
You can pass additional arguments to your test binary on the command line,
stress.sh -test.v -test.run=ThisTestOnly
The goal is to be able to run the stress test for as long as you want without a test failure.
Once you achieve that, uncomment go test -c -race and try again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment