From 59f785974fef102ee4e150f14514ad4af6cd7132 Mon Sep 17 00:00:00 2001 From: jcamiel Date: Sun, 31 Mar 2024 18:11:04 +0200 Subject: [PATCH] Fix parallel integration tests. --- completions/_hurl | 2 +- completions/_hurl.ps1 | 2 +- completions/hurl.bash | 2 +- completions/hurl.fish | 2 +- docs/spec/options/hurl/jobs.option | 12 +++++++++++ docs/spec/options/hurl/workers.option | 12 ----------- .../hurl/tests_ok/parallel.err.pattern | 2 +- integration/hurl/tests_ok/parallel.ps1 | 2 +- integration/hurl/tests_ok/parallel.sh | 2 +- .../hurl/tests_ok/parallel_one_worker.ps1 | 2 +- .../hurl/tests_ok/parallel_one_worker.sh | 2 +- packages/hurl/src/cli/options/commands.rs | 20 +++++++++---------- packages/hurl/src/cli/options/matches.rs | 4 ++-- packages/hurl/src/cli/options/mod.rs | 10 +++++----- packages/hurl/src/main.rs | 6 +++--- packages/hurl/src/run.rs | 4 ++-- 16 files changed, 43 insertions(+), 43 deletions(-) create mode 100644 docs/spec/options/hurl/jobs.option delete mode 100644 docs/spec/options/hurl/workers.option diff --git a/completions/_hurl b/completions/_hurl index aeda9e986..e8b9d7d7b 100644 --- a/completions/_hurl +++ b/completions/_hurl @@ -44,6 +44,7 @@ _hurl() { '--interactive[Turn on interactive mode]' \ '(-4 --ipv4)'{-4,--ipv4}'[Tell Hurl to use IPv4 addresses only when resolving host names, and not for example try IPv6]' \ '(-6 --ipv6)'{-6,--ipv6}'[Tell Hurl to use IPv6 addresses only when resolving host names, and not for example try IPv4]' \ + '--jobs[(Experimental) Maximum number of parallel jobs]: :' \ '--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]: :' \ @@ -73,7 +74,6 @@ _hurl() { '*--variables-file[Define a properties file in which you define your variables]: :_files' \ '(-v --verbose)'{-v,--verbose}'[Turn on verbose]' \ '--very-verbose[Turn on verbose output, including HTTP response and libcurl logs]' \ - '--workers[(Experimental) Maximum number of parallel execution]: :' \ '--help[Print help]' \ '--version[Print version]' \ '*:file:_files' \ diff --git a/completions/_hurl.ps1 b/completions/_hurl.ps1 index bed340a7d..a24d2cca9 100644 --- a/completions/_hurl.ps1 +++ b/completions/_hurl.ps1 @@ -49,6 +49,7 @@ Register-ArgumentCompleter -Native -CommandName 'hurl' -ScriptBlock { [CompletionResult]::new('--interactive', 'interactive', [CompletionResultType]::ParameterName, 'Turn on interactive mode') [CompletionResult]::new('--ipv4', 'ipv4', [CompletionResultType]::ParameterName, 'Tell Hurl to use IPv4 addresses only when resolving host names, and not for example try IPv6') [CompletionResult]::new('--ipv6', 'ipv6', [CompletionResultType]::ParameterName, 'Tell Hurl to use IPv6 addresses only when resolving host names, and not for example try IPv4') + [CompletionResult]::new('--jobs', 'jobs', [CompletionResultType]::ParameterName, '(Experimental) Maximum number of parallel jobs') [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') @@ -78,7 +79,6 @@ Register-ArgumentCompleter -Native -CommandName 'hurl' -ScriptBlock { [CompletionResult]::new('--variables-file', 'variables-file', [CompletionResultType]::ParameterName, 'Define a properties file in which you define your variables') [CompletionResult]::new('--verbose', 'verbose', [CompletionResultType]::ParameterName, 'Turn on verbose') [CompletionResult]::new('--very-verbose', 'very-verbose', [CompletionResultType]::ParameterName, 'Turn on verbose output, including HTTP response and libcurl logs') - [CompletionResult]::new('--workers', 'workers', [CompletionResultType]::ParameterName, '(Experimental) Maximum number of parallel execution') [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help') [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version') break diff --git a/completions/hurl.bash b/completions/hurl.bash index 688238a02..7fb1dd12d 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 --from-entry --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 --workers --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 --from-entry --glob --http1.0 --http1.1 --http2 --http3 --ignore-asserts --include --insecure --interactive --ipv4 --ipv6 --jobs --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")) return fi diff --git a/completions/hurl.fish b/completions/hurl.fish index 89e006872..0111fe5ec 100644 --- a/completions/hurl.fish +++ b/completions/hurl.fish @@ -27,6 +27,7 @@ complete -c hurl -l insecure -d 'Allow insecure SSL connections' complete -c hurl -l interactive -d 'Turn on interactive mode' complete -c hurl -l ipv4 -d 'Tell Hurl to use IPv4 addresses only when resolving host names, and not for example try IPv6' complete -c hurl -l ipv6 -d 'Tell Hurl to use IPv6 addresses only when resolving host names, and not for example try IPv4' +complete -c hurl -l jobs -d '(Experimental) Maximum number of parallel jobs' 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' @@ -56,7 +57,6 @@ complete -c hurl -l variable -d 'Define a variable' complete -c hurl -l variables-file -d 'Define a properties file in which you define your variables' complete -c hurl -l verbose -d 'Turn on verbose' complete -c hurl -l very-verbose -d 'Turn on verbose output, including HTTP response and libcurl logs' -complete -c hurl -l workers -d '(Experimental) Maximum number of parallel execution' complete -c hurl -l help -d 'Print help' complete -c hurl -l version -d 'Print version' diff --git a/docs/spec/options/hurl/jobs.option b/docs/spec/options/hurl/jobs.option new file mode 100644 index 000000000..c14e1e9f8 --- /dev/null +++ b/docs/spec/options/hurl/jobs.option @@ -0,0 +1,12 @@ +name: jobs +long: jobs +value: NUM +value_parser: clap::value_parser!(u32).range(1..) +help: (Experimental) Maximum number of parallel jobs +cli_only: true +experimental: true +--- +(Experimental) Maximum number of parallel jobs in parallel mode. Default value corresponds (in most cases) to the +current amount of CPUs. + +See also [`--parallel`](#parallel). diff --git a/docs/spec/options/hurl/workers.option b/docs/spec/options/hurl/workers.option deleted file mode 100644 index 699254350..000000000 --- a/docs/spec/options/hurl/workers.option +++ /dev/null @@ -1,12 +0,0 @@ -name: workers -long: workers -value: NUM -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. Default value corresponds (in most cases) to the -current amount of CPUs. - -See also [`--parallel`](#parallel). diff --git a/integration/hurl/tests_ok/parallel.err.pattern b/integration/hurl/tests_ok/parallel.err.pattern index ee040e3ff..b3e2eea23 100644 --- a/integration/hurl/tests_ok/parallel.err.pattern +++ b/integration/hurl/tests_ok/parallel.err.pattern @@ -1,4 +1,4 @@ -* Parallel run using ~~~ workers +* Parallel run using 4 workers * Variables: * name: Bob * ------------------------------------------------------------------------------ diff --git a/integration/hurl/tests_ok/parallel.ps1 b/integration/hurl/tests_ok/parallel.ps1 index 7184581ea..167b98c8e 100644 --- a/integration/hurl/tests_ok/parallel.ps1 +++ b/integration/hurl/tests_ok/parallel.ps1 @@ -6,7 +6,7 @@ $ErrorActionPreference = 'Stop' $Start = [DateTimeOffset]::Now.ToUnixTimeSeconds() -hurl --parallel --verbose --variable name=Bob ` +hurl --parallel --jobs 4 --verbose --variable name=Bob ` tests_ok/parallel.hurl ` tests_ok/parallel.hurl ` tests_ok/parallel.hurl ` diff --git a/integration/hurl/tests_ok/parallel.sh b/integration/hurl/tests_ok/parallel.sh index f67755fa9..b2d4dbfe8 100755 --- a/integration/hurl/tests_ok/parallel.sh +++ b/integration/hurl/tests_ok/parallel.sh @@ -7,7 +7,7 @@ rm -f build/parallel.tap start=$(date +%s) -hurl --parallel --verbose --variable name=Bob \ +hurl --parallel --jobs 4 --verbose --variable name=Bob \ tests_ok/parallel.hurl \ tests_ok/parallel.hurl \ tests_ok/parallel.hurl \ diff --git a/integration/hurl/tests_ok/parallel_one_worker.ps1 b/integration/hurl/tests_ok/parallel_one_worker.ps1 index 7d32f5d17..bd1de0968 100644 --- a/integration/hurl/tests_ok/parallel_one_worker.ps1 +++ b/integration/hurl/tests_ok/parallel_one_worker.ps1 @@ -1,7 +1,7 @@ Set-StrictMode -Version latest $ErrorActionPreference = 'Stop' -hurl --parallel --workers 1 ` +hurl --parallel --jobs 1 ` tests_ok/parallel_a.hurl ` tests_ok/parallel_b.hurl ` tests_ok/parallel_c.hurl ` diff --git a/integration/hurl/tests_ok/parallel_one_worker.sh b/integration/hurl/tests_ok/parallel_one_worker.sh index c36cab706..e13186474 100755 --- a/integration/hurl/tests_ok/parallel_one_worker.sh +++ b/integration/hurl/tests_ok/parallel_one_worker.sh @@ -1,7 +1,7 @@ #!/bin/bash set -Eeuo pipefail -hurl --parallel --workers 1 \ +hurl --parallel --jobs 1 \ tests_ok/parallel_a.hurl \ tests_ok/parallel_b.hurl \ tests_ok/parallel_c.hurl \ diff --git a/packages/hurl/src/cli/options/commands.rs b/packages/hurl/src/cli/options/commands.rs index 8a56222c0..b2cc0700d 100644 --- a/packages/hurl/src/cli/options/commands.rs +++ b/packages/hurl/src/cli/options/commands.rs @@ -264,6 +264,16 @@ pub fn ipv6() -> clap::Arg { .action(clap::ArgAction::SetTrue) } +pub fn jobs() -> clap::Arg { + clap::Arg::new("jobs") + .long("jobs") + .value_name("NUM") + .value_parser(clap::value_parser!(u32).range(1..)) + .help("(Experimental) Maximum number of parallel jobs") + .num_args(1) + .hide(true) +} + pub fn json() -> clap::Arg { clap::Arg::new("json") .long("json") @@ -514,13 +524,3 @@ pub fn very_verbose() -> clap::Arg { .help("Turn on verbose output, including HTTP response and libcurl logs") .action(clap::ArgAction::SetTrue) } - -pub fn workers() -> clap::Arg { - clap::Arg::new("workers") - .long("workers") - .value_name("NUM") - .value_parser(clap::value_parser!(u32).range(1..)) - .help("(Experimental) Maximum number of parallel execution") - .num_args(1) - .hide(true) -} diff --git a/packages/hurl/src/cli/options/matches.rs b/packages/hurl/src/cli/options/matches.rs index 6a39bd90e..e2855cce9 100644 --- a/packages/hurl/src/cli/options/matches.rs +++ b/packages/hurl/src/cli/options/matches.rs @@ -250,8 +250,8 @@ pub fn max_redirect(arg_matches: &ArgMatches) -> Option { } } -pub fn workers(arg_matches: &ArgMatches) -> Option { - get::(arg_matches, "workers").map(|m| m as usize) +pub fn jobs(arg_matches: &ArgMatches) -> Option { + get::(arg_matches, "jobs").map(|m| m as usize) } pub fn netrc(arg_matches: &ArgMatches) -> bool { diff --git a/packages/hurl/src/cli/options/mod.rs b/packages/hurl/src/cli/options/mod.rs index ce18b4205..1e46a7b19 100644 --- a/packages/hurl/src/cli/options/mod.rs +++ b/packages/hurl/src/cli/options/mod.rs @@ -65,6 +65,7 @@ pub struct CliOptions { pub insecure: bool, pub interactive: bool, pub ip_resolve: Option, + pub jobs: Option, pub junit_file: Option, pub max_redirect: Option, pub netrc: bool, @@ -91,7 +92,6 @@ pub struct CliOptions { pub variables: HashMap, pub verbose: bool, pub very_verbose: bool, - pub workers: Option, } #[derive(Copy, Clone, Debug, PartialEq, Eq)] @@ -189,6 +189,7 @@ pub fn parse() -> Result { .arg(commands::interactive()) .arg(commands::ipv4()) .arg(commands::ipv6()) + .arg(commands::jobs()) .arg(commands::json()) .arg(commands::max_redirects()) .arg(commands::max_time()) @@ -217,8 +218,7 @@ pub fn parse() -> Result { .arg(commands::variable()) .arg(commands::variables_file()) .arg(commands::verbose()) - .arg(commands::very_verbose()) - .arg(commands::workers()); + .arg(commands::very_verbose()); let arg_matches = command.try_get_matches_from_mut(env::args_os())?; let opts = parse_matches(&arg_matches)?; @@ -289,7 +289,7 @@ fn parse_matches(arg_matches: &ArgMatches) -> Result Result Result, CliError> { - let workers_count = min(files.len(), workers); + let workers_count = min(files.len(), workers_count); let variables = &options.variables; let output_type = options .output_type