| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "path/filepath" |
| 5 | "testing" |
| 6 | "time" |
| 7 | ) |
| 8 | |
| 9 | func TestRunExercisesColdOpenAndHistoryIndex(t *testing.T) { |
| 10 | result, err := run(t.Context(), config{ |
| 11 | Root: filepath.Join(t.TempDir(), "sessions-v4"), SessionID: "small-capacity", |
| 12 | HistoryMessages: 6, HistoryBytes: 256 << 10, |
| 13 | AttachmentBytes: 384 << 10, AttachmentChunkBytes: 128 << 10, |
| 14 | WorksetBytes: 64 << 10, FlushEvery: 2, PageSamples: 2, |
| 15 | }) |
| 16 | if err != nil { |
| 17 | t.Fatal(err) |
| 18 | } |
| 19 | if result.HistoryMessages != 6 || result.HistoryLogicalBytes != 256<<10 { |
| 20 | t.Fatalf("history result = %+v", result) |
| 21 | } |
| 22 | if result.AttachmentObjects != 3 || result.AttachmentLogicalBytes != 384<<10 { |
| 23 | t.Fatalf("attachment result = %+v", result) |
| 24 | } |
| 25 | if result.EventSequence != 13 || result.DurableSequence != result.EventSequence { |
| 26 | t.Fatalf("watermarks = accepted %d durable %d", result.EventSequence, result.DurableSequence) |
| 27 | } |
| 28 | if result.ModelWorksetBytes != 64<<10 || result.SessionDiskBytes == 0 || result.ContentDiskBytes == 0 || result.QueryCacheDiskBytes == 0 { |
| 29 | t.Fatalf("capacity evidence incomplete: %+v", result) |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | func TestPercentile95(t *testing.T) { |
| 34 | values := []time.Duration{5, 1, 3, 2, 4} |
| 35 | if got := percentile95(values); got != 5 { |
| 36 | t.Fatalf("p95 = %v, want 5", got) |
| 37 | } |
| 38 | } |
| 39 |