Skip to content

Commit f8562ee

Browse files
committed
Implemented
1 parent b177b28 commit f8562ee

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Error: No servers available

src/NetPace.Console.Tests/NetPaceConsoleTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,29 @@ public async Task Should_Continue_Multiple_Speed_Tests_On_Exception()
499499
await Verify(result.Output);
500500
}
501501

502+
[Fact]
503+
public async Task Should_Handle_No_Servers_Available()
504+
{
505+
// Given
506+
var mock = new SpeedTestMock
507+
{
508+
GetServersAsyncFunc = (cancellationToken) => Task.FromResult(Array.Empty<IServer>()),
509+
};
510+
511+
var registrar = new TypeRegistrar();
512+
registrar.RegisterInstance(typeof(ISpeedTestService), mock);
513+
registrar.Register(typeof(IClock), typeof(ClockStub));
514+
registrar.Register(typeof(IWaiter), typeof(NoDelayStub));
515+
var app = GetCommandAppTester(registrar);
516+
517+
// When
518+
var result = await app.RunAsync();
519+
520+
// Then
521+
Assert.Equal(0, result.ExitCode);
522+
await Verify(result.Output);
523+
}
524+
502525
[Fact]
503526
public async Task Should_Handle_No_Servers_Available_With_NoLatency()
504527
{

src/NetPace.Console/ConsoleWriters/ServerSelector.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ public static async Task<ServerLatencyResult> GetServerAsync(ISpeedTestService s
4141
{
4242
// Get the fastest speed test server.
4343
var servers = await speedTestClient.GetServersAsync(cancellationToken);
44+
if (servers.Length == 0)
45+
{
46+
throw new Exception("No servers available");
47+
}
4448
return await speedTestClient.GetFastestServerByLatencyAsync(servers, cancellationToken);
4549
}
4650
else

0 commit comments

Comments
 (0)