Skip to content

Commit 023c25a

Browse files
Merge pull request #100 from Workiva/travis_gomaxprocs
Fix ctrie tests
2 parents d832cf3 + df425f2 commit 023c25a

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@ go:
88
before_install: go get golang.org/x/tools/cmd/cover
99
script: go test -race -cover ./...
1010

11+
env:
12+
- GOMAXPROCS=8
13+
1114
notifications:
1215
email: false

queue/queue_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ func TestPoll(t *testing.T) {
116116

117117
before := time.Now()
118118
_, err = q.Poll(1, 5*time.Millisecond)
119-
assert.InDelta(t, 5, time.Since(before).Seconds()*1000, 2)
119+
// This delta is normally 1-3 ms but running tests in CI with -race causes
120+
// this to run much slower. For now, just bump up the threshold.
121+
assert.InDelta(t, 5, time.Since(before).Seconds()*1000, 10)
120122
assert.Equal(t, ErrTimeout, err)
121123
}
122124

trie/ctrie/ctrie_test.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,19 @@ func TestInsertTNode(t *testing.T) {
119119
assert := assert.New(t)
120120
ctrie := New(nil)
121121

122-
for i := 0; i < 100000; i++ {
122+
for i := 0; i < 10000; i++ {
123123
ctrie.Insert([]byte(strconv.Itoa(i)), i)
124124
}
125125

126-
for i := 0; i < 50000; i++ {
126+
for i := 0; i < 5000; i++ {
127127
ctrie.Remove([]byte(strconv.Itoa(i)))
128128
}
129129

130-
for i := 0; i < 100000; i++ {
130+
for i := 0; i < 10000; i++ {
131131
ctrie.Insert([]byte(strconv.Itoa(i)), i)
132132
}
133133

134-
for i := 0; i < 100000; i++ {
134+
for i := 0; i < 10000; i++ {
135135
val, ok := ctrie.Lookup([]byte(strconv.Itoa(i)))
136136
assert.True(ok)
137137
assert.Equal(i, val)
@@ -145,14 +145,14 @@ func TestConcurrency(t *testing.T) {
145145
wg.Add(2)
146146

147147
go func() {
148-
for i := 0; i < 100000; i++ {
148+
for i := 0; i < 10000; i++ {
149149
ctrie.Insert([]byte(strconv.Itoa(i)), i)
150150
}
151151
wg.Done()
152152
}()
153153

154154
go func() {
155-
for i := 0; i < 100000; i++ {
155+
for i := 0; i < 10000; i++ {
156156
val, ok := ctrie.Lookup([]byte(strconv.Itoa(i)))
157157
if ok {
158158
assert.Equal(i, val)
@@ -161,7 +161,7 @@ func TestConcurrency(t *testing.T) {
161161
wg.Done()
162162
}()
163163

164-
for i := 0; i < 100000; i++ {
164+
for i := 0; i < 10000; i++ {
165165
time.Sleep(5)
166166
ctrie.Remove([]byte(strconv.Itoa(i)))
167167
}
@@ -291,7 +291,11 @@ func TestIterator(t *testing.T) {
291291
assert.Equal(exp, entry.Value)
292292
}
293293
close(cancel)
294-
<-iter // Drain anything already put on the channel
294+
// Drain anything already put on the channel. Since select chooses a
295+
// pseudo-random case, we must attempt to drain for every item.
296+
for _ = range expected {
297+
<-iter
298+
}
295299
_, ok = <-iter
296300
assert.False(ok)
297301
}

0 commit comments

Comments
 (0)