Enhance SwarmUI integration by adding swarm connection status to the API and updating client-side components to reflect this status. Improved localization strings for various SwarmUI states and refactored ApplicantsDialog and PersonCard components to utilize the new connection information, ensuring a more responsive user experience.
This commit is contained in:
@@ -34,6 +34,44 @@ public class SwarmUiClientTests
|
||||
Assert.Contains("/API/GenerateText2Image", handler.Requests[1]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ProbeAsync_ReturnsTrueWhenSessionOpens()
|
||||
{
|
||||
var handler = new FakeHandler();
|
||||
var http = new HttpClient(handler) { BaseAddress = new Uri("http://swarm.test/") };
|
||||
var client = new SwarmUiClient(
|
||||
http,
|
||||
Options.Create(new SwarmUiOptions { BaseUrl = "http://swarm.test", TimeoutSeconds = 30 }),
|
||||
NullLogger<SwarmUiClient>.Instance);
|
||||
|
||||
var ok = await client.ProbeAsync(TimeSpan.FromSeconds(5), CancellationToken.None);
|
||||
|
||||
Assert.True(ok);
|
||||
Assert.Single(handler.Requests);
|
||||
Assert.Contains("/API/GetNewSession", handler.Requests[0]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ProbeAsync_ReturnsFalseWhenUnreachable()
|
||||
{
|
||||
var handler = new FailingHandler();
|
||||
var http = new HttpClient(handler) { BaseAddress = new Uri("http://swarm.test/") };
|
||||
var client = new SwarmUiClient(
|
||||
http,
|
||||
Options.Create(new SwarmUiOptions { BaseUrl = "http://swarm.test", TimeoutSeconds = 30 }),
|
||||
NullLogger<SwarmUiClient>.Instance);
|
||||
|
||||
var ok = await client.ProbeAsync(TimeSpan.FromSeconds(5), CancellationToken.None);
|
||||
|
||||
Assert.False(ok);
|
||||
}
|
||||
|
||||
private sealed class FailingHandler : HttpMessageHandler
|
||||
{
|
||||
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) =>
|
||||
Task.FromResult(new HttpResponseMessage(HttpStatusCode.ServiceUnavailable));
|
||||
}
|
||||
|
||||
private sealed class FakeHandler : HttpMessageHandler
|
||||
{
|
||||
public List<string> Requests { get; } = [];
|
||||
|
||||
Reference in New Issue
Block a user