Artifact 1985b98aeb0e055e3e081b5939606c217b7ab35c524b5620dc0a8300ba1d1bb6:
- File
simio/buggify_test.go
— part of check-in
[f5744359d3]
at
2026-04-19 16:30:54
on branch trunk
— Initial open source release
libfossil is a pure-Go implementation of the Fossil SCM, reading and writing the same .fossil SQLite repository format as upstream Fossil.
This is the first public release of code that previously lived in a private repository. The module path is github.com/danmestas/libfossil and the binary is named libfossil to avoid $PATH collisions with upstream fossil.
Included: - Repo lifecycle (create, clone), checkout/checkin, timeline, merge, diff, annotate, shun, tag, branch, bisect, stash, undo/redo - Sync-over-HTTP protocol (client and handler) - Two SQLite drivers: modernc (pure Go, default) and ncruces (wasm-capable) - Observer interfaces (SyncObserver, CheckoutObserver) with an optional OpenTelemetry implementation in observer/otel (separate submodule) - Deterministic simulation testing harness with BUGGIFY fault injection - Kong-based embeddable CLI under cli/ and a standalone binary under cmd/libfossil/ (user: [email protected], size: 1259) [annotate] [blame] [check-ins using]
package simio import "testing" func TestBuggifyDisabledByDefault(t *testing.T) { // Should never fire when not enabled. for range 1000 { if Buggify(1.0) { t.Fatal("Buggify fired when not enabled") } } } func TestBuggifyEnabledFires(t *testing.T) { EnableBuggify(42) defer DisableBuggify() // With probability 1.0, should always fire. if !Buggify(1.0) { t.Fatal("Buggify(1.0) should always fire when enabled") } // With probability 0.0, should never fire. if Buggify(0.0) { t.Fatal("Buggify(0.0) should never fire") } } func TestBuggifyDeterministic(t *testing.T) { run := func(seed int64) int { EnableBuggify(seed) defer DisableBuggify() count := 0 for range 1000 { if Buggify(0.5) { count++ } } return count } c1 := run(99) c2 := run(99) if c1 != c2 { t.Fatalf("non-deterministic: %d vs %d", c1, c2) } // Different seed should produce different count (with high probability). c3 := run(7) if c1 == c3 { t.Logf("WARNING: different seeds produced same count %d (unlikely)", c1) } } func TestBuggifyDisableStops(t *testing.T) { EnableBuggify(1) if !Buggify(1.0) { t.Fatal("should fire when enabled") } DisableBuggify() if Buggify(1.0) { t.Fatal("should not fire after disable") } }