diff options
author | lukechampine <luke.champine@gmail.com> | 2016-04-03 12:41:38 -0400 |
---|---|---|
committer | lukechampine <luke.champine@gmail.com> | 2016-04-03 12:41:50 -0400 |
commit | 9d00b9ddaee0d5bac09a428b1974336845038423 (patch) | |
tree | 8d61e772e97ed121c004125da8632ad35de72ec6 /stm_test.go | |
parent | fix AtomicSet bug (diff) | |
download | stm-9d00b9ddaee0d5bac09a428b1974336845038423.tar.gz stm-9d00b9ddaee0d5bac09a428b1974336845038423.tar.xz |
add TestPanic and TestReadWritten
100% test coverage!
Diffstat (limited to 'stm_test.go')
-rw-r--r-- | stm_test.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/stm_test.go b/stm_test.go index 2542894..44ca40b 100644 --- a/stm_test.go +++ b/stm_test.go @@ -177,6 +177,28 @@ func TestCompose(t *testing.T) { } } +func TestPanic(t *testing.T) { + defer func() { + if recover() == nil { + t.Fatal("expected panic, got nil") + } + }() + // normal panics should escape Atomically + Atomically(func(*Tx) { + panic("foo") + }) +} + +func TestReadWritten(t *testing.T) { + // reading a variable written in the same transaction should return the + // previously written value + x := NewVar(3) + Atomically(func(tx *Tx) { + tx.Set(x, 5) + tx.Assert(tx.Get(x).(int) == 5) + }) +} + func BenchmarkAtomicGet(b *testing.B) { x := NewVar(0) for i := 0; i < b.N; i++ { |