From 88b7c04ed56282799347bdb1000407a95b3bdfb1 Mon Sep 17 00:00:00 2001 From: jcamiel Date: Fri, 15 Mar 2024 17:18:16 +0100 Subject: [PATCH] Add experimental max-workers option. --- completions/_hurl | 1 + completions/_hurl.ps1 | 1 + completions/hurl.bash | 2 +- completions/hurl.fish | 1 + docs/spec/options/hurl/max_workers.option | 12 ++++++++++++ docs/spec/options/hurl/parallel.option | 2 ++ packages/hurl/src/cli/options/commands.rs | 11 +++++++++++ packages/hurl/src/cli/options/matches.rs | 6 ++++++ packages/hurl/src/cli/options/mod.rs | 4 ++++ 9 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 docs/spec/options/hurl/max_workers.option diff --git a/completions/_hurl b/completions/_hurl index 936b7b78d..f3ae7411f 100644 --- a/completions/_hurl +++ b/completions/_hurl @@ -46,6 +46,7 @@ _hurl() { '--json[Output each Hurl file result to JSON]' \ '--max-redirs[Maximum number of redirects allowed, -1 for unlimited redirects]: :' \ '(-m --max-time)'{-m,--max-time}'[Maximum time allowed for the transfer]: :' \ + '--max-workers[(Experimental) Maximum number of parallel execution]: :' \ '(-n --netrc)'{-n,--netrc}'[Must read .netrc for username and password]' \ '--netrc-file[Specify FILE for .netrc]: :_files' \ '--netrc-optional[Use either .netrc or the URL]' \ diff --git a/completions/_hurl.ps1 b/completions/_hurl.ps1 index baeccdef4..9eb163515 100644 --- a/completions/_hurl.ps1 +++ b/completions/_hurl.ps1 @@ -51,6 +51,7 @@ Register-ArgumentCompleter -Native -CommandName 'hurl' -ScriptBlock { [CompletionResult]::new('--json', 'json', [CompletionResultType]::ParameterName, 'Output each Hurl file result to JSON') [CompletionResult]::new('--max-redirs', 'max-redirs', [CompletionResultType]::ParameterName, 'Maximum number of redirects allowed, -1 for unlimited redirects') [CompletionResult]::new('--max-time', 'max-time', [CompletionResultType]::ParameterName, 'Maximum time allowed for the transfer') + [CompletionResult]::new('--max-workers', 'max-workers', [CompletionResultType]::ParameterName, '(Experimental) Maximum number of parallel execution') [CompletionResult]::new('--netrc', 'netrc', [CompletionResultType]::ParameterName, 'Must read .netrc for username and password') [CompletionResult]::new('--netrc-file', 'netrc-file', [CompletionResultType]::ParameterName, 'Specify FILE for .netrc') [CompletionResult]::new('--netrc-optional', 'netrc-optional', [CompletionResultType]::ParameterName, 'Use either .netrc or the URL') diff --git a/completions/hurl.bash b/completions/hurl.bash index f12872711..b2ef1c2a8 100644 --- a/completions/hurl.bash +++ b/completions/hurl.bash @@ -5,7 +5,7 @@ _hurl() _init_completion || return if [[ $cur == -* ]]; then - COMPREPLY=($(compgen -W '--aws-sigv4 --cacert --cert --key --color --compressed --connect-timeout --connect-to --continue-on-error --cookie --cookie-jar --delay --error-format --fail-at-end --file-root --location --location-trusted --glob --http1.0 --http1.1 --http2 --http3 --ignore-asserts --include --insecure --interactive --ipv4 --ipv6 --json --max-redirs --max-time --netrc --netrc-file --netrc-optional --no-color --no-output --noproxy --output --parallel --path-as-is --proxy --report-html --report-junit --report-tap --resolve --retry --retry-interval --ssl-no-revoke --test --to-entry --unix-socket --user --user-agent --variable --variables-file --verbose --very-verbose --help --version' -- "$cur")) + COMPREPLY=($(compgen -W '--aws-sigv4 --cacert --cert --key --color --compressed --connect-timeout --connect-to --continue-on-error --cookie --cookie-jar --delay --error-format --fail-at-end --file-root --location --location-trusted --glob --http1.0 --http1.1 --http2 --http3 --ignore-asserts --include --insecure --interactive --ipv4 --ipv6 --json --max-redirs --max-time --max-workers --netrc --netrc-file --netrc-optional --no-color --no-output --noproxy --output --parallel --path-as-is --proxy --report-html --report-junit --report-tap --resolve --retry --retry-interval --ssl-no-revoke --test --to-entry --unix-socket --user --user-agent --variable --variables-file --verbose --very-verbose --help --version' -- "$cur")) return fi diff --git a/completions/hurl.fish b/completions/hurl.fish index fbbb272ab..77cd42098 100644 --- a/completions/hurl.fish +++ b/completions/hurl.fish @@ -29,6 +29,7 @@ complete -c hurl -l ipv6 -d 'Tell Hurl to use IPv6 addresses only when resolving complete -c hurl -l json -d 'Output each Hurl file result to JSON' complete -c hurl -l max-redirs -d 'Maximum number of redirects allowed, -1 for unlimited redirects' complete -c hurl -l max-time -d 'Maximum time allowed for the transfer' +complete -c hurl -l max-workers -d '(Experimental) Maximum number of parallel execution' complete -c hurl -l netrc -d 'Must read .netrc for username and password' complete -c hurl -l netrc-file -d 'Specify FILE for .netrc' complete -c hurl -l netrc-optional -d 'Use either .netrc or the URL' diff --git a/docs/spec/options/hurl/max_workers.option b/docs/spec/options/hurl/max_workers.option new file mode 100644 index 000000000..39a093e1d --- /dev/null +++ b/docs/spec/options/hurl/max_workers.option @@ -0,0 +1,12 @@ +name: max_workers +long: max-workers +value: NUM +value_default: 6 +value_parser: clap::value_parser!(u32).range(1..) +help: (Experimental) Maximum number of parallel execution +cli_only: true +experimental: true +--- +(Experimental) Maximum number of parallel execution in parallel mode. + +See also [`--parallel`](#parallel). diff --git a/docs/spec/options/hurl/parallel.option b/docs/spec/options/hurl/parallel.option index 7efc49b25..22b7ba184 100644 --- a/docs/spec/options/hurl/parallel.option +++ b/docs/spec/options/hurl/parallel.option @@ -7,3 +7,5 @@ experimental: true (Experimental) Run files in parallel. Each Hurl file is executed in its own worker thread, without sharing anything with the other workers. The default run mode is sequential. + +See also [`--max-workers`](#max-workers). diff --git a/packages/hurl/src/cli/options/commands.rs b/packages/hurl/src/cli/options/commands.rs index 5b8ecf750..5177e7fed 100644 --- a/packages/hurl/src/cli/options/commands.rs +++ b/packages/hurl/src/cli/options/commands.rs @@ -284,6 +284,17 @@ pub fn max_time() -> clap::Arg { .num_args(1) } +pub fn max_workers() -> clap::Arg { + clap::Arg::new("max_workers") + .long("max-workers") + .value_name("NUM") + .default_value("6") + .value_parser(clap::value_parser!(u32).range(1..)) + .help("(Experimental) Maximum number of parallel execution") + .num_args(1) + .hide(true) +} + pub fn netrc() -> clap::Arg { clap::Arg::new("netrc") .long("netrc") diff --git a/packages/hurl/src/cli/options/matches.rs b/packages/hurl/src/cli/options/matches.rs index 224f53e9b..dd62823b2 100644 --- a/packages/hurl/src/cli/options/matches.rs +++ b/packages/hurl/src/cli/options/matches.rs @@ -246,6 +246,12 @@ pub fn max_redirect(arg_matches: &ArgMatches) -> Option { } } +pub fn max_workers(arg_matches: &ArgMatches) -> usize { + get::(arg_matches, "max_workers") + .map(|m| m as usize) + .unwrap() +} + pub fn netrc(arg_matches: &ArgMatches) -> bool { has_flag(arg_matches, "netrc") } diff --git a/packages/hurl/src/cli/options/mod.rs b/packages/hurl/src/cli/options/mod.rs index 9113f7529..a5bd8a0c5 100644 --- a/packages/hurl/src/cli/options/mod.rs +++ b/packages/hurl/src/cli/options/mod.rs @@ -66,6 +66,7 @@ pub struct CliOptions { pub ip_resolve: Option, pub junit_file: Option, pub max_redirect: Option, + pub max_workers: usize, pub netrc: bool, pub netrc_file: Option, pub netrc_optional: bool, @@ -189,6 +190,7 @@ pub fn parse() -> Result { .arg(commands::json()) .arg(commands::max_redirects()) .arg(commands::max_time()) + .arg(commands::max_workers()) .arg(commands::netrc()) .arg(commands::netrc_file()) .arg(commands::netrc_optional()) @@ -260,6 +262,7 @@ fn parse_matches(arg_matches: &ArgMatches) -> Result Result