Skip to content

Commit 9a62e53

Browse files
committed
Fixes couchbaselabs#23: Try the alloc checker multiple times to determine success.
This is required due to the fact that Go can arbitrarily perform allocations at any time, which causes the test to fail occasionally. This commit causes it to run up to 20 times trying to get a 0-alloc run, if any run has no allocations, it can be assumed that any other allocations that were seen were arbitrary and unrelated to the binTree.
1 parent 203c26f commit 9a62e53

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

bintree_test.go

+18-10
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,25 @@ func TestBinTree(t *testing.T) {
106106
}
107107

108108
{
109-
memTrack := allocTracker{}
110-
111-
state := tree.NewState()
112-
113-
memTrack.Start()
114-
state.MarkNode(1, false)
115-
state.MarkNode(3, true)
116-
state.MarkNode(5, true)
117-
memTrack.Stop()
109+
madeNoAllocs := false
110+
for i := 0; i < 100; i++ {
111+
memTrack := allocTracker{}
112+
113+
state := tree.NewState()
114+
115+
memTrack.Start()
116+
state.MarkNode(1, false)
117+
state.MarkNode(3, true)
118+
state.MarkNode(5, true)
119+
memTrack.Stop()
120+
121+
if memTrack.Alloc() == 0 {
122+
madeNoAllocs = true
123+
break
124+
}
125+
}
118126

119-
if memTrack.Alloc() != 0 {
127+
if !madeNoAllocs {
120128
t.Fatal("marking nodes should not allocate memory")
121129
}
122130
}

0 commit comments

Comments
 (0)