]> source.dussan.org Git - gitea.git/commitdiff
Fix unit test race condition (#2516)
authorEthan Koenig <ethantkoenig@gmail.com>
Fri, 15 Sep 2017 07:54:25 +0000 (00:54 -0700)
committerLauris BH <lauris@nix.lv>
Fri, 15 Sep 2017 07:54:25 +0000 (10:54 +0300)
models/pull_test.go

index c8eb033aa51a9c186b62fb113cd6e76975884fc5..e725193bb1766ae1527d3465cd1eab5905967025 100644 (file)
@@ -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)