Files
kra-new/pkg/task/output_test.go
T

36 lines
853 B
Go

package task
import (
"context"
"strings"
"sync"
"testing"
"unicode/utf8"
)
func TestOutputIsBoundedConcurrentAndExecutionLocal(t *testing.T) {
ctx, output := WithOutput(context.Background())
other, separate := WithOutput(context.Background())
Logf(other, "独立任务")
var workers sync.WaitGroup
for i := 0; i < 20; i++ {
workers.Add(1)
go func() {
defer workers.Done()
for j := 0; j < 100; j++ {
Logf(ctx, "%s", strings.Repeat("渠道", 20))
_ = output.String()
}
}()
}
workers.Wait()
text := output.String()
if !utf8.ValidString(text) || len(text) > 3100 || !strings.Contains(text, "已截断") {
t.Fatalf("invalid bounded output: bytes=%d", len(text))
}
if separate.String() != "独立任务" {
t.Fatal("execution details leaked between tasks")
}
Logf(context.Background(), "outside an execution")
}