github.com/iotexproject/iotex-core@v1.14.1-rc1/testutil/wait_test.go (about) 1 // Copyright (c) 2018 IoTeX 2 // This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability 3 // or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed. 4 // This source code is governed by Apache License 2.0 that can be found in the LICENSE file. 5 6 package testutil 7 8 import ( 9 "testing" 10 "time" 11 12 "github.com/stretchr/testify/assert" 13 ) 14 15 func TestWaitUntil(t *testing.T) { 16 assert := assert.New(t) 17 threshold := time.Now() 18 check1 := CheckCondition(func() (bool, error) { 19 return time.Now().UnixNano() > threshold.UnixNano()+int64(1000), nil 20 }) 21 err := WaitUntil(time.Millisecond, time.Second, check1) 22 assert.Nil(err) 23 check2 := CheckCondition(func() (bool, error) { 24 return time.Now().UnixNano() > threshold.UnixNano()+int64(1000000000), nil 25 }) 26 err = WaitUntil(time.Millisecond, time.Millisecond*10, check2) 27 assert.Equal(ErrTimeout, err) 28 }