From e4d4fd09781c927dfccf4707df1d60fa07868c07 Mon Sep 17 00:00:00 2001 From: Brandon Palm Date: Fri, 1 Dec 2023 15:13:15 -0600 Subject: [PATCH] Add abortChan --- .../lifecycle/podrecreation/podrecreation.go | 2 +- pkg/checksdb/check.go | 12 ++++++++++++ pkg/checksdb/checksdb.go | 10 +++++++++- pkg/checksdb/checksgroup.go | 3 ++- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/cnf-certification-test/lifecycle/podrecreation/podrecreation.go b/cnf-certification-test/lifecycle/podrecreation/podrecreation.go index 0ff9ad2bed..7bb18b291d 100644 --- a/cnf-certification-test/lifecycle/podrecreation/podrecreation.go +++ b/cnf-certification-test/lifecycle/podrecreation/podrecreation.go @@ -144,7 +144,7 @@ func CordonCleanup(node string, check *checksdb.Check) { err := CordonHelper(node, Uncordon) if err != nil { logrus.Errorf("cleanup: error uncordoning the node: %s, err=%s", node, err) - check.SetResultAborted(fmt.Sprintf("cleanup: error uncordoning the node: %s, err=%s", node, err)) + check.Abort() } } diff --git a/pkg/checksdb/check.go b/pkg/checksdb/check.go index 1fa97af2b5..1cf5730043 100644 --- a/pkg/checksdb/check.go +++ b/pkg/checksdb/check.go @@ -54,6 +54,7 @@ type Check struct { StartTime, EndTime time.Time Timeout time.Duration Error error + abortChan chan bool } func NewCheck(id string, labels []string) *Check { @@ -69,6 +70,17 @@ func NewCheck(id string, labels []string) *Check { return check } +func (check *Check) Abort() { + check.mutex.Lock() + defer check.mutex.Unlock() + + check.abortChan <- true +} + +func (check *Check) SetAbortChan(abortChan chan bool) { + check.abortChan = abortChan +} + func (check *Check) LogDebug(msg string, args ...any) { log.Logf(check.logger, slog.LevelDebug, msg, args...) } diff --git a/pkg/checksdb/checksdb.go b/pkg/checksdb/checksdb.go index df02b7b291..4c768a84db 100644 --- a/pkg/checksdb/checksdb.go +++ b/pkg/checksdb/checksdb.go @@ -49,17 +49,25 @@ func RunChecks(labelsExpr string, timeout time.Duration) error { // Stop channel, so we can send a stop signal to group.RunChecks() stopChan := make(chan bool, 1) + abortChan := make(chan bool, 1) // Done channel for the goroutine that runs group.RunChecks(). groupDone := make(chan bool) go func() { - errs = append(errs, group.RunChecks(labelsExpr, stopChan)...) + errs = append(errs, group.RunChecks(labelsExpr, stopChan, abortChan)...) groupDone <- true }() select { case <-groupDone: logrus.Tracef("Group %s finished running checks.", group.name) + case <-abortChan: + logrus.Warnf("Group %s aborted.", group.name) + stopChan <- true + + abort = true + abortReason = "Test suite aborted due to error" + _ = group.OnAbort(labelsExpr, abortReason) case <-timeOutChan: logrus.Warnf("Running all checks timed-out.") stopChan <- true diff --git a/pkg/checksdb/checksgroup.go b/pkg/checksdb/checksgroup.go index 08f1a7f049..e400867754 100644 --- a/pkg/checksdb/checksgroup.go +++ b/pkg/checksdb/checksgroup.go @@ -282,7 +282,7 @@ func runCheck(check *Check, group *ChecksGroup, remainingChecks []*Check) (err e // - AfterEach panic: Set check as error. // //nolint:funlen -func (group *ChecksGroup) RunChecks(labelsExpr string, stopChan <-chan bool) (errs []error) { +func (group *ChecksGroup) RunChecks(labelsExpr string, stopChan <-chan bool, abortChan chan bool) (errs []error) { logrus.Infof("Running group %q checks.", group.name) labelsExprEvaluator, err := NewLabelsExprEvaluator(labelsExpr) @@ -346,6 +346,7 @@ func (group *ChecksGroup) RunChecks(labelsExpr string, stopChan <-chan bool) (er if skip { skipCheck(check, strings.Join(reasons, ", ")) } else { + check.SetAbortChan(abortChan) // Set the abort channel for the check. err := runCheck(check, group, remainingChecks) if err != nil { errs = append(errs, err)