Skip to content

Commit

Permalink
Fix flaky test when reconciler start before previous one still up
Browse files Browse the repository at this point in the history
between test, the reconciler is stopped and started again.
Stop is not instant but we started a new instance right away.
Since it bind a port, the new one crashed because the old
one didn't release it yet. Instead we wait for the manager to
be properly down before starting a new one
  • Loading branch information
geobeau committed Nov 24, 2023
1 parent 8bbcee2 commit 7b330a0
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions internal/controller/nodedisruption_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func clearAllNodeDisruptionRessources() {

}

func startReconcilerWithConfig(config NodeDisruptionReconcilerConfig) (cancelFn context.CancelFunc) {
func startReconcilerWithConfig(config NodeDisruptionReconcilerConfig) context.CancelFunc {
k8sManager, err := ctrl.NewManager(cfg, ctrl.Options{
MetricsBindAddress: "127.0.0.1:8081",
PprofBindAddress: "127.0.0.1:8082",
Expand All @@ -83,14 +83,22 @@ func startReconcilerWithConfig(config NodeDisruptionReconcilerConfig) (cancelFn
}).SetupWithManager(k8sManager)
Expect(err).ToNot(HaveOccurred())

managerCtx, cancelFn := context.WithCancel(context.Background())
managerCtx, cancel := context.WithCancel(context.Background())

shutdownChan := make(chan bool, 1)

go func() {
defer GinkgoRecover()
err = k8sManager.Start(managerCtx)
Expect(err).ToNot(HaveOccurred(), "failed to run manager")
shutdownChan <- true
}()
return cancelFn

return func() {
cancel()
// Ensure the manager is actually stopped to avoid starting a new manager too early
<-shutdownChan
}
}

func startDummyHTTPServer(handle http.HandlerFunc, listenAddr string) (cancelFn func()) {
Expand Down

0 comments on commit 7b330a0

Please sign in to comment.