@@ -25,6 +25,7 @@ import (
2525 "github.com/medik8s/self-node-remediation/controllers"
2626 "github.com/medik8s/self-node-remediation/controllers/tests/shared"
2727 "github.com/medik8s/self-node-remediation/pkg/utils"
28+ "github.com/medik8s/self-node-remediation/pkg/watchdog"
2829)
2930
3031const (
@@ -44,6 +45,9 @@ var _ = Describe("SNR Controller", func() {
4445 snr .Namespace = snrNamespace
4546 snrConfig = shared .GenerateTestConfig ()
4647 time .Sleep (time .Second * 2 )
48+
49+ // reset watchdog for each test!
50+ dummyDog .Reset ()
4751 })
4852
4953 JustBeforeEach (func () {
@@ -183,7 +187,7 @@ var _ = Describe("SNR Controller", func() {
183187
184188 verifyTimeHasBeenRebootedExists (snr )
185189
186- verifyNoWatchdogFood ()
190+ verifyWatchdogTriggered ()
187191
188192 verifyEvent ("Normal" , "NodeReboot" , "Remediation process - about to attempt fencing the unhealthy node by rebooting it" )
189193
@@ -233,7 +237,7 @@ var _ = Describe("SNR Controller", func() {
233237
234238 verifyTimeHasBeenRebootedExists (snr )
235239
236- verifyNoWatchdogFood ()
240+ verifyWatchdogTriggered ()
237241
238242 // The kube-api calls for VA fail intentionally. In this case, we expect the snr agent to try
239243 // to delete node resources again. So LastError is set to the error every time Reconcile()
@@ -315,7 +319,7 @@ var _ = Describe("SNR Controller", func() {
315319
316320 verifyTimeHasBeenRebootedExists (snr )
317321
318- verifyNoWatchdogFood ()
322+ verifyWatchdogTriggered ()
319323
320324 verifyFinalizerExists (snr )
321325
@@ -436,30 +440,16 @@ var _ = Describe("SNR Controller", func() {
436440 })
437441
438442 Context ("Unhealthy node without api-server access" , func () {
439-
440- // this is not a controller test anymore... it's testing peers. But keep it here for now...
441-
442443 BeforeEach (func () {
443444 By ("Simulate api-server failure" )
444445 k8sClient .ShouldSimulateFailure = true
445446 remediationStrategy = v1alpha1 .ResourceDeletionRemediationStrategy
446447 })
447448
448- It ("Verify that watchdog is not receiving food after some time" , func () {
449- lastFoodTime := dummyDog .LastFoodTime ()
450- timeout := dummyDog .GetTimeout ()
451- Eventually (func () bool {
452- newTime := dummyDog .LastFoodTime ()
453- // ensure the timeout passed
454- timeoutPassed := time .Now ().After (lastFoodTime .Add (3 * timeout ))
455- // ensure wd wasn't feeded
456- missedFeed := newTime .Before (lastFoodTime .Add (timeout ))
457- if timeoutPassed && missedFeed {
458- return true
459- }
460- lastFoodTime = newTime
461- return false
462- }, 10 * shared .PeerUpdateInterval , timeout ).Should (BeTrue ())
449+ Context ("no peer found" , func () {
450+ It ("Verify that watchdog is not triggered" , func () {
451+ verifyWatchdogNotTriggered ()
452+ })
463453 })
464454 })
465455
@@ -532,12 +522,16 @@ func verifyNodeIsSchedulable() {
532522 }, 95 * time .Second , 250 * time .Millisecond ).Should (BeFalse ())
533523}
534524
535- func verifyNoWatchdogFood () {
536- By ("Verify that watchdog is not receiving food" )
537- currentLastFoodTime := dummyDog .LastFoodTime ()
538- ConsistentlyWithOffset (1 , func () time.Time {
539- return dummyDog .LastFoodTime ()
540- }, 5 * dummyDog .GetTimeout (), 1 * time .Second ).Should (Equal (currentLastFoodTime ), "watchdog should not receive food anymore" )
525+ func verifyWatchdogTriggered () {
526+ EventuallyWithOffset (1 , func (g Gomega ) {
527+ g .Expect (dummyDog .Status ()).To (Equal (watchdog .Triggered ))
528+ }, 5 * dummyDog .GetTimeout (), 1 * time .Second ).Should (Succeed (), "watchdog should be triggered" )
529+ }
530+
531+ func verifyWatchdogNotTriggered () {
532+ ConsistentlyWithOffset (1 , func (g Gomega ) {
533+ g .Expect (dummyDog .Status ()).To (Equal (watchdog .Armed ))
534+ }, 5 * dummyDog .GetTimeout (), 1 * time .Second ).Should (Succeed (), "watchdog should not be triggered" )
541535}
542536
543537func verifyFinalizerExists (snr * v1alpha1.SelfNodeRemediation ) {
0 commit comments