Skip to content

Commit

Permalink
Fix race condition and dead lock in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
black-adder committed Apr 11, 2017
1 parent 899c1b8 commit c5accee
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/agent/app/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ func TestAgentStartStop(t *testing.T) {
body, err := ioutil.ReadAll(resp.Body)
assert.NoError(t, err)
assert.Equal(t, "tcollector error: no peers available\n", string(body))
agent.Stop()
assert.NoError(t, <-ch)
agent.Stop()
}
4 changes: 2 additions & 2 deletions pkg/queue/drop_oldest_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestQueue(t *testing.T) {
var wg sync.WaitGroup
var startLock sync.Mutex

// Make sure that at least one consumer consumes and element before we produce them
// Make sure that at least one consumer consumes an element before we produce them
// all. If all 5 go out before an consumers, we'll have 1 reaped, 1 in reaper channel,
// and 2 in the items channel, and we'll deadlock.
consumerConsumed := sync.NewCond(&sync.Mutex{})
Expand Down Expand Up @@ -66,7 +66,7 @@ func TestQueue(t *testing.T) {
q.Produce(val) // goes to consumer 1 and blocks it on startLock
t.Logf("produced %s, queue size %d\n", val, q.Size())
}
// With queue capacity of 3, and two consumers, we can product at most 5 items without blocking,
// With queue capacity of 3, and two consumers, we can produce at most 5 items without blocking,
// assuming that both consumers read one value and block
// If they don't read, then main will block while producing 5 items, thus allowing consumers to read
// and block.
Expand Down

0 comments on commit c5accee

Please sign in to comment.