Skip to content

Commit

Permalink
Fix tests flakiness
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Matyushentsev authored and Alexander Matyushentsev committed Jun 11, 2019
1 parent 3234a42 commit 9919549
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
9 changes: 9 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ required = [
[[override]]
name = "k8s.io/apimachinery"
branch = "release-1.12"

[[constraint]]
name = "github.com/bouk/monkey"
version = "1.0.0"
2 changes: 2 additions & 0 deletions controller/bluegreen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ func TestBlueGreenSetPreviewService(t *testing.T) {

func TestBlueGreenHandlePause(t *testing.T) {
t.Run("AddPause", func(t *testing.T) {
defer freezeNowAt(time.Now())

f := newFixture(t)

r1 := newBlueGreenRollout("foo", 1, nil, "active", "preview")
Expand Down
14 changes: 10 additions & 4 deletions controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ import (
informers "github.com/argoproj/argo-rollouts/pkg/client/informers/externalversions"
"github.com/argoproj/argo-rollouts/utils/annotations"
"github.com/argoproj/argo-rollouts/utils/conditions"
"github.com/bouk/monkey"
)

var (
alwaysReady = func() bool { return true }
noResyncPeriodFunc = func() time.Duration { return 0 }
)

Expand Down Expand Up @@ -314,9 +314,6 @@ func (f *fixture) newController(resync resyncFunc) (*Controller, informers.Share
resync(),
DefaultMetricsPort)

c.rolloutsSynced = alwaysReady
c.replicaSetSynced = alwaysReady
c.servicesSynced = alwaysReady
c.recorder = &record.FakeRecorder{}
c.enqueueRollout = func(obj interface{}) {
var key string
Expand Down Expand Up @@ -350,6 +347,13 @@ func (f *fixture) newController(resync resyncFunc) (*Controller, informers.Share
return c, i, k8sI
}

func freezeNowAt(now time.Time) func() {
patch := monkey.Patch(time.Now, func() time.Time { return now })
return func() {
patch.Unpatch()
}
}

func (f *fixture) run(rolloutName string) {
c, i, k8sI := f.newController(noResyncPeriodFunc)
f.runController(rolloutName, true, false, c, i, k8sI)
Expand All @@ -366,6 +370,8 @@ func (f *fixture) runController(rolloutName string, startInformers bool, expectE
defer close(stopCh)
i.Start(stopCh)
k8sI.Start(stopCh)

assert.True(f.t, cache.WaitForCacheSync(stopCh, c.replicaSetSynced, c.servicesSynced, c.rolloutsSynced))
}

err := c.syncHandler(rolloutName)
Expand Down

0 comments on commit 9919549

Please sign in to comment.