Skip to content

Commit

Permalink
test: Deflake deprovisioning testing (#203)
Browse files Browse the repository at this point in the history
* Deflake deprovisioning testing

* Wait for verify action before completing test
  • Loading branch information
jonathan-innis authored Feb 10, 2023
1 parent 6abab23 commit d045564
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 66 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ test: ## Run tests
go test ./... \
-race \
--ginkgo.focus="${FOCUS}" \
--ginkgo.v \
-cover -coverprofile=coverage.out -outputdir=. -coverpkg=./...

deflake: ## Run randomized, racing tests until the test fails to catch flakes
Expand Down
1 change: 1 addition & 0 deletions hack/toolchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ tools() {
go install github.com/sigstore/cosign/cmd/cosign@v1.10.0
go install github.com/gohugoio/hugo@v0.97.3+extended
go install golang.org/x/vuln/cmd/govulncheck@v0.0.0-20220902211423-27dd78d2ca39
go install github.com/onsi/ginkgo/v2/ginkgo@latest

if ! echo "$PATH" | grep -q "${GOPATH:-undefined}/bin\|$HOME/go/bin"; then
echo "Go workspace's \"bin\" directory is not in PATH. Run 'export PATH=\"\$PATH:\${GOPATH:-\$HOME/go}/bin\"'."
Expand Down
31 changes: 23 additions & 8 deletions pkg/controllers/deprovisioning/drift_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ limitations under the License.
package deprovisioning_test

import (
"sync"
"time"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -61,9 +62,11 @@ var _ = Describe("Drift", func() {
// inform cluster state about the nodes
ExpectReconcileSucceeded(ctx, nodeStateController, client.ObjectKeyFromObject(node))
fakeClock.Step(10 * time.Minute)
go triggerVerifyAction()
var wg sync.WaitGroup
ExpectTriggerVerifyAction(&wg)
_, err := deprovisioningController.Reconcile(ctx, reconcile.Request{})
Expect(err).ToNot(HaveOccurred())
wg.Wait()

Expect(cloudProvider.CreateCalls).To(HaveLen(0))
ExpectExists(ctx, env.Client, node)
Expand Down Expand Up @@ -93,9 +96,12 @@ var _ = Describe("Drift", func() {
// inform cluster state about the nodes
ExpectReconcileSucceeded(ctx, nodeStateController, client.ObjectKeyFromObject(node))
fakeClock.Step(10 * time.Minute)
go triggerVerifyAction()

var wg sync.WaitGroup
ExpectTriggerVerifyAction(&wg)
_, err := deprovisioningController.Reconcile(ctx, reconcile.Request{})
Expect(err).ToNot(HaveOccurred())
wg.Wait()

Expect(cloudProvider.CreateCalls).To(HaveLen(0))
ExpectExists(ctx, env.Client, node)
Expand Down Expand Up @@ -154,9 +160,11 @@ var _ = Describe("Drift", func() {
// inform cluster state about the nodes
ExpectReconcileSucceeded(ctx, nodeStateController, client.ObjectKeyFromObject(node))
fakeClock.Step(10 * time.Minute)
go triggerVerifyAction()
var wg sync.WaitGroup
ExpectTriggerVerifyAction(&wg)
_, err := deprovisioningController.Reconcile(ctx, reconcile.Request{})
Expect(err).ToNot(HaveOccurred())
wg.Wait()

// we don't need a new node, but we should evict everything off one of node2 which only has a single pod
Expect(cloudProvider.CreateCalls).To(HaveLen(0))
Expand Down Expand Up @@ -207,9 +215,11 @@ var _ = Describe("Drift", func() {
Expect(env.Client.Get(ctx, client.ObjectKeyFromObject(node), node)).To(Succeed())

// deprovisioning won't delete the old node until the new node is ready
wg := ExpectMakeNewNodesReady(ctx, env.Client, 1, node)
var wg sync.WaitGroup
ExpectTriggerVerifyAction(&wg)
ExpectMakeNewNodesReady(ctx, env.Client, &wg, 1, node)

fakeClock.Step(10 * time.Minute)
go triggerVerifyAction()
_, err := deprovisioningController.Reconcile(ctx, reconcile.Request{})
Expect(err).ToNot(HaveOccurred())
wg.Wait()
Expand Down Expand Up @@ -299,9 +309,11 @@ var _ = Describe("Drift", func() {
Expect(env.Client.Get(ctx, client.ObjectKeyFromObject(node), node)).To(Succeed())

// deprovisioning won't delete the old node until the new node is ready
wg := ExpectMakeNewNodesReady(ctx, env.Client, 3, node)
var wg sync.WaitGroup
ExpectTriggerVerifyAction(&wg)
ExpectMakeNewNodesReady(ctx, env.Client, &wg, 3, node)

fakeClock.Step(10 * time.Minute)
go triggerVerifyAction()
_, err := deprovisioningController.Reconcile(ctx, reconcile.Request{})
Expect(err).ToNot(HaveOccurred())
wg.Wait()
Expand Down Expand Up @@ -344,10 +356,13 @@ var _ = Describe("Drift", func() {
// inform cluster state about the nodes
ExpectReconcileSucceeded(ctx, nodeStateController, client.ObjectKeyFromObject(node1))
ExpectReconcileSucceeded(ctx, nodeStateController, client.ObjectKeyFromObject(node2))

fakeClock.Step(10 * time.Minute)
go triggerVerifyAction()
var wg sync.WaitGroup
ExpectTriggerVerifyAction(&wg)
_, err := deprovisioningController.Reconcile(ctx, reconcile.Request{})
Expect(err).ToNot(HaveOccurred())
wg.Wait()

// we don't need a new node, but we should evict everything off one of node2 which only has a single pod
Expect(cloudProvider.CreateCalls).To(HaveLen(0))
Expand Down
28 changes: 21 additions & 7 deletions pkg/controllers/deprovisioning/expiration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ limitations under the License.
package deprovisioning_test

import (
"sync"
"time"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -86,10 +87,14 @@ var _ = Describe("Expiration", func() {

// inform cluster state about the nodes
ExpectReconcileSucceeded(ctx, nodeStateController, client.ObjectKeyFromObject(node))

fakeClock.Step(10 * time.Minute)
go triggerVerifyAction()

var wg sync.WaitGroup
ExpectTriggerVerifyAction(&wg)
_, err := deprovisioningController.Reconcile(ctx, reconcile.Request{})
Expect(err).ToNot(HaveOccurred())
wg.Wait()

// we don't need a new node, but we should evict everything off one of node2 which only has a single pod
Expect(cloudProvider.CreateCalls).To(HaveLen(0))
Expand Down Expand Up @@ -130,10 +135,13 @@ var _ = Describe("Expiration", func() {
// inform cluster state about the nodes
ExpectReconcileSucceeded(ctx, nodeStateController, client.ObjectKeyFromObject(nodeToExpire))
ExpectReconcileSucceeded(ctx, nodeStateController, client.ObjectKeyFromObject(nodeNotExpire))

fakeClock.Step(10 * time.Minute)
go triggerVerifyAction()
var wg sync.WaitGroup
ExpectTriggerVerifyAction(&wg)
_, err := deprovisioningController.Reconcile(ctx, reconcile.Request{})
Expect(err).ToNot(HaveOccurred())
wg.Wait()

// we don't need a new node, but we should evict everything off one of node2 which only has a single pod
Expect(cloudProvider.CreateCalls).To(HaveLen(0))
Expand Down Expand Up @@ -183,9 +191,11 @@ var _ = Describe("Expiration", func() {
Expect(env.Client.Get(ctx, client.ObjectKeyFromObject(node), node)).To(Succeed())

// deprovisioning won't delete the old node until the new node is ready
wg := ExpectMakeNewNodesReady(ctx, env.Client, 1, node)
var wg sync.WaitGroup
ExpectTriggerVerifyAction(&wg)
ExpectMakeNewNodesReady(ctx, env.Client, &wg, 1, node)

fakeClock.Step(10 * time.Minute)
go triggerVerifyAction()
_, err := deprovisioningController.Reconcile(ctx, reconcile.Request{})
Expect(err).ToNot(HaveOccurred())
wg.Wait()
Expand Down Expand Up @@ -275,9 +285,11 @@ var _ = Describe("Expiration", func() {
Expect(env.Client.Get(ctx, client.ObjectKeyFromObject(node), node)).To(Succeed())

fakeClock.Step(10 * time.Minute)
go triggerVerifyAction()
var wg sync.WaitGroup
ExpectTriggerVerifyAction(&wg)
_, err := deprovisioningController.Reconcile(ctx, reconcile.Request{})
Expect(err).To(HaveOccurred())
wg.Wait()

// Expiration should try to make 3 calls but fail for the third.
Expect(cloudProvider.CreateCalls).To(HaveLen(3))
Expand Down Expand Up @@ -365,9 +377,11 @@ var _ = Describe("Expiration", func() {
Expect(env.Client.Get(ctx, client.ObjectKeyFromObject(node), node)).To(Succeed())

// deprovisioning won't delete the old node until the new node is ready
wg := ExpectMakeNewNodesReady(ctx, env.Client, 3, node)
var wg sync.WaitGroup
ExpectTriggerVerifyAction(&wg)
ExpectMakeNewNodesReady(ctx, env.Client, &wg, 3, node)

fakeClock.Step(10 * time.Minute)
go triggerVerifyAction()
_, err := deprovisioningController.Reconcile(ctx, reconcile.Request{})
Expect(err).ToNot(HaveOccurred())
wg.Wait()
Expand Down
Loading

0 comments on commit d045564

Please sign in to comment.