check waits for its progress output before the summary (closes #140)
check / check (push) Failing after 1s
check / check (push) Failing after 1s
With --progress, runCheck started the progress goroutine but waited only for the results goroutine, so check could log its summary, or return, before the last progress line was written and cleared. The progress goroutine now signals a sync.WaitGroup when it finishes, and runCheck waits on it as soon as Check returns, as generate does. The new test sends stdout and stderr to one buffer and slows down stdout writes, so without the wait the progress output lands after the summary. Model: opus-5-5
This commit is contained in:
+15
-3
@@ -11,6 +11,7 @@ import (
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/dustin/go-humanize"
|
||||
@@ -163,7 +164,9 @@ func verifyRequiredSigner(
|
||||
}
|
||||
|
||||
// reportCheckProgress renders progress updates until the channel closes.
|
||||
func reportCheckProgress(progress <-chan mfer.CheckStatus) {
|
||||
func reportCheckProgress(progress <-chan mfer.CheckStatus, wg *sync.WaitGroup) {
|
||||
defer wg.Done()
|
||||
|
||||
for status := range progress {
|
||||
if status.ETA > 0 {
|
||||
log.Progressf("Checking: %d/%d files, %s/s, ETA %s, %d failures",
|
||||
@@ -235,11 +238,17 @@ func runCheck(ctx *cli.Context, chk *mfer.Checker, showProgress bool) (int64, er
|
||||
results := make(chan mfer.Result, 1)
|
||||
|
||||
// Set up progress channel
|
||||
var progress chan mfer.CheckStatus
|
||||
var (
|
||||
progress chan mfer.CheckStatus
|
||||
progressWg sync.WaitGroup
|
||||
)
|
||||
|
||||
if showProgress {
|
||||
progress = make(chan mfer.CheckStatus, 1)
|
||||
|
||||
go reportCheckProgress(progress)
|
||||
progressWg.Add(1)
|
||||
|
||||
go reportCheckProgress(progress, &progressWg)
|
||||
}
|
||||
|
||||
// Process results in a goroutine
|
||||
@@ -251,6 +260,9 @@ func runCheck(ctx *cli.Context, chk *mfer.Checker, showProgress bool) (int64, er
|
||||
|
||||
// Run check
|
||||
err := chk.Check(ctx.Context, results, progress)
|
||||
|
||||
progressWg.Wait()
|
||||
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("check failed: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user