Skip to content

Repository files navigation

Go Non-Determinism Examples

Runnable examples demonstrating sources of non-determinism in Go and how to handle them.

Examples

File Command Purpose
map_iteration_test.go go test -v -run TestMapIterationNonDeterminism Shows that map iteration order changes between iterations
map_iteration_safe_test.go go test -v -run TestMapIterationSafe Fix: sort keys before iterating for deterministic order
map_insertion_order_test.go go test -v -run TestMapInsertionOrderIteration Fix: track keys in a slice at insertion time to avoid sorting
map_clustering_test.go go test -v -run TestMapIterationClustering Proves that map iteration randomization is shallow — entries in the same group always cluster together
channel_select_test.go go test -v -run TestChannelSelectNonDeterminism Shows that select picks randomly among ready channels

Reference Data

  • iteration_orders.txt — Raw iteration orders from the clustering test. Each line is one full iteration over a 512-entry map, showing how entries cluster by group. Try searching for 336, 366, 378, 466, 121, 175, 192, 226, 329, 368, 385 — this sequence appears in the exact same order across every iteration.

Run all

go test -v ./...

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages