You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

46 lines
1.2 KiB

package startup
import (
"errors"
"testing"
"time"
)
func TestFailureNeverBecomesReady(t *testing.T) {
b := New(time.Now())
b.Add("config", "config")
b.Add("health", "health")
_ = b.Run("config", time.Second, func() error { return errors.New("private detail") })
_ = b.Run("health", time.Second, func() error { return nil })
s := b.Snapshot()
if s.Ready || s.State != "failed" || s.Completed != 1 {
t.Fatalf("%+v", s)
}
}
func TestTimeoutIgnoresLateSuccess(t *testing.T) {
b := New(time.Now())
b.Add("config", "config")
release := make(chan struct{})
returned := make(chan struct{})
err := b.Run("config", time.Millisecond, func() error { <-release; close(returned); return nil })
if err == nil {
t.Fatal("expected timeout")
}
close(release)
<-returned
if b.Snapshot().Ready || b.Snapshot().State != "failed" {
t.Fatal("late result opened login")
}
}
func TestReadyTimeIsFrozenAndSnapshotIsIndependent(t *testing.T) {
b := New(time.Now())
b.Add("config", "config")
_ = b.Run("config", time.Second, func() error { return nil })
s := b.Snapshot()
s.Stages[0].State = "failed"
time.Sleep(2 * time.Millisecond)
next := b.Snapshot()
if !next.Ready || next.ElapsedMS != s.ElapsedMS {
t.Fatalf("%+v", next)
}
}