Skip to content

Commit 29fbed2

Browse files
committed
Attempt to get diff twice
Signed-off-by: Andrew Thornton <[email protected]>
1 parent afa781b commit 29fbed2

File tree

3 files changed

+50
-6
lines changed

3 files changed

+50
-6
lines changed

integrations/api_helper_for_declarative_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,26 @@ func doAPICreatePullRequest(ctx APITestContext, owner, repo, baseBranch, headBra
239239
}
240240
}
241241

242+
func doAPIGetPullRequest(ctx APITestContext, owner, repo string, index int64) func(*testing.T) (api.PullRequest, error) {
243+
return func(t *testing.T) (api.PullRequest, error) {
244+
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d?token=%s",
245+
owner, repo, index, ctx.Token)
246+
req := NewRequest(t, http.MethodGet, urlStr)
247+
248+
expected := 200
249+
if ctx.ExpectedCode != 0 {
250+
expected = ctx.ExpectedCode
251+
}
252+
resp := ctx.Session.MakeRequest(t, req, expected)
253+
254+
json := jsoniter.ConfigCompatibleWithStandardLibrary
255+
decoder := json.NewDecoder(resp.Body)
256+
pr := api.PullRequest{}
257+
err := decoder.Decode(&pr)
258+
return pr, err
259+
}
260+
}
261+
242262
func doAPIMergePullRequest(ctx APITestContext, owner, repo string, index int64) func(*testing.T) {
243263
return func(t *testing.T) {
244264
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/merge?token=%s",

integrations/git_test.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
package integrations
66

77
import (
8+
"encoding/hex"
89
"fmt"
910
"io/ioutil"
1011
"math/rand"
1112
"net/http"
1213
"net/url"
14+
"os"
1315
"path"
1416
"path/filepath"
1517
"strconv"
@@ -452,26 +454,41 @@ func doMergeFork(ctx, baseCtx APITestContext, baseBranch, headBranch string) fun
452454

453455
// Then get the diff string
454456
var diffHash string
457+
var diffLength int
455458
t.Run("GetDiff", func(t *testing.T) {
456459
req := NewRequest(t, "GET", fmt.Sprintf("/%s/%s/pulls/%d.diff", url.PathEscape(baseCtx.Username), url.PathEscape(baseCtx.Reponame), pr.Index))
457460
resp := ctx.Session.MakeRequestNilResponseHashSumRecorder(t, req, http.StatusOK)
458461
diffHash = string(resp.Hash.Sum(nil))
462+
diffLength = resp.Length
463+
if diffLength == 0 {
464+
fmt.Fprintf(os.Stdout, "Had to request diff twice due to 0 bytes\n")
465+
req := NewRequest(t, "GET", fmt.Sprintf("/%s/%s/pulls/%d.diff", url.PathEscape(baseCtx.Username), url.PathEscape(baseCtx.Reponame), pr.Index))
466+
resp := ctx.Session.MakeRequestNilResponseHashSumRecorder(t, req, http.StatusOK)
467+
diffHash = string(resp.Hash.Sum(nil))
468+
diffLength = resp.Length
469+
}
459470
})
460471

461472
// Now: Merge the PR & make sure that doesn't break the PR page or change its diff
462473
t.Run("MergePR", doAPIMergePullRequest(baseCtx, baseCtx.Username, baseCtx.Reponame, pr.Index))
463474
t.Run("EnsureCanSeePull", doEnsureCanSeePull(baseCtx, pr))
464-
t.Run("EnsureDiffNoChange", doEnsureDiffNoChange(baseCtx, pr, diffHash))
475+
t.Run("CheckPR", func(t *testing.T) {
476+
oldMergeBase := pr.MergeBase
477+
pr2, err := doAPIGetPullRequest(baseCtx, baseCtx.Username, baseCtx.Reponame, pr.Index)(t)
478+
assert.NoError(t, err)
479+
assert.Equal(t, oldMergeBase, pr2.MergeBase)
480+
})
481+
t.Run("EnsurDiffNoChange", doEnsureDiffNoChange(baseCtx, pr, diffHash, diffLength))
465482

466483
// Then: Delete the head branch & make sure that doesn't break the PR page or change its diff
467484
t.Run("DeleteHeadBranch", doBranchDelete(baseCtx, baseCtx.Username, baseCtx.Reponame, headBranch))
468485
t.Run("EnsureCanSeePull", doEnsureCanSeePull(baseCtx, pr))
469-
t.Run("EnsureDiffNoChange", doEnsureDiffNoChange(baseCtx, pr, diffHash))
486+
t.Run("EnsureDiffNoChange", doEnsureDiffNoChange(baseCtx, pr, diffHash, diffLength))
470487

471488
// Delete the head repository & make sure that doesn't break the PR page or change its diff
472489
t.Run("DeleteHeadRepository", doAPIDeleteRepository(ctx))
473490
t.Run("EnsureCanSeePull", doEnsureCanSeePull(baseCtx, pr))
474-
t.Run("EnsureDiffNoChange", doEnsureDiffNoChange(baseCtx, pr, diffHash))
491+
t.Run("EnsureDiffNoChange", doEnsureDiffNoChange(baseCtx, pr, diffHash, diffLength))
475492
}
476493
}
477494

@@ -515,14 +532,15 @@ func doEnsureCanSeePull(ctx APITestContext, pr api.PullRequest) func(t *testing.
515532
}
516533
}
517534

518-
func doEnsureDiffNoChange(ctx APITestContext, pr api.PullRequest, diffHash string) func(t *testing.T) {
535+
func doEnsureDiffNoChange(ctx APITestContext, pr api.PullRequest, diffHash string, diffLength int) func(t *testing.T) {
519536
return func(t *testing.T) {
520537
req := NewRequest(t, "GET", fmt.Sprintf("/%s/%s/pulls/%d.diff", url.PathEscape(ctx.Username), url.PathEscape(ctx.Reponame), pr.Index))
521538
resp := ctx.Session.MakeRequestNilResponseHashSumRecorder(t, req, http.StatusOK)
522539
actual := string(resp.Hash.Sum(nil))
540+
actualLength := resp.Length
523541

524542
equal := diffHash == actual
525-
assert.True(t, equal, "Unexpected change in the diff string: expected hash: %s but was actually: %s", diffHash, actual)
543+
assert.True(t, equal, "Unexpected change in the diff string: expected hash: %s size: %d but was actually: %s size: %d", hex.EncodeToString([]byte(diffHash)), diffLength, hex.EncodeToString([]byte(actual)), actualLength)
526544
}
527545
}
528546

modules/queue/manager.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ func (m *Manager) FlushAll(baseCtx context.Context, timeout time.Duration) error
174174
default:
175175
}
176176
mqs := m.ManagedQueues()
177+
log.Debug("Found %d Managed Queues", len(mqs))
177178
wg := sync.WaitGroup{}
178179
wg.Add(len(mqs))
179180
allEmpty := true
@@ -184,6 +185,7 @@ func (m *Manager) FlushAll(baseCtx context.Context, timeout time.Duration) error
184185
}
185186
allEmpty = false
186187
if flushable, ok := mq.Managed.(Flushable); ok {
188+
log.Debug("Flushing (flushable) queue: %s", mq.Name)
187189
go func(q *ManagedQueue) {
188190
localCtx, localCancel := context.WithCancel(ctx)
189191
pid := q.RegisterWorkers(1, start, hasTimeout, end, localCancel, true)
@@ -196,7 +198,11 @@ func (m *Manager) FlushAll(baseCtx context.Context, timeout time.Duration) error
196198
wg.Done()
197199
}(mq)
198200
} else {
199-
wg.Done()
201+
log.Debug("Queue: %s is non-empty but is not flushable - adding 100 millisecond wait", mq.Name)
202+
go func() {
203+
<-time.After(100 * time.Millisecond)
204+
wg.Done()
205+
}()
200206
}
201207

202208
}

0 commit comments

Comments
 (0)