add tests
This commit is contained in:
@@ -516,4 +516,33 @@ public class AIServiceTests : UnitTestBase
|
||||
Times.AtLeast(3) // One for each attempt
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GenerateChatCompletionAsync_ShouldTimeout_WhenRequestExceedsConfiguredTimeout()
|
||||
{
|
||||
// Arrange
|
||||
var messages = TestDataBuilder.ChatMessages.CreateMessageHistory(2);
|
||||
var model = "llama3.2";
|
||||
|
||||
_modelServiceMock.Setup(x => x.GetCurrentModel()).Returns(model);
|
||||
_systemPromptServiceMock.Setup(x => x.GetSystemPromptAsync()).ReturnsAsync("System prompt");
|
||||
|
||||
// Configure very small timeout (not strictly needed for this simulation)
|
||||
_aiSettings.RequestTimeoutSeconds = 1;
|
||||
|
||||
// Emulate timeout from underlying client
|
||||
_ollamaClientMock
|
||||
.Setup(x => x.ChatAsync(It.IsAny<OllamaSharp.Models.Chat.ChatRequest>()))
|
||||
.Throws(new TimeoutException("Request timed out"));
|
||||
|
||||
// Act
|
||||
var result = await _aiService.GenerateChatCompletionAsync(messages);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(AIResponseConstants.DefaultErrorMessage);
|
||||
_ollamaClientMock.Verify(
|
||||
x => x.ChatAsync(It.IsAny<OllamaSharp.Models.Chat.ChatRequest>()),
|
||||
Times.Exactly(3)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user