Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce --download-only and --upload-only flags #150

Merged
merged 5 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ Options:
Force usage of IPv6
-d, --disable-dynamic-max-payload-size
Disables dynamically skipping tests with larger payload sizes if the tests for the previous payload size took longer than 5 seconds
--download-only
Test download speed only
--upload-only
Test upload speed only
-h, --help
Print help
-V, --version
Expand Down
2 changes: 2 additions & 0 deletions examples/simple_speedtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ fn main() {
ipv4: false, // don't force ipv4 usage
ipv6: false, // don't force ipv6 usage
verbose: false,
upload_only: false,
download_only: false,
nr_tests: 5,
nr_latency_tests: 20,
max_payload_size: PayloadSize::M10,
Expand Down
20 changes: 20 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,26 @@ pub struct SpeedTestCLIOptions {
/// size took longer than 5 seconds
#[arg(short, long)]
pub disable_dynamic_max_payload_size: bool,

/// Test download speed only
#[arg(long, conflicts_with = "upload_only")]
pub download_only: bool,

/// Test upload speed only
#[arg(long, conflicts_with = "download_only")]
pub upload_only: bool,
}

impl SpeedTestCLIOptions {
/// Returns whether download tests should be performed
pub fn should_download(&self) -> bool {
self.download_only || !self.upload_only
}

/// Returns whether upload tests should be performed
pub fn should_upload(&self) -> bool {
self.upload_only || !self.download_only
}
}

fn parse_payload_size(input_string: &str) -> Result<PayloadSize, String> {
Expand Down
46 changes: 27 additions & 19 deletions src/speedtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,33 @@ pub fn speed_test(client: Client, options: SpeedTestCLIOptions) -> Vec<Measureme
println!("{metadata}");
}
run_latency_test(&client, options.nr_latency_tests, options.output_format);
let payload_sizes = PayloadSize::sizes_from_max(options.max_payload_size);
let mut measurements = run_tests(
&client,
test_download,
TestType::Download,
payload_sizes.clone(),
options.nr_tests,
options.output_format,
options.disable_dynamic_max_payload_size,
);
measurements.extend(run_tests(
&client,
test_upload,
TestType::Upload,
payload_sizes.clone(),
options.nr_tests,
options.output_format,
options.disable_dynamic_max_payload_size,
));
let payload_sizes = PayloadSize::sizes_from_max(options.max_payload_size.clone());
let mut measurements = Vec::new();

if options.should_download() {
measurements.extend(run_tests(
&client,
test_download,
TestType::Download,
payload_sizes.clone(),
options.nr_tests,
options.output_format,
options.disable_dynamic_max_payload_size,
));
}

if options.should_upload() {
measurements.extend(run_tests(
&client,
test_upload,
TestType::Upload,
payload_sizes.clone(),
options.nr_tests,
options.output_format,
options.disable_dynamic_max_payload_size,
));
}

log_measurements(
&measurements,
payload_sizes,
Expand Down
Loading