github.com/cilium/cilium@v1.16.2/pkg/testutils/condition_test.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package testutils 5 6 import ( 7 "testing" 8 "time" 9 10 "github.com/stretchr/testify/require" 11 ) 12 13 func TestWaitUntil(t *testing.T) { 14 require.Error(t, WaitUntil(func() bool { return false }, 50*time.Millisecond)) 15 require.NoError(t, WaitUntil(func() bool { return true }, 50*time.Millisecond)) 16 17 counter := 0 18 countTo5 := func() bool { 19 if counter > 5 { 20 return true 21 } 22 counter++ 23 return false 24 } 25 26 require.Error(t, WaitUntil(countTo5, 1*time.Millisecond)) 27 28 counter = 0 29 require.NoError(t, WaitUntil(countTo5, time.Second)) 30 }