Skip to content

Commit

Permalink
Fix unit test race condition (#2516)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethantkoenig authored and lafriks committed Sep 15, 2017
1 parent cbe5058 commit b496e3e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions models/pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package models

import (
"strconv"
"testing"
"time"

Expand Down Expand Up @@ -193,8 +194,12 @@ func TestPullRequest_AddToTaskQueue(t *testing.T) {
pr := AssertExistsAndLoadBean(t, &PullRequest{ID: 1}).(*PullRequest)
pr.AddToTaskQueue()

// briefly sleep so that background threads have time to run
time.Sleep(time.Millisecond)
select {
case id := <-pullRequestQueue.Queue():
assert.EqualValues(t, strconv.FormatInt(pr.ID, 10), id)
case <-time.After(time.Second):
assert.Fail(t, "Timeout: nothing was added to pullRequestQueue")
}

assert.True(t, pullRequestQueue.Exist(pr.ID))
pr = AssertExistsAndLoadBean(t, &PullRequest{ID: 1}).(*PullRequest)
Expand Down

0 comments on commit b496e3e

Please sign in to comment.