fix(dedup): use deterministic seed in TestChunker_ShiftedData
Some checks failed
CI/CD / Test (push) Successful in 1m18s
CI/CD / Lint (push) Successful in 1m27s
CI/CD / Build & Release (push) Has been cancelled

The test was flaky because it used crypto/rand for random data,
causing non-deterministic chunk boundaries. With small sample sizes
(100KB / 8KB avg = ~12 chunks), variance was high - sometimes only
42.9% overlap instead of expected >50%.

Fixed by using math/rand with seed 42 for reproducible test results.
Now consistently achieves 91.7% overlap (11/12 chunks).
This commit is contained in:
2026-01-16 16:02:29 +01:00
parent 5728b465e6
commit b2a78cad2a
2 changed files with 9 additions and 5 deletions

View File

@@ -4,6 +4,7 @@ import (
"bytes"
"crypto/rand"
"io"
mathrand "math/rand"
"testing"
)
@@ -100,12 +101,15 @@ func TestChunker_Deterministic(t *testing.T) {
func TestChunker_ShiftedData(t *testing.T) {
// Test that shifted data still shares chunks (the key CDC benefit)
// Use deterministic random data for reproducible test results
rng := mathrand.New(mathrand.NewSource(42))
original := make([]byte, 100*1024)
rand.Read(original)
rng.Read(original)
// Create shifted version (prepend some bytes)
prefix := make([]byte, 1000)
rand.Read(prefix)
rng.Read(prefix)
shifted := append(prefix, original...)
// Chunk both