blob: c5eb98dbe40da07ccd1210f6d973cc9276141b86 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
package transporthealth
import (
"context"
"errors"
"testing"
"time"
)
type checkerFunc func(context.Context) error
func (f checkerFunc) Check(ctx context.Context) error {
return f(ctx)
}
func TestProbeTracksReadiness(t *testing.T) {
var checkErr error
monitor := New(checkerFunc(func(context.Context) error { return checkErr }), time.Minute, time.Second)
monitor.Probe(context.Background())
if !monitor.Ready() {
t.Fatal("successful probe did not mark transport ready")
}
checkErr = errors.New("transport unavailable")
monitor.Probe(context.Background())
if monitor.Ready() {
t.Fatal("failed probe left transport ready")
}
}
|