Move construction and document OnOutbox out of server, give HTTP/CLI a shared task use case, and block already-cleared import/event arch rules. Co-authored-by: Cursor <cursoragent@cursor.com>
45 lines
939 B
Go
45 lines
939 B
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)
|
|
}
|