GCT helps find concurrency bugs in Go programs by taking control of goroutine scheduling during tests. It can explore alternative schedules, record failures, and replay them deterministically, making flaky schedule-dependent bugs easier to reproduce and debug.
Install the gct command from this checkout:
go install ./cmd/gctMake sure Go's command install directory is on your PATH:
export PATH="$(go env GOPATH)/bin:$PATH"Instrument a target package:
gct instrument ./...Run tests under GCT:
gct test ./...Replay a recorded schedule:
gct replay trace.logGCT currently uses random_walk as the default scheduler and writes schedules to trace.log.
GitHub issue about the demo test case: etcd-io/etcd#15666
Install Go as instructed on https://go.dev/doc/install
git clone https://github.com/focs-lab/gct.git
cd gct
go mod tidygit clone https://github.com/etcd-io/etcd.git
cd etcd
git checkout f7af6b64bcd client/v3
go test -vet=off -run TestTxnPanicsYou should see that the test passes. Now, try running this test multiple times:
for i in {1..10}; do go test -vet=off -run TestTxnPanics || break; done;Back to the GCT main directory
cd ../../..
go run ./cmd/gct instrument etcd/client/v3_CCT_TRACE_LOC=trace.log _CCT_SCHEDULER_NAME=random_walk _CCT_RECORD_FLAG=true go test -vet=off -run TestTxnPanicsOr use the CLI from the instrumented package directory:
gct test -vet=off -run TestTxnPanics_CCT_TRACE_LOC=trace.log _CCT_SCHEDULER_NAME=replay _CCT_RECORD_FLAG=true go test -vet=off -run TestTxnPanicsOr use the CLI from the instrumented package directory:
gct replay trace.log -vet=off -run TestTxnPanics