From 9da123ae5e30f8f57639bdff1ae2f2d56305bc9b Mon Sep 17 00:00:00 2001 From: Yusuke Kuoka Date: Thu, 25 Feb 2021 09:30:32 +0900 Subject: [PATCH] Fix integration test flakiness (#351) Ref https://github.com/summerwind/actions-runner-controller/pull/345#issuecomment-785015406 --- controllers/integration_test.go | 53 ++-------------------- controllers/runnerreplicaset_controller.go | 2 +- github/fake/runners.go | 15 ++++++ 3 files changed, 19 insertions(+), 51 deletions(-) diff --git a/controllers/integration_test.go b/controllers/integration_test.go index fc56f3c5..55db2edf 100644 --- a/controllers/integration_test.go +++ b/controllers/integration_test.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "github.com/google/go-github/v33/github" - github3 "github.com/google/go-github/v33/github" github2 "github.com/summerwind/actions-runner-controller/github" "k8s.io/apimachinery/pkg/runtime" "net/http" @@ -248,26 +247,7 @@ var _ = Context("INTEGRATION: Inside of a new namespace", func() { } { - var runnerList actionsv1alpha1.RunnerList - - err := k8sClient.List(ctx, &runnerList, client.InNamespace(ns.Name)) - if err != nil { - logf.Log.Error(err, "list runners") - } - - for i, r := range runnerList.Items { - env.fakeRunnerList.Add(&github3.Runner{ - ID: github.Int64(int64(i)), - Name: github.String(r.Name), - OS: github.String("linux"), - Status: github.String("online"), - Busy: github.Bool(false), - }) - } - - rs, err := env.ghClient.ListRunners(context.Background(), "", "", "test/valid") - Expect(err).NotTo(HaveOccurred(), "verifying list fake runners response") - Expect(len(rs)).To(Equal(3), "count of fake list runners") + env.ExpectRegisteredNumberCountEventuallyEquals(3, "count of fake runners after HRA creation") } // Scale-down to 1 replica @@ -478,26 +458,7 @@ var _ = Context("INTEGRATION: Inside of a new namespace", func() { } { - var runnerList actionsv1alpha1.RunnerList - - err := k8sClient.List(ctx, &runnerList, client.InNamespace(ns.Name)) - if err != nil { - logf.Log.Error(err, "list runners") - } - - for i, r := range runnerList.Items { - env.fakeRunnerList.Add(&github3.Runner{ - ID: github.Int64(int64(i)), - Name: github.String(r.Name), - OS: github.String("linux"), - Status: github.String("online"), - Busy: github.Bool(false), - }) - } - - rs, err := env.ghClient.ListRunners(context.Background(), "", "", "test/valid") - Expect(err).NotTo(HaveOccurred(), "verifying list fake runners response") - Expect(len(rs)).To(Equal(3), "count of fake list runners") + env.ExpectRegisteredNumberCountEventuallyEquals(3, "count of fake runners after HRA creation") } // Scale-down to 1 replica @@ -746,15 +707,7 @@ func (env *testEnvironment) SyncRunnerRegistrations() { logf.Log.Error(err, "list runners") } - for i, r := range runnerList.Items { - env.fakeRunnerList.Add(&github3.Runner{ - ID: github.Int64(int64(i)), - Name: github.String(r.Name), - OS: github.String("linux"), - Status: github.String("online"), - Busy: github.Bool(false), - }) - } + env.fakeRunnerList.Sync(runnerList.Items) } func ExpectCreate(ctx context.Context, rd runtime.Object, s string) { diff --git a/controllers/runnerreplicaset_controller.go b/controllers/runnerreplicaset_controller.go index f0c74c34..e47b4483 100644 --- a/controllers/runnerreplicaset_controller.go +++ b/controllers/runnerreplicaset_controller.go @@ -204,7 +204,7 @@ func (r *RunnerReplicaSetReconciler) Reconcile(req ctrl.Request) (ctrl.Result, e updated.Status.ReadyReplicas = ready if err := r.Status().Update(ctx, updated); err != nil { - log.Error(err, "Failed to update status. Retrying immediately") + log.Info("Failed to update status. Retrying immediately", "error", err.Error()) return ctrl.Result{ Requeue: true, }, nil diff --git a/github/fake/runners.go b/github/fake/runners.go index 01f2ac1d..d0484ddf 100644 --- a/github/fake/runners.go +++ b/github/fake/runners.go @@ -2,6 +2,7 @@ package fake import ( "encoding/json" + "github.com/summerwind/actions-runner-controller/api/v1alpha1" "net/http" "net/http/httptest" "strconv" @@ -64,6 +65,20 @@ func (r *RunnersList) handleRemove() http.HandlerFunc { } } +func (r *RunnersList) Sync(runners []v1alpha1.Runner) { + r.runners = nil + + for i, want := range runners { + r.Add(&github.Runner{ + ID: github.Int64(int64(i)), + Name: github.String(want.Name), + OS: github.String("linux"), + Status: github.String("online"), + Busy: github.Bool(false), + }) + } +} + func exists(runners []*github.Runner, runner *github.Runner) bool { for _, r := range runners { if *r.Name == *runner.Name {