Skip to content

Commit b496e3e

Browse files
ethantkoeniglafriks
authored andcommitted
Fix unit test race condition (#2516)
1 parent cbe5058 commit b496e3e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

models/pull_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package models
66

77
import (
8+
"strconv"
89
"testing"
910
"time"
1011

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

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+
}
198203

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

0 commit comments

Comments
 (0)