snapshot_test.odin (1078B)
1 package main 2 3 import "core:testing" 4 5 @(test) 6 test_snapshot_round_trips :: proc(t: ^testing.T) { 7 p: Publisher 8 _, ok := current(&p) 9 testing.expect(t, ok, "an untouched publisher should still hand out its zero value") 10 11 s := Snapshot { 12 count = 2, 13 nodes = 99, 14 complete = true, 15 } 16 s.rows[0] = { 17 node = 7, 18 bytes = 4096, 19 } 20 publish(&p, s) 21 22 got, got_ok := current(&p) 23 testing.expect(t, got_ok) 24 testing.expect_value(t, got.count, 2) 25 testing.expect_value(t, got.nodes, u64(99)) 26 testing.expect_value(t, got.rows[0].bytes, u64(4096)) 27 testing.expect(t, got.complete) 28 } 29 30 @(test) 31 test_snapshot_refuses_a_write_in_flux :: proc(t: ^testing.T) { 32 // An odd sequence is what a half-written snapshot looks like. The reader must 33 // decline rather than hand back something torn. 34 p: Publisher 35 publish(&p, Snapshot{count = 1}) 36 p.seq += 1 // as though a write had begun 37 38 _, ok := current(&p) 39 testing.expect(t, !ok, "a snapshot mid-write was handed out") 40 41 p.seq += 1 // and finished 42 _, ok2 := current(&p) 43 testing.expect(t, ok2, "a finished write was not readable") 44 }