Ejemplo n.º 1
0
        public void Should_test_latency_to_server()
        {
            var settings = _speedTestClientClient.GetSettings();
            var latency  = _speedTestClientClient.TestServerLatency(settings.Servers.First());

            Assert.True(latency > 0);
            Assert.True(latency < 1000 * 60 * 5);
        }
        public void Should_test_latency_to_server()
        {
            var settings = speedTestClientClient.GetSettings();
            var latency  = speedTestClientClient.TestServerLatency(settings.Servers.First());

            Console.WriteLine("Latency: {0} ms", latency);

            Assert.Greater(latency, 0);
            Assert.Less(latency, 1000 * 60 * 5);
        }
Ejemplo n.º 3
0
        private Server FindBestTestServer()
        {
            var tenLocalServers = _settings.Servers
                                  .Where(s => s.Country.Equals(_location.EnglishName))
                                  .Take(10);

            var serversOrdersByLatency = tenLocalServers
                                         .Select(s =>
            {
                s.Latency = _client.TestServerLatency(s);
                return(s);
            })
                                         .OrderBy(s => s.Latency);

            return(serversOrdersByLatency.First());
        }
Ejemplo n.º 4
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");
            }
        }