public void Should_return_settings_with_sorted_server_list_by_distance() { var settings = _speedTestClientClient.GetSettings(); for (var i = 1; i < settings.Servers.Count; i++) { Assert.True(settings.Servers[i - 1].Distance.CompareTo(settings.Servers[i].Distance) <= 0); } }
public async Task RunAsync() { var executionDateTime = DateTime.UtcNow; _logger.LogDebug("Getting speed test client settings..."); var settings = _speedTestClient.GetSettings(); _logger.LogDebug("Retrieved settings"); var servers = settings.Servers; var serverEnumerator = servers.GetEnumerator(); var testSuccessful = false; SpeedTestResult result = null; while (serverEnumerator.MoveNext() && !testSuccessful) { var server = serverEnumerator.Current; try { _logger.LogDebug($"Testing server {server.Host} latency"); server.Latency = _speedTestClient.TestServerLatency(server); _logger.LogDebug($"Latency test complete"); _logger.LogDebug("Testing doownload speed..."); var downloadSpeed = _speedTestClient.TestDownloadSpeed(server, _runnerOptions.SpeedTestNetClient.ConcurrentDownloads); _logger.LogDebug("Download test completed"); _logger.LogDebug("Testing upload speed..."); var uploadSpeed = _speedTestClient.TestUploadSpeed(server, _runnerOptions.SpeedTestNetClient.ConcurrentUploads); _logger.LogDebug("Upload test completed"); result = new SpeedTestResult { NodeName = _runnerOptions.NodeName, Location = _runnerOptions.Location, ExecutionDateTime = executionDateTime, AverageDownloadSpeed = (decimal)downloadSpeed, AverageUploadSpeed = (decimal)uploadSpeed, MaximumDownloadSpeed = (decimal)downloadSpeed, MaximumUploadSpeed = (decimal)uploadSpeed, Latency = server.Latency, TestServerName = server.Host }; testSuccessful = true; } catch (HttpRequestException hre) { var message = $"Error testing server {server.Host}. Skipping..."; if (_runnerOptions.LogExceptions) { _logger.LogError(hre, message); } else { _logger.LogError(message); } } } if (result != null) { _logger.LogDebug("Posting speed test results..."); await _speedtestHttpClient.PostTestResult(result); _logger.LogDebug("Speed test results posted"); } else { _logger.LogError("All speed tests failed"); } }
public SpeedTestRunner(RegionInfo location) { _client = new SpeedTestClient(); _settings = _client.GetSettings(); _location = location; }