Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

Commit

Permalink
Fix #1678 by speeding up IsMergeable retries when testing. (#1684)
Browse files Browse the repository at this point in the history
before:
ok      k8s.io/contrib/mungegithub/mungers      65.728s
after:
ok      k8s.io/contrib/mungegithub/mungers      3.886s
  • Loading branch information
rmmh authored Sep 2, 2016
1 parent 0843745 commit c694368
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
14 changes: 9 additions & 5 deletions mungegithub/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ type Config struct {
// If true, don't make any mutating API calls
DryRun bool

// Defaults to 30 seconds.
PendingWaitTime *time.Duration
// Base sleep time for retry loops. Defaults to 1 second.
BaseWaitTime time.Duration

// When we clear analytics we store the last values here
lastAnalytics analytics
Expand Down Expand Up @@ -1183,8 +1183,8 @@ func (obj *MungeObject) doWaitStatus(pending bool, requiredContexts []string, c
}
sleepTime := 30 * time.Second
// If the time was explicitly set, use that instead
if config.PendingWaitTime != nil {
sleepTime = *config.PendingWaitTime
if config.BaseWaitTime != 0 {
sleepTime = 30 * config.BaseWaitTime
}
if pending {
glog.V(4).Infof("PR# %d is not pending, waiting for %f seconds", *obj.Issue.Number, sleepTime.Seconds())
Expand Down Expand Up @@ -1730,7 +1730,11 @@ func (obj *MungeObject) IsMergeable() (bool, error) {
// Sleep for 2-32 seconds on successive attempts.
// Worst case, we'll wait for up to a minute for GitHub
// to compute it before bailing out.
time.Sleep((1 << uint(try)) * time.Second)
baseDelay := time.Second
if obj.config.BaseWaitTime != 0 { // Allow shorter delays in tests.
baseDelay = obj.config.BaseWaitTime
}
time.Sleep((1 << uint(try)) * baseDelay)
err := obj.Refresh()
if err != nil {
glog.Errorf("Unable to refresh PR# %d: %v", prNum, err)
Expand Down
5 changes: 2 additions & 3 deletions mungegithub/mungers/submit-queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -896,9 +896,8 @@ func TestSubmitQueue(t *testing.T) {
config.Org = "o"
config.Project = "r"
config.SetClient(client)
// Don't wait so long for it to go pending or back
d := 250 * time.Millisecond
config.PendingWaitTime = &d
// Don't wait so long for retries (pending, mergeability)
config.BaseWaitTime = time.Millisecond

stateSet := ""
wasMerged := false
Expand Down

0 comments on commit c694368

Please sign in to comment.