(t *testing.T)
| 1938 | } |
| 1939 | |
| 1940 | func 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 | } |
nothing calls this directly
no test coverage detected