github.com/asynkron/protoactor-go@v0.0.0-20240308120642-ef91a6abee75/cluster/cluster_test_tool/wait_helper.go (about)

     1  package cluster_test_tool
     2  
     3  import (
     4  	"runtime/debug"
     5  	"testing"
     6  	"time"
     7  )
     8  
     9  const DefaultWaitTimeout = time.Second * 5
    10  
    11  func WaitUntil(t testing.TB, cond func() bool, errorMsg string, timeout time.Duration) {
    12  	after := time.After(timeout)
    13  
    14  	for {
    15  		select {
    16  		case <-after:
    17  			t.Error(errorMsg)
    18  			debug.PrintStack()
    19  		default:
    20  			if cond() {
    21  				return
    22  			}
    23  			time.Sleep(100 * time.Millisecond)
    24  		}
    25  	}
    26  }