...

Source file src/edge-infra.dev/test/f2/x/ktest/kpoll/result.go

Documentation: edge-infra.dev/test/f2/x/ktest/kpoll

     1  package kpoll
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"gotest.tools/v3/poll"
     8  )
     9  
    10  // JoinResults combines one or more polling results into a single
    11  // [gotest.tools/v3/poll.Result].
    12  //
    13  // At least one poll.Result must be provided. If a single poll.Result is passed
    14  // in, it is returned directly.
    15  //
    16  // If any results contain an error, it is immediately returned. Otherwise, all
    17  // unfinished results have their messages combined into a single
    18  // [gotest.tools/v3/poll.Continue] call. If all results indicate they are done,
    19  // [gotest.tools/v3/poll.Success] is returned.
    20  //
    21  // TODO(aw18576): Consider generalizing this
    22  func JoinResults(results ...poll.Result) poll.Result {
    23  	if len(results) == 0 {
    24  		return poll.Error(fmt.Errorf("can't join 0 results, need at least one"))
    25  	}
    26  	if len(results) == 1 {
    27  		return results[0] //nolint:gosec // I know the array has a length of 1
    28  	}
    29  
    30  	var msgs []string
    31  	for _, r := range results {
    32  		if r.Error() != nil {
    33  			return r
    34  		}
    35  		if !r.Done() {
    36  			msgs = append(msgs, r.Message())
    37  		}
    38  	}
    39  
    40  	if len(msgs) > 0 {
    41  		return poll.Continue("waiting on %d checks (%d/%d complete):\n%s",
    42  			len(msgs), len(results)-len(msgs), len(results), strings.Join(msgs, "\n\n"))
    43  	}
    44  	return poll.Success()
    45  }
    46  

View as plain text