예제 #1
0
        public void Should_test_upload_speed()
        {
            var settings = _speedTestClientClient.GetSettings();
            var speed    = _speedTestClientClient.TestUploadSpeed(settings.Servers.First(), settings.Upload.ThreadsPerUrl);

            Assert.True(speed > 0);
        }
        public void Should_test_upload_speed()
        {
            var settings = speedTestClientClient.GetSettings();
            var speed    = speedTestClientClient.TestUploadSpeed(settings.Servers.First(), settings.Upload.ThreadsPerUrl);

            PrintSpeed("Upload", speed);
            Assert.Greater(speed, 0);
        }
예제 #3
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");
            }
        }
예제 #4
0
        private double TestUploadSpeed(Server server)
        {
            var uploadSpeed = _client.TestUploadSpeed(server, _settings.Download.ThreadsPerUrl);

            return(ConvertSpeedToMbps(uploadSpeed));
        }