MCPcopy Index your code
hub / github.com/coder/coder / TestAIBridgeConcurrencyLimiting

Function TestAIBridgeConcurrencyLimiting

enterprise/coderd/aibridge_test.go:1940–2016  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1938}
1939
1940func TestAIBridgeConcurrencyLimiting(t *testing.T) {
1941 t.Parallel()
1942
1943 dv := coderdtest.DeploymentValues(t)
1944 dv.AI.BridgeConfig.Enabled = serpent.Bool(true)
1945 // Set a low concurrency limit for testing.
1946 dv.AI.BridgeConfig.MaxConcurrency = 1
1947
1948 client, closer, api, _ := coderdenttest.NewWithAPI(t, &coderdenttest.Options{
1949 Options: &coderdtest.Options{
1950 DeploymentValues: dv,
1951 },
1952 LicenseOptions: &coderdenttest.LicenseOptions{
1953 Features: license.Features{
1954 codersdk.FeatureAIBridge: 1,
1955 },
1956 },
1957 })
1958 t.Cleanup(func() {
1959 _ = closer.Close()
1960 })
1961
1962 // Register a handler that blocks until signaled.
1963 started := make(chan struct{})
1964 unblock := make(chan struct{})
1965 testHandler := http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
1966 started <- struct{}{}
1967 <-unblock
1968 rw.WriteHeader(http.StatusOK)
1969 })
1970 api.AGPL.RegisterInMemoryAIBridgedHTTPHandler(testHandler)
1971
1972 ctx := testutil.Context(t, testutil.WaitLong)
1973 httpClient := &http.Client{}
1974 url := client.URL.String() + "/api/v2/aibridge/test"
1975
1976 // Start a request that will block.
1977 done := make(chan struct{})
1978 go func() {
1979 defer close(done)
1980 req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, nil)
1981 if err != nil {
1982 return
1983 }
1984 req.Header.Set(codersdk.SessionTokenHeader, client.SessionToken())
1985
1986 resp, err := httpClient.Do(req)
1987 if err == nil {
1988 _ = resp.Body.Close()
1989 }
1990 }()
1991
1992 // Wait for the first request to start processing.
1993 select {
1994 case <-started:
1995 case <-ctx.Done():
1996 t.Fatal("timed out waiting for first request to start")
1997 }

Callers

nothing calls this directly

Calls 14

DeploymentValuesFunction · 0.92
NewWithAPIFunction · 0.92
ContextFunction · 0.92
FatalMethod · 0.80
CleanupMethod · 0.65
CloseMethod · 0.65
SetMethod · 0.65
DoMethod · 0.65
WriteHeaderMethod · 0.45
StringMethod · 0.45
SessionTokenMethod · 0.45

Tested by

no test coverage detected