Skip to content

Commit

Permalink
Add abortChan
Browse files Browse the repository at this point in the history
  • Loading branch information
sebrandon1 committed Dec 1, 2023
1 parent 4ca4216 commit e4d4fd0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
12 changes: 12 additions & 0 deletions pkg/checksdb/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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...)
}
Expand Down
10 changes: 9 additions & 1 deletion pkg/checksdb/checksdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pkg/checksdb/checksgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e4d4fd0

Please sign in to comment.