13 // FakeSummarizer builds each node with a line of fakeLine. It fails each task
14 // while failing is true, and each task waits for gate when gate is not nil.
15 type FakeSummarizer struct {
24 func (f *FakeSummarizer) Summarize(ctx context.Context, task Task) (string, error) {
27 f.tasks = append(f.tasks, task)
29 f.peak = max(f.peak, f.active)
49 return "", errors.New("fake failure")
52 return fakeLine(task), nil
55 // SetFailing makes the next tasks fail or not.
56 func (f *FakeSummarizer) SetFailing(failing bool) {
58 defer f.mutex.Unlock()
63 // Active returns the number of tasks that run now.
64 func (f *FakeSummarizer) Active() int {
66 defer f.mutex.Unlock()
71 // Tasks returns the tasks so far.
72 func (f *FakeSummarizer) Tasks() []Task {
74 defer f.mutex.Unlock()
76 return slices.Clone(f.tasks)
79 // fakeLine returns a line of nodeBytes bytes or less that names the node and
80 // starts with the input. A real line of this size makes each merge a model
82 func fakeLine(task Task) string {
83 count := 1 << task.Level
84 line := fmt.Sprintf("summary %d+%d: %s", task.Index*count, count, strings.Join(task.Input, " "))
85 line = strings.ReplaceAll(line, "\n", " ")
86 for len(line) > nodeBytes-12 {
87 _, size := utf8.DecodeLastRuneInString(line)
88 line = line[:len(line)-size]
94 func newFakeSummarizer() *FakeSummarizer {
95 return &FakeSummarizer{}