(t *testing.T)
| 102 | } |
| 103 | |
| 104 | func TestFanout(t *testing.T) { |
| 105 | ctx := context.Background() |
| 106 | |
| 107 | var executions atomic.Int32 |
| 108 | registry := map[string]agent.Agent{ |
| 109 | "root": AgentFunc(func(inputs []*proto.Message, tm agent.Executor, o agent.OutputHandler) { |
| 110 | var g errgroup.Group |
| 111 | for i := range 50 { |
| 112 | i := i // Capture loop variable. |
| 113 | g.Go(func() error { |
| 114 | _, err := tm.Exec(ctx, "test-conv", fmt.Sprintf("child-%d", i), &proto.AgentStart{ |
| 115 | AgentId: "child", |
| 116 | Messages: inputs, |
| 117 | }, nil) |
| 118 | return err |
| 119 | }) |
| 120 | } |
| 121 | if err := g.Wait(); err != nil { |
| 122 | t.Fatal(err) |
| 123 | } |
| 124 | if o != nil { |
| 125 | o(&proto.AgentOutputs{ |
| 126 | Messages: []*proto.Message{text("assistant", "root done")}, |
| 127 | }) |
| 128 | } |
| 129 | }), |
| 130 | "child": AgentFunc(func(inputs []*proto.Message, tm agent.Executor, o agent.OutputHandler) { |
| 131 | executions.Add(1) |
| 132 | time.Sleep(100 * time.Millisecond) |
| 133 | |
| 134 | var g errgroup.Group |
| 135 | for i := range 2 { |
| 136 | i := i // Capture loop variable. |
| 137 | g.Go(func() error { |
| 138 | _, err := tm.Exec(ctx, "test-conv", fmt.Sprintf("child2-%d", i), &proto.AgentStart{ |
| 139 | AgentId: "child2", |
| 140 | Messages: inputs, |
| 141 | }, nil) |
| 142 | return err |
| 143 | }) |
| 144 | } |
| 145 | if err := g.Wait(); err != nil { |
| 146 | t.Fatal(err) |
| 147 | } |
| 148 | if o != nil { |
| 149 | o(&proto.AgentOutputs{ |
| 150 | Messages: []*proto.Message{text("assistant", "child done")}, |
| 151 | }) |
| 152 | } |
| 153 | }), |
| 154 | "child2": AgentFunc(func(inputs []*proto.Message, tm agent.Executor, o agent.OutputHandler) { |
| 155 | executions.Add(1) |
| 156 | time.Sleep(100 * time.Millisecond) |
| 157 | if o != nil { |
| 158 | o(&proto.AgentOutputs{ |
| 159 | Messages: []*proto.Message{text("assistant", "child2 done")}, |
| 160 | }) |
| 161 | } |
nothing calls this directly
no test coverage detected