Browse Source

Fix unit test race condition (#2516)

Ethan Koenig 2 years ago
parent
commit
b496e3e1cc
1 changed files with 7 additions and 2 deletions
  1. 7 2
      models/pull_test.go

+ 7 - 2
models/pull_test.go

@@ -5,6 +5,7 @@
5 5
 package models
6 6
 
7 7
 import (
8
+	"strconv"
8 9
 	"testing"
9 10
 	"time"
10 11
 
@@ -193,8 +194,12 @@ func TestPullRequest_AddToTaskQueue(t *testing.T) {
193 194
 	pr := AssertExistsAndLoadBean(t, &PullRequest{ID: 1}).(*PullRequest)
194 195
 	pr.AddToTaskQueue()
195 196
 
196
-	// briefly sleep so that background threads have time to run
197
-	time.Sleep(time.Millisecond)
197
+	select {
198
+	case id := <-pullRequestQueue.Queue():
199
+		assert.EqualValues(t, strconv.FormatInt(pr.ID, 10), id)
200
+	case <-time.After(time.Second):
201
+		assert.Fail(t, "Timeout: nothing was added to pullRequestQueue")
202
+	}
198 203
 
199 204
 	assert.True(t, pullRequestQueue.Exist(pr.ID))
200 205
 	pr = AssertExistsAndLoadBean(t, &PullRequest{ID: 1}).(*PullRequest)