56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestStartStopRestartIdempotent(t *testing.T) {
|
|
rt := &Runtime{}
|
|
ctx := context.Background()
|
|
if err := rt.Start(ctx); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := rt.Start(ctx); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if rt.StartCount() != 1 {
|
|
t.Fatalf("duplicate Start spawned workers: starts=%d", rt.StartCount())
|
|
}
|
|
if got := rt.SubscriberCount(); got != 1 {
|
|
t.Fatalf("subscribers=%d", got)
|
|
}
|
|
if !rt.Running() {
|
|
t.Fatal("expected running")
|
|
}
|
|
if err := rt.Stop(ctx); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if rt.Running() {
|
|
t.Fatal("expected stopped")
|
|
}
|
|
if err := rt.Start(ctx); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if rt.StartCount() != 2 {
|
|
t.Fatalf("restart did not relaunch worker: starts=%d", rt.StartCount())
|
|
}
|
|
if rt.SubscriberCount() != 1 {
|
|
t.Fatalf("restart re-registered subscribers: %d", rt.SubscriberCount())
|
|
}
|
|
_ = rt.Stop(ctx)
|
|
time.Sleep(10 * time.Millisecond)
|
|
}
|
|
|
|
func TestWriterLiveNilRuntime(t *testing.T) {
|
|
var rt *Runtime
|
|
if rt.WriterLive(context.Background(), "notify") {
|
|
t.Fatal("nil runtime must not skip hooks")
|
|
}
|
|
rt = &Runtime{}
|
|
if rt.WriterLive(context.Background(), "notify") {
|
|
t.Fatal("unwired runtime must keep hook writers")
|
|
}
|
|
}
|