aboutsummaryrefslogtreecommitdiff
path: root/stm_test.go
diff options
context:
space:
mode:
authorlukechampine <luke.champine@gmail.com>2016-04-03 12:41:38 -0400
committerlukechampine <luke.champine@gmail.com>2016-04-03 12:41:50 -0400
commit9d00b9ddaee0d5bac09a428b1974336845038423 (patch)
tree8d61e772e97ed121c004125da8632ad35de72ec6 /stm_test.go
parentfix AtomicSet bug (diff)
downloadstm-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.go22
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++ {