mirror of
				https://github.com/go-gitea/gitea
				synced 2025-10-31 03:18:24 +00:00 
			
		
		
		
	* Only check for merging if the PR has not been merged in the interim * fixup! Only check for merging if the PR has not been merged in the interim * Try to fix test failure * Use PR2 not PR1 in tests as PR1 merges automatically * return already merged error * enforce locking * enforce locking - fix-test * enforce locking - fix-testx2 * enforce locking - fix-testx3 * move pullrequest checking to after merge This might improve the chance that the race does not affect us but does not prevent it. * Remove minor race with getting merge commit id * fixup * move check pr after merge * Remove unnecessary prepareTestEnv - onGiteaRun does this for us * Add information about when merging occuring * fix fmt * More logging * Attempt to fix mysql * Try MySQL fix again * try again * Try again?! * Try again?! * Sigh * remove the count - perhaps that will help * next remove the update id * next remove the update id - make it updated_unix instead * On failure to merge ensure that the pr is rechecked for conflict errors * On failure to merge ensure that the pr is rechecked for conflict errors * Update models/pull.go * Update models/pull.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Apply suggestions from code review Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
		
			
				
	
	
		
			88 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			88 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // 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 (
 | |
| 	"context"
 | |
| 	"strconv"
 | |
| 	"testing"
 | |
| 	"time"
 | |
| 
 | |
| 	"code.gitea.io/gitea/models"
 | |
| 	"code.gitea.io/gitea/modules/queue"
 | |
| 
 | |
| 	"github.com/stretchr/testify/assert"
 | |
| 	"github.com/unknwon/com"
 | |
| )
 | |
| 
 | |
| func TestPullRequest_AddToTaskQueue(t *testing.T) {
 | |
| 	assert.NoError(t, models.PrepareTestDatabase())
 | |
| 
 | |
| 	idChan := make(chan int64, 10)
 | |
| 
 | |
| 	q, err := queue.NewChannelUniqueQueue(func(data ...queue.Data) {
 | |
| 		for _, datum := range data {
 | |
| 			prID := datum.(string)
 | |
| 			id := com.StrTo(prID).MustInt64()
 | |
| 			idChan <- id
 | |
| 		}
 | |
| 	}, queue.ChannelUniqueQueueConfiguration{
 | |
| 		WorkerPoolConfiguration: queue.WorkerPoolConfiguration{
 | |
| 			QueueLength: 10,
 | |
| 			BatchLength: 1,
 | |
| 		},
 | |
| 		Workers: 1,
 | |
| 		Name:    "temporary-queue",
 | |
| 	}, "")
 | |
| 	assert.NoError(t, err)
 | |
| 
 | |
| 	queueShutdown := []func(){}
 | |
| 	queueTerminate := []func(){}
 | |
| 
 | |
| 	prQueue = q.(queue.UniqueQueue)
 | |
| 
 | |
| 	pr := models.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
 | |
| 	AddToTaskQueue(pr)
 | |
| 
 | |
| 	assert.Eventually(t, func() bool {
 | |
| 		pr = models.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
 | |
| 		return pr.Status == models.PullRequestStatusChecking
 | |
| 	}, 1*time.Second, 100*time.Millisecond)
 | |
| 
 | |
| 	has, err := prQueue.Has(strconv.FormatInt(pr.ID, 10))
 | |
| 	assert.True(t, has)
 | |
| 	assert.NoError(t, err)
 | |
| 
 | |
| 	prQueue.Run(func(_ context.Context, shutdown func()) {
 | |
| 		queueShutdown = append(queueShutdown, shutdown)
 | |
| 	}, func(_ context.Context, terminate func()) {
 | |
| 		queueTerminate = append(queueTerminate, terminate)
 | |
| 	})
 | |
| 
 | |
| 	select {
 | |
| 	case id := <-idChan:
 | |
| 		assert.EqualValues(t, pr.ID, id)
 | |
| 	case <-time.After(time.Second):
 | |
| 		assert.Fail(t, "Timeout: nothing was added to pullRequestQueue")
 | |
| 	}
 | |
| 
 | |
| 	has, err = prQueue.Has(strconv.FormatInt(pr.ID, 10))
 | |
| 	assert.False(t, has)
 | |
| 	assert.NoError(t, err)
 | |
| 
 | |
| 	pr = models.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
 | |
| 	assert.Equal(t, models.PullRequestStatusChecking, pr.Status)
 | |
| 
 | |
| 	for _, callback := range queueShutdown {
 | |
| 		callback()
 | |
| 	}
 | |
| 	for _, callback := range queueTerminate {
 | |
| 		callback()
 | |
| 	}
 | |
| 
 | |
| 	prQueue = nil
 | |
| }
 |