Runnable examples demonstrating sources of non-determinism in Go and how to handle them.
| 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 |
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 for336, 366, 378, 466, 121, 175, 192, 226, 329, 368, 385— this sequence appears in the exact same order across every iteration.
go test -v ./...