Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.Net: Add unit test to confirm 429 exception handling #9772

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<IChatCompletionService>((sp) => chatCompletion);
Kernel kernel = builder.Build();

// Act
var exception = await Assert.ThrowsAsync<HttpOperationException>(async () => await kernel.InvokePromptAsync("Prompt"));

// Assert
Assert.Equal(HttpStatusCode.TooManyRequests, exception.StatusCode);
}

[Fact]
public async Task InvokePromptAsyncWithPromptFunctionInTemplateAndSingleResultAsync()
{
Expand Down
Loading