fix(19.8-03): conga worker tests read the startup summary from diary records

- queue:work and schedule:run print their summary block only on a
  terminal; off one (the test's buffer) they log 'startup summary' and
  'shutdown report' records of component queue/schedule, so the tests
  still asserted the pre-19.8 Info lines
- captureDiary bootstraps diary on a buffer; TestQueueWork and
  TestScheduleRunForeground wait for the startup summary record and
  check the shutdown report record
This commit is contained in:
Jakub Zych
2026-10-21 14:01:14 +02:00
parent 7170c5bac6
commit 205764300e
2 changed files with 51 additions and 6 deletions

View File

@@ -11,6 +11,7 @@ import (
"time"
"git.golem15.com/golem15/summercms/modules/bonfire"
"git.golem15.com/golem15/summercms/modules/diary"
)
// TestQueueClear covers D-05 and CLI-06: available, scheduled and
@@ -164,6 +165,17 @@ func (b *syncBuffer) String() string {
return b.buf.String()
}
// captureDiary sends every diary record to the returned buffer until the
// test ends. Off a terminal queue:work and schedule:run report through
// records (component queue or schedule), not through their Output.
func captureDiary(t *testing.T) *syncBuffer {
t.Helper()
logs := newSyncBuffer()
diary.Bootstrap(logs, diary.Options{Color: bonfire.ColorNever})
t.Cleanup(diary.Reset)
return logs
}
// TestQueueWork covers CLI-06 and D-17: queue:work runs a filtered worker
// until its context ends and rejects unknown queues naming the known ones;
// serve runs a worker on every known queue unless queue.work_in_serve is
@@ -185,6 +197,7 @@ func TestQueueWork(t *testing.T) {
})
t.Run("runs_until_cancelled", func(t *testing.T) {
logs := captureDiary(t)
out := newSyncBuffer()
root, err := bonfire.NewRoot("acme", RuntimeCommands(commandApp(t, dsn, nil), nil), out)
if err != nil {
@@ -195,10 +208,19 @@ func TestQueueWork(t *testing.T) {
defer cancel()
done := make(chan error, 1)
go func() { done <- root.ExecuteContext(ctx) }()
// Off a terminal the startup summary is a record, not a block.
started := func() bool {
for _, line := range strings.Split(logs.String(), "\n") {
if strings.Contains(line, `msg="startup summary"`) && strings.Contains(line, "component=queue") && strings.Contains(line, "queues=default") {
return true
}
}
return false
}
deadline := time.Now().Add(10 * time.Second)
for !strings.Contains(out.String(), "worker started on queues: default") {
for !started() {
if time.Now().After(deadline) {
t.Fatalf("worker did not start: %q", out.String())
t.Fatalf("worker did not start: out %q, logs:\n%s", out.String(), logs.String())
}
time.Sleep(25 * time.Millisecond)
}
@@ -211,6 +233,12 @@ func TestQueueWork(t *testing.T) {
case <-time.After(15 * time.Second):
t.Fatal("queue:work did not stop")
}
if got := logs.String(); !strings.Contains(got, `msg="shutdown report"`) || !strings.Contains(got, "jobs_failed=0") {
t.Fatalf("no shutdown report record:\n%s", got)
}
if strings.Contains(out.String(), "Worker started") {
t.Fatalf("the summary block printed off a terminal: %q", out.String())
}
})
t.Run("serve_worker", func(t *testing.T) {

View File

@@ -564,6 +564,7 @@ func TestScheduleRunForeground(t *testing.T) {
}})); err != nil {
t.Fatal(err)
}
logs := captureDiary(t)
out := newSyncBuffer()
root, err := bonfire.NewRoot("acme", RuntimeCommands(app, schedulePlugins(
pact.ScheduledCommand{Command: "acme:tick", Cadence: pact.Every(time.Second)},
@@ -579,12 +580,19 @@ func TestScheduleRunForeground(t *testing.T) {
select {
case <-ticked:
case err := <-done:
t.Fatalf("schedule:run returned early: %v (%q)", err, out.String())
t.Fatalf("schedule:run returned early: %v (%q)\n%s", err, out.String(), logs.String())
case <-time.After(10 * time.Second):
t.Fatalf("scheduled command did not run: %q", out.String())
t.Fatalf("scheduled command did not run: %q\n%s", out.String(), logs.String())
}
if !strings.Contains(out.String(), "scheduler started") {
t.Fatalf("out = %q", out.String())
// Off a terminal the startup summary is a record of component schedule.
var summary string
for _, line := range strings.Split(logs.String(), "\n") {
if strings.Contains(line, `msg="startup summary"`) && strings.Contains(line, "component=schedule") {
summary = line
}
}
if summary == "" || !strings.Contains(summary, `next="acme:tick at `) {
t.Fatalf("no schedule startup summary record (out %q):\n%s", out.String(), logs.String())
}
m, err := From(app)
if err != nil {
@@ -605,6 +613,15 @@ func TestScheduleRunForeground(t *testing.T) {
case <-time.After(15 * time.Second):
t.Fatal("schedule:run did not stop")
}
reported := false
for _, line := range strings.Split(logs.String(), "\n") {
if strings.Contains(line, `msg="shutdown report"`) && strings.Contains(line, "component=schedule") {
reported = true
}
}
if !reported {
t.Fatalf("no schedule shutdown report record:\n%s", logs.String())
}
}
// TestScheduleValidation covers the CLI-04 refusals: an empty command, a