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

check_test.go 2.2 kB

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>
5 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>
5 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>
5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. )
  15. func TestPullRequest_AddToTaskQueue(t *testing.T) {
  16. assert.NoError(t, models.PrepareTestDatabase())
  17. idChan := make(chan int64, 10)
  18. q, err := queue.NewChannelUniqueQueue(func(data ...queue.Data) {
  19. for _, datum := range data {
  20. id, _ := strconv.ParseInt(datum.(string), 10, 64)
  21. idChan <- id
  22. }
  23. }, queue.ChannelUniqueQueueConfiguration{
  24. WorkerPoolConfiguration: queue.WorkerPoolConfiguration{
  25. QueueLength: 10,
  26. BatchLength: 1,
  27. },
  28. Workers: 1,
  29. Name: "temporary-queue",
  30. }, "")
  31. assert.NoError(t, err)
  32. queueShutdown := []func(){}
  33. queueTerminate := []func(){}
  34. prQueue = q.(queue.UniqueQueue)
  35. pr := models.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
  36. AddToTaskQueue(pr)
  37. assert.Eventually(t, func() bool {
  38. pr = models.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
  39. return pr.Status == models.PullRequestStatusChecking
  40. }, 1*time.Second, 100*time.Millisecond)
  41. has, err := prQueue.Has(strconv.FormatInt(pr.ID, 10))
  42. assert.True(t, has)
  43. assert.NoError(t, err)
  44. prQueue.Run(func(_ context.Context, shutdown func()) {
  45. queueShutdown = append(queueShutdown, shutdown)
  46. }, func(_ context.Context, terminate func()) {
  47. queueTerminate = append(queueTerminate, terminate)
  48. })
  49. select {
  50. case id := <-idChan:
  51. assert.EqualValues(t, pr.ID, id)
  52. case <-time.After(time.Second):
  53. assert.Fail(t, "Timeout: nothing was added to pullRequestQueue")
  54. }
  55. has, err = prQueue.Has(strconv.FormatInt(pr.ID, 10))
  56. assert.False(t, has)
  57. assert.NoError(t, err)
  58. pr = models.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
  59. assert.Equal(t, models.PullRequestStatusChecking, pr.Status)
  60. for _, callback := range queueShutdown {
  61. callback()
  62. }
  63. for _, callback := range queueTerminate {
  64. callback()
  65. }
  66. prQueue = nil
  67. }