feat(conga,dev): worker and scheduler reports, summer dev runs serve
- queue:work and schedule:run print a startup summary and a shutdown report on a terminal, log them as records otherwise, and return nil after a clean stop - schedule:run --once ends with 'Ran N due entries (M failed)' - summer dev runs bin/<app> serve with the forwarded global options, reports through Output, stops the old server before starting the new one and prints a dev report on Ctrl+C (exit 0) - lagoon.DatabaseLabel describes a DSN without its secrets - Long help and examples for queue:work, schedule:run, dev, docs:serve
This commit is contained in:
@@ -16,6 +16,7 @@ import (
|
||||
"time"
|
||||
|
||||
"git.golem15.com/golem15/summercms/internal/build"
|
||||
"git.golem15.com/golem15/summercms/modules/bonfire"
|
||||
)
|
||||
|
||||
type safeBuffer struct {
|
||||
@@ -35,6 +36,11 @@ func (s *safeBuffer) String() string {
|
||||
return s.b.String()
|
||||
}
|
||||
|
||||
// testOutput is a non-terminal bonfire console writing to w.
|
||||
func testOutput(w io.Writer) bonfire.Output {
|
||||
return bonfire.NewOutput(strings.NewReader(""), w, w)
|
||||
}
|
||||
|
||||
func TestWatchRebuildsOnSourceEdit(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
writeWatchApp(t, dir)
|
||||
@@ -53,7 +59,10 @@ func TestWatchRebuildsOnSourceEdit(t *testing.T) {
|
||||
fmt.Fprintln(w, "built hello in 1ms")
|
||||
return nil
|
||||
},
|
||||
Start: func(ctx context.Context, binPath string, stdout, stderr io.Writer) (*exec.Cmd, error) {
|
||||
Start: func(ctx context.Context, binPath string, args []string, stdout, stderr io.Writer) (*exec.Cmd, error) {
|
||||
if got := strings.Join(args, " "); got != "serve -v --env staging" {
|
||||
return nil, fmt.Errorf("start args = %q, want serve and the forwarded globals", got)
|
||||
}
|
||||
starts.Add(1)
|
||||
cmd := exec.Command("sleep", "30")
|
||||
if err := cmd.Start(); err != nil {
|
||||
@@ -64,7 +73,7 @@ func TestWatchRebuildsOnSourceEdit(t *testing.T) {
|
||||
}
|
||||
|
||||
done := make(chan error, 1)
|
||||
go func() { done <- watch(ctx, dir, &out, opts) }()
|
||||
go func() { done <- watch(ctx, dir, testOutput(&out), []string{"-v", "--env", "staging"}, opts) }()
|
||||
|
||||
waitUntil(t, "initial start", func() bool { return starts.Load() == 1 })
|
||||
if builds.Load() != 1 {
|
||||
@@ -91,15 +100,18 @@ func TestWatchRebuildsOnSourceEdit(t *testing.T) {
|
||||
}
|
||||
|
||||
got := out.String()
|
||||
if strings.Count(got, "rebuild:") != 2 {
|
||||
if strings.Count(got, "Rebuilt in ") != 2 {
|
||||
t.Fatalf("want 2 rebuild latency lines, got %q", got)
|
||||
}
|
||||
|
||||
cancel()
|
||||
select {
|
||||
case err := <-done:
|
||||
if err != nil && err != context.Canceled {
|
||||
t.Fatalf("watch exit: %v", err)
|
||||
if err != nil {
|
||||
t.Fatalf("watch returned %v after Ctrl+C, want nil (exit 0)", err)
|
||||
}
|
||||
if !strings.Contains(out.String(), "Dev report") || !strings.Contains(out.String(), "Restarts 1") {
|
||||
t.Fatalf("missing dev report:\n%s", out.String())
|
||||
}
|
||||
case <-time.After(3 * time.Second):
|
||||
t.Fatal("watch did not exit on cancel")
|
||||
@@ -127,7 +139,7 @@ func TestWatchKeepsChildOnBuildFailure(t *testing.T) {
|
||||
}
|
||||
return nil
|
||||
},
|
||||
Start: func(ctx context.Context, binPath string, stdout, stderr io.Writer) (*exec.Cmd, error) {
|
||||
Start: func(ctx context.Context, binPath string, args []string, stdout, stderr io.Writer) (*exec.Cmd, error) {
|
||||
starts.Add(1)
|
||||
cmd := exec.Command("sleep", "30")
|
||||
if err := cmd.Start(); err != nil {
|
||||
@@ -139,7 +151,7 @@ func TestWatchKeepsChildOnBuildFailure(t *testing.T) {
|
||||
}
|
||||
|
||||
done := make(chan error, 1)
|
||||
go func() { done <- watch(ctx, dir, &out, opts) }()
|
||||
go func() { done <- watch(ctx, dir, testOutput(&out), nil, opts) }()
|
||||
waitUntil(t, "initial start", func() bool { return starts.Load() == 1 })
|
||||
|
||||
if err := os.WriteFile(filepath.Join(dir, "plugin.go"), []byte("package p\n// bad\n"), 0o644); err != nil {
|
||||
@@ -192,7 +204,7 @@ func TestWatchDebouncesRapidEdits(t *testing.T) {
|
||||
builds.Add(1)
|
||||
return nil
|
||||
},
|
||||
Start: func(ctx context.Context, binPath string, stdout, stderr io.Writer) (*exec.Cmd, error) {
|
||||
Start: func(ctx context.Context, binPath string, args []string, stdout, stderr io.Writer) (*exec.Cmd, error) {
|
||||
cmd := exec.Command("sleep", "30")
|
||||
if err := cmd.Start(); err != nil {
|
||||
return nil, err
|
||||
@@ -201,7 +213,7 @@ func TestWatchDebouncesRapidEdits(t *testing.T) {
|
||||
},
|
||||
}
|
||||
done := make(chan error, 1)
|
||||
go func() { done <- watch(ctx, dir, &out, opts) }()
|
||||
go func() { done <- watch(ctx, dir, testOutput(&out), nil, opts) }()
|
||||
waitUntil(t, "initial build", func() bool { return builds.Load() == 1 })
|
||||
|
||||
for i := 0; i < 5; i++ {
|
||||
@@ -243,7 +255,7 @@ func TestWatchIgnoresBinAndTmp(t *testing.T) {
|
||||
builds.Add(1)
|
||||
return nil
|
||||
},
|
||||
Start: func(ctx context.Context, binPath string, stdout, stderr io.Writer) (*exec.Cmd, error) {
|
||||
Start: func(ctx context.Context, binPath string, args []string, stdout, stderr io.Writer) (*exec.Cmd, error) {
|
||||
cmd := exec.Command("sleep", "30")
|
||||
if err := cmd.Start(); err != nil {
|
||||
return nil, err
|
||||
@@ -252,7 +264,7 @@ func TestWatchIgnoresBinAndTmp(t *testing.T) {
|
||||
},
|
||||
}
|
||||
done := make(chan error, 1)
|
||||
go func() { done <- watch(ctx, dir, &out, opts) }()
|
||||
go func() { done <- watch(ctx, dir, testOutput(&out), nil, opts) }()
|
||||
waitUntil(t, "initial build", func() bool { return builds.Load() == 1 })
|
||||
|
||||
if err := os.WriteFile(filepath.Join(dir, "bin", "hello.go"), []byte("package main\n"), 0o644); err != nil {
|
||||
@@ -290,7 +302,7 @@ func TestWatchHelloWorkspaceRebuildLatency(t *testing.T) {
|
||||
}
|
||||
return nil
|
||||
},
|
||||
Start: func(ctx context.Context, binPath string, stdout, stderr io.Writer) (*exec.Cmd, error) {
|
||||
Start: func(ctx context.Context, binPath string, args []string, stdout, stderr io.Writer) (*exec.Cmd, error) {
|
||||
starts.Add(1)
|
||||
cmd := exec.Command("sleep", "30")
|
||||
if err := cmd.Start(); err != nil {
|
||||
@@ -301,7 +313,7 @@ func TestWatchHelloWorkspaceRebuildLatency(t *testing.T) {
|
||||
}
|
||||
|
||||
done := make(chan error, 1)
|
||||
go func() { done <- watch(ctx, dir, &out, opts) }()
|
||||
go func() { done <- watch(ctx, dir, testOutput(&out), nil, opts) }()
|
||||
waitUntilTimeout(t, 60*time.Second, "initial real rebuild", func() bool { return starts.Load() == 1 })
|
||||
if builds.Load() != 1 {
|
||||
t.Fatalf("initial builds = %d", builds.Load())
|
||||
@@ -320,7 +332,7 @@ func TestWatchHelloWorkspaceRebuildLatency(t *testing.T) {
|
||||
}
|
||||
waitUntilTimeout(t, 60*time.Second, "rebuild after source edit", func() bool { return starts.Load() == 2 })
|
||||
got := out.String()
|
||||
if strings.Count(got, "rebuild:") < 2 {
|
||||
if strings.Count(got, "Rebuilt in ") < 2 {
|
||||
t.Fatalf("want rebuild latency lines after restart, got %q", got)
|
||||
}
|
||||
if !rebuildLinePresent(got) {
|
||||
@@ -352,7 +364,7 @@ func TestWatchHelloWorkspaceRebuildLatency(t *testing.T) {
|
||||
func rebuildLinePresent(s string) bool {
|
||||
for _, line := range strings.Split(s, "\n") {
|
||||
line = strings.TrimSpace(line)
|
||||
if strings.HasPrefix(line, "rebuild:") && len(strings.TrimSpace(strings.TrimPrefix(line, "rebuild:"))) > 0 {
|
||||
if _, d, ok := strings.Cut(line, "Rebuilt in "); ok && strings.TrimSpace(d) != "" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user