WaitForExchanges waits until the proxy has captured at least the requested exchanges.
(t *testing.T, minimumCount int)
| 178 | |
| 179 | // WaitForExchanges waits until the proxy has captured at least the requested exchanges. |
| 180 | func (c *TestContext) WaitForExchanges(t *testing.T, minimumCount int) []ParsedHttpExchange { |
| 181 | t.Helper() |
| 182 | |
| 183 | deadline := time.Now().Add(120 * time.Second) |
| 184 | var lastErr error |
| 185 | var exchanges []ParsedHttpExchange |
| 186 | for time.Now().Before(deadline) { |
| 187 | var err error |
| 188 | exchanges, err = c.GetExchanges() |
| 189 | if err == nil && len(exchanges) >= minimumCount { |
| 190 | return exchanges |
| 191 | } |
| 192 | lastErr = err |
| 193 | time.Sleep(100 * time.Millisecond) |
| 194 | } |
| 195 | |
| 196 | if lastErr != nil { |
| 197 | t.Fatalf("Timed out waiting for %d chat completion request(s): %v", minimumCount, lastErr) |
| 198 | } |
| 199 | t.Fatalf("Timed out waiting for %d chat completion request(s); captured %d", minimumCount, len(exchanges)) |
| 200 | return nil |
| 201 | } |
| 202 | |
| 203 | // SetCopilotUserByToken registers a per-token user configuration on the proxy. |
| 204 | func (c *TestContext) SetCopilotUserByToken(token string, response map[string]interface{}) error { |