mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-23 20:17:03 +01:00
Fix unit test race condition (#2516)
This commit is contained in:
parent
cbe50587ba
commit
b496e3e1cc
1 changed files with 7 additions and 2 deletions
|
@ -5,6 +5,7 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -193,8 +194,12 @@ func TestPullRequest_AddToTaskQueue(t *testing.T) {
|
||||||
pr := AssertExistsAndLoadBean(t, &PullRequest{ID: 1}).(*PullRequest)
|
pr := AssertExistsAndLoadBean(t, &PullRequest{ID: 1}).(*PullRequest)
|
||||||
pr.AddToTaskQueue()
|
pr.AddToTaskQueue()
|
||||||
|
|
||||||
// briefly sleep so that background threads have time to run
|
select {
|
||||||
time.Sleep(time.Millisecond)
|
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))
|
assert.True(t, pullRequestQueue.Exist(pr.ID))
|
||||||
pr = AssertExistsAndLoadBean(t, &PullRequest{ID: 1}).(*PullRequest)
|
pr = AssertExistsAndLoadBean(t, &PullRequest{ID: 1}).(*PullRequest)
|
||||||
|
|
Loading…
Reference in a new issue