2019-12-07 02:44:10 +00:00
|
|
|
// Copyright 2019 The Gitea Authors.
|
|
|
|
// All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package pull
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPullRequest_AddToTaskQueue(t *testing.T) {
|
|
|
|
assert.NoError(t, models.PrepareTestDatabase())
|
|
|
|
|
2020-02-10 13:09:08 +00:00
|
|
|
pr := models.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
|
2019-12-07 02:44:10 +00:00
|
|
|
AddToTaskQueue(pr)
|
|
|
|
|
|
|
|
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))
|
2020-02-10 13:09:08 +00:00
|
|
|
pr = models.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
|
2019-12-07 02:44:10 +00:00
|
|
|
assert.Equal(t, models.PullRequestStatusChecking, pr.Status)
|
|
|
|
}
|