From b496e3e1cc70829e5a6f78f3dff28277993f8406 Mon Sep 17 00:00:00 2001
From: Ethan Koenig <ethantkoenig@gmail.com>
Date: Fri, 15 Sep 2017 00:54:25 -0700
Subject: [PATCH] Fix unit test race condition (#2516)

---
 models/pull_test.go | 9 +++++++--
 1 file 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)