LK4D4 / testpoller

testpoller - Simple polling for tests

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

testpoller - Simple polling for tests.

Build Status GoDoc

Sometimes you're not sure when the event will happen, using just big sleep is one way, but it needs to be big enough to satisfy even slow machines. You can use "polling" for speeding up your tests.

testpoller calls some func repeatedly until it returns true or error. It also consumes context, which can be used to control polling time.

It's very easy to use:

p := testpoller.New().WithInterval(500 * time.Millisecond)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Millisecond)
err := p.Poll(ctx, func() (bool, error) {
	err := cluster.IsLeader()
	if err != nil {
		if isNotLeader(err) {
			return false, nil
		}
		return false, err
	}
	return true, nil
})

About

testpoller - Simple polling for tests

License:MIT License


Languages

Language:Go 100.0%