Fix parallel integration tests.

This commit is contained in:
jcamiel 2024-03-31 18:11:04 +02:00
parent bf472937f9
commit 59f785974f
No known key found for this signature in database
GPG Key ID: 07FF11CFD55356CC
16 changed files with 43 additions and 43 deletions

View File

@ -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' \

View File

@ -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

View File

@ -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

View File

@ -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'

View File

@ -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).

View File

@ -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).

View File

@ -1,4 +1,4 @@
* Parallel run using ~~~ workers
* Parallel run using 4 workers
* Variables:
* name: Bob
* ------------------------------------------------------------------------------

View File

@ -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 `

View File

@ -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 \

View File

@ -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 `

View File

@ -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 \

View File

@ -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)
}

View File

@ -250,8 +250,8 @@ pub fn max_redirect(arg_matches: &ArgMatches) -> Option<usize> {
}
}
pub fn workers(arg_matches: &ArgMatches) -> Option<usize> {
get::<u32>(arg_matches, "workers").map(|m| m as usize)
pub fn jobs(arg_matches: &ArgMatches) -> Option<usize> {
get::<u32>(arg_matches, "jobs").map(|m| m as usize)
}
pub fn netrc(arg_matches: &ArgMatches) -> bool {

View File

@ -65,6 +65,7 @@ pub struct CliOptions {
pub insecure: bool,
pub interactive: bool,
pub ip_resolve: Option<IpResolve>,
pub jobs: Option<usize>,
pub junit_file: Option<PathBuf>,
pub max_redirect: Option<usize>,
pub netrc: bool,
@ -91,7 +92,6 @@ pub struct CliOptions {
pub variables: HashMap<String, Value>,
pub verbose: bool,
pub very_verbose: bool,
pub workers: Option<usize>,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
@ -189,6 +189,7 @@ pub fn parse() -> Result<CliOptions, CliOptionsError> {
.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<CliOptions, CliOptionsError> {
.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<CliOptions, CliOptionsError
let variables = matches::variables(arg_matches)?;
let verbose = matches::verbose(arg_matches);
let very_verbose = matches::very_verbose(arg_matches);
let workers = matches::workers(arg_matches);
let workers = matches::jobs(arg_matches);
Ok(CliOptions {
aws_sigv4,
cacert_file,
@ -342,7 +342,7 @@ fn parse_matches(arg_matches: &ArgMatches) -> Result<CliOptions, CliOptionsError
variables,
verbose,
very_verbose,
workers,
jobs: workers,
})
}

View File

@ -82,10 +82,10 @@ fn main() {
EXIT_ERROR_UNDEFINED,
&base_logger,
);
let workers = opts.workers.unwrap_or(available.get());
base_logger.debug(&format!("Parallel run using {workers} workers"));
let workers_count = opts.jobs.unwrap_or(available.get());
base_logger.debug(&format!("Parallel run using {workers_count} workers"));
run::run_par(&opts.input_files, current_dir, &opts, workers)
run::run_par(&opts.input_files, current_dir, &opts, workers_count)
} else {
run::run_seq(&opts.input_files, current_dir, &opts)
};

View File

@ -125,9 +125,9 @@ pub fn run_par(
files: &[Input],
current_dir: &Path,
options: &CliOptions,
workers: usize,
workers_count: usize,
) -> Result<Vec<HurlRun>, 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