37 lines
1.0 KiB
Go
37 lines
1.0 KiB
Go
package libraryfreeze
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
type pendingStopControl struct{ *fixtureControl }
|
|
|
|
func (c *pendingStopControl) Stop(context.Context, string) error {
|
|
return errors.New("stop may complete later")
|
|
}
|
|
func TestFreezeUncertainStopCannotBecomeTerminalWhileStillRunning(t *testing.T) {
|
|
_, c, e := freezeFixture(t)
|
|
e.control = &pendingStopControl{c}
|
|
_, err := e.Run(context.Background(), "uncertain", func(context.Context) (string, error) { t.Fatal("capture after uncertain stop"); return "", nil })
|
|
if err == nil {
|
|
t.Fatal("uncertain stop succeeded")
|
|
}
|
|
j, err := e.load("uncertain")
|
|
if err != nil || terminal(j.State) {
|
|
t.Fatal("running now was treated as proof that delayed stop cannot happen")
|
|
}
|
|
if err = e.Recover(context.Background()); err == nil {
|
|
t.Fatal("uncertain running stop falsely recovered")
|
|
}
|
|
c.services[0].Running = false
|
|
c.services[0].Healthy = false
|
|
if err = e.Recover(context.Background()); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !c.services[0].Running {
|
|
t.Fatal("delayed stop not restored")
|
|
}
|
|
}
|