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 newFakeSummarizer() *FakeSummarizer {
25 return &FakeSummarizer{}
28 func (f *FakeSummarizer) Summarize(ctx context.Context, task Task) (string, error) {
31 f.tasks = append(f.tasks, task)
33 f.peak = max(f.peak, f.active)
53 return "", errors.New("fake failure")
56 return fakeLine(task), nil
59 // SetFailing makes the next tasks fail or not.
60 func (f *FakeSummarizer) SetFailing(failing bool) {
62 defer f.mutex.Unlock()
67 // Active returns the number of tasks that run now.
68 func (f *FakeSummarizer) Active() int {
70 defer f.mutex.Unlock()
75 // Tasks returns the tasks so far.
76 func (f *FakeSummarizer) Tasks() []Task {
78 defer f.mutex.Unlock()
80 return slices.Clone(f.tasks)
83 // fakeLine returns a line of nodeBytes bytes or less that names the node and
84 // starts with the input. A real line of this size makes each merge a model
86 func fakeLine(task Task) string {
87 count := 1 << task.Level
88 line := fmt.Sprintf("summary %d+%d: %s", task.Index*count, count, strings.Join(task.Input, " "))
89 line = strings.ReplaceAll(line, "\n", " ")
90 for len(line) > nodeBytes-12 {
91 _, size := utf8.DecodeLastRuneInString(line)
92 line = line[:len(line)-size]