diff --git a/dotnet/src/SemanticKernel.UnitTests/Functions/KernelFunctionFromPromptTests.cs b/dotnet/src/SemanticKernel.UnitTests/Functions/KernelFunctionFromPromptTests.cs index ff45e19c62d7..72dc5199dafb 100644 --- a/dotnet/src/SemanticKernel.UnitTests/Functions/KernelFunctionFromPromptTests.cs +++ b/dotnet/src/SemanticKernel.UnitTests/Functions/KernelFunctionFromPromptTests.cs @@ -3,6 +3,8 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net; +using System.Net.Http; using System.Runtime.CompilerServices; using System.Text.Json; using System.Threading; @@ -843,6 +845,27 @@ public async Task InvokePromptAsyncWithChatCompletionReturnsMultipleResultsAsync } } + [Fact] + public async Task InvokePromptAsyncWithChatCompletionPropagatesTooManyRequestsAsync() + { + // Arrange + using var messageHandlerStub = new HttpMessageHandlerStub(); + using var response = new HttpResponseMessage(System.Net.HttpStatusCode.TooManyRequests); + messageHandlerStub.ResponseToReturn = response; + using var httpClient = new HttpClient(messageHandlerStub, false); + var chatCompletion = new OpenAIChatCompletionService(modelId: "any", apiKey: "any", httpClient: httpClient); + + KernelBuilder builder = new(); + builder.Services.AddTransient((sp) => chatCompletion); + Kernel kernel = builder.Build(); + + // Act + var exception = await Assert.ThrowsAsync(async () => await kernel.InvokePromptAsync("Prompt")); + + // Assert + Assert.Equal(HttpStatusCode.TooManyRequests, exception.StatusCode); + } + [Fact] public async Task InvokePromptAsyncWithPromptFunctionInTemplateAndSingleResultAsync() {