You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.2 KiB

Only check for conflicts/merging if the PR has not been merged in the interim (#10132) * 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>
4 years ago
Only check for conflicts/merging if the PR has not been merged in the interim (#10132) * 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>
4 years ago
Only check for conflicts/merging if the PR has not been merged in the interim (#10132) * 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>
4 years ago
  1. // Copyright 2019 The Gitea Authors.
  2. // All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package pull
  6. import (
  7. "context"
  8. "strconv"
  9. "testing"
  10. "time"
  11. "code.gitea.io/gitea/models"
  12. "code.gitea.io/gitea/modules/queue"
  13. "github.com/stretchr/testify/assert"
  14. "github.com/unknwon/com"
  15. )
  16. func TestPullRequest_AddToTaskQueue(t *testing.T) {
  17. assert.NoError(t, models.PrepareTestDatabase())
  18. idChan := make(chan int64, 10)
  19. q, err := queue.NewChannelUniqueQueue(func(data ...queue.Data) {
  20. for _, datum := range data {
  21. prID := datum.(string)
  22. id := com.StrTo(prID).MustInt64()
  23. idChan <- id
  24. }
  25. }, queue.ChannelUniqueQueueConfiguration{
  26. WorkerPoolConfiguration: queue.WorkerPoolConfiguration{
  27. QueueLength: 10,
  28. BatchLength: 1,
  29. },
  30. Workers: 1,
  31. Name: "temporary-queue",
  32. }, "")
  33. assert.NoError(t, err)
  34. queueShutdown := []func(){}
  35. queueTerminate := []func(){}
  36. prQueue = q.(queue.UniqueQueue)
  37. pr := models.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
  38. AddToTaskQueue(pr)
  39. assert.Eventually(t, func() bool {
  40. pr = models.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
  41. return pr.Status == models.PullRequestStatusChecking
  42. }, 1*time.Second, 100*time.Millisecond)
  43. has, err := prQueue.Has(strconv.FormatInt(pr.ID, 10))
  44. assert.True(t, has)
  45. assert.NoError(t, err)
  46. prQueue.Run(func(_ context.Context, shutdown func()) {
  47. queueShutdown = append(queueShutdown, shutdown)
  48. }, func(_ context.Context, terminate func()) {
  49. queueTerminate = append(queueTerminate, terminate)
  50. })
  51. select {
  52. case id := <-idChan:
  53. assert.EqualValues(t, pr.ID, id)
  54. case <-time.After(time.Second):
  55. assert.Fail(t, "Timeout: nothing was added to pullRequestQueue")
  56. }
  57. has, err = prQueue.Has(strconv.FormatInt(pr.ID, 10))
  58. assert.False(t, has)
  59. assert.NoError(t, err)
  60. pr = models.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
  61. assert.Equal(t, models.PullRequestStatusChecking, pr.Status)
  62. for _, callback := range queueShutdown {
  63. callback()
  64. }
  65. for _, callback := range queueTerminate {
  66. callback()
  67. }
  68. prQueue = nil
  69. }