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) {
26 f.tasks = append(f.tasks, task)
28 f.peak = max(f.peak, f.active)
47 return "", errors.New("fake failure")
50 return fakeLine(task), nil
53 // SetFailing makes the next tasks fail or not.
54 func (f *FakeSummarizer) SetFailing(failing bool) {
56 defer f.mutex.Unlock()
61 // Active returns the number of tasks that run now.
62 func (f *FakeSummarizer) Active() int {
64 defer f.mutex.Unlock()
69 // Tasks returns the tasks so far.
70 func (f *FakeSummarizer) Tasks() []Task {
72 defer f.mutex.Unlock()
74 return slices.Clone(f.tasks)
77 // fakeLine returns a line of nodeBytes bytes or less that names the node and
78 // starts with the input. A real line of this size makes each merge a model
80 func fakeLine(task Task) string {
81 count := 1 << task.Level
82 line := fmt.Sprintf("summary %d+%d: %s", task.Index*count, count, strings.Join(task.Input, " "))
83 line = strings.ReplaceAll(line, "\n", " ")
84 for len(line) > nodeBytes-12 {
85 _, size := utf8.DecodeLastRuneInString(line)
86 line = line[:len(line)-size]
92 func newFakeSummarizer() *FakeSummarizer {
93 return &FakeSummarizer{}