MCPcopy Create free account
hub / github.com/coder/aibridge / TestClientAndConnectionError

Function TestClientAndConnectionError

internal/integrationtest/responses_test.go:602–661  ·  view source on GitHub ↗

TODO set MaxRetries to speed up this test option.WithMaxRetries(0), in base responses interceptor https://github.com/coder/aibridge/issues/115

(t *testing.T)

Source from the content-addressed store, hash-verified

600// option.WithMaxRetries(0), in base responses interceptor
601// https://github.com/coder/aibridge/issues/115
602func TestClientAndConnectionError(t *testing.T) {
603 t.Parallel()
604
605 tests := []struct {
606 name string
607 addr string
608 streaming bool
609 errContains string
610 }{
611 {
612 name: "blocking_connection_refused",
613 addr: startRejectingListener(t),
614 streaming: false,
615 errContains: "connection reset by peer",
616 },
617 {
618 name: "streaming_connection_refused",
619 addr: startRejectingListener(t),
620 streaming: true,
621 errContains: "connection reset by peer",
622 },
623 {
624 name: "blocking_bad_url",
625 addr: "not_url",
626 streaming: false,
627 errContains: "unsupported protocol scheme",
628 },
629 {
630 name: "streaming_bad_url",
631 addr: "not_url",
632 streaming: true,
633 errContains: "unsupported protocol scheme",
634 },
635 }
636
637 for _, tc := range tests {
638 t.Run(tc.name, func(t *testing.T) {
639 t.Parallel()
640
641 ctx, cancel := context.WithTimeout(t.Context(), testutil.WaitLong)
642 t.Cleanup(cancel)
643
644 // tc.addr may be an intentionally invalid URL; use withCustomProvider.
645 bridgeServer := newBridgeTestServer(ctx, t, tc.addr, withCustomProvider(provider.NewOpenAI(openAICfg(tc.addr, apiKey))))
646
647 reqBytes := responsesRequestBytes(t, tc.streaming)
648 resp, err := bridgeServer.makeRequest(t, http.MethodPost, pathOpenAIResponses, reqBytes)
649 require.NoError(t, err)
650 defer resp.Body.Close()
651
652 require.Equal(t, "application/json", resp.Header.Get("Content-Type"))
653 require.Equal(t, http.StatusInternalServerError, resp.StatusCode)
654
655 body, err := io.ReadAll(resp.Body)
656 require.NoError(t, err)
657 requireResponsesError(t, http.StatusInternalServerError, tc.errContains, body)
658 require.Empty(t, bridgeServer.Recorder.RecordedPromptUsages())
659 })

Callers

nothing calls this directly

Calls 11

NewOpenAIFunction · 0.92
startRejectingListenerFunction · 0.85
newBridgeTestServerFunction · 0.85
withCustomProviderFunction · 0.85
openAICfgFunction · 0.85
responsesRequestBytesFunction · 0.85
requireResponsesErrorFunction · 0.85
makeRequestMethod · 0.80
GetMethod · 0.80
RecordedPromptUsagesMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected