summaryrefslogtreecommitdiffstats
path: root/models/pull_test.go
diff options
context:
space:
mode:
authorEthan Koenig <ethantkoenig@gmail.com>2017-09-15 00:54:25 -0700
committerLauris BH <lauris@nix.lv>2017-09-15 10:54:25 +0300
commitb496e3e1cc70829e5a6f78f3dff28277993f8406 (patch)
tree7714999caaeddda9659614c21c6f3fd540d2ad24 /models/pull_test.go
parentcbe50587bafa0a807de128f9c3541ba922fbd2f8 (diff)
downloadgitea-b496e3e1cc70829e5a6f78f3dff28277993f8406.tar.gz
gitea-b496e3e1cc70829e5a6f78f3dff28277993f8406.zip
Fix unit test race condition (#2516)
Diffstat (limited to 'models/pull_test.go')
-rw-r--r--models/pull_test.go9
1 files changed, 7 insertions, 2 deletions
diff --git a/models/pull_test.go b/models/pull_test.go
index c8eb033aa5..e725193bb1 100644
--- a/models/pull_test.go
+++ b/models/pull_test.go
@@ -5,6 +5,7 @@
package models
import (
+ "strconv"
"testing"
"time"
@@ -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)