mirror of
https://github.com/Orange-OpenSource/hurl.git
synced 2024-12-23 11:02:43 +03:00
Add retry-interval request option.
This commit is contained in:
parent
cec84ca811
commit
9e6f5088c6
@ -35,6 +35,10 @@
|
||||
* ------------------------------------------------------------------------------
|
||||
* Executing entry 2
|
||||
*
|
||||
* Entry options:
|
||||
* retry: true
|
||||
* retry-interval: 100
|
||||
*
|
||||
* Cookie store:
|
||||
*
|
||||
* Request:
|
||||
@ -58,9 +62,9 @@
|
||||
<
|
||||
*
|
||||
* Assert failure
|
||||
* --> tests_ok/retry.hurl:16:0
|
||||
* --> tests_ok/option_retry.hurl:19:0
|
||||
* |
|
||||
* 16 | jsonpath "$.state" == "COMPLETED"
|
||||
* 19 | jsonpath "$.state" == "COMPLETED"
|
||||
* | actual: string <RUNNING>
|
||||
* | expected: string <COMPLETED>
|
||||
* |
|
||||
@ -69,6 +73,10 @@
|
||||
* ------------------------------------------------------------------------------
|
||||
* Executing entry 2
|
||||
*
|
||||
* Entry options:
|
||||
* retry: true
|
||||
* retry-interval: 100
|
||||
*
|
||||
* Cookie store:
|
||||
*
|
||||
* Request:
|
||||
@ -92,9 +100,9 @@
|
||||
<
|
||||
*
|
||||
* Assert failure
|
||||
* --> tests_ok/retry.hurl:16:0
|
||||
* --> tests_ok/option_retry.hurl:19:0
|
||||
* |
|
||||
* 16 | jsonpath "$.state" == "COMPLETED"
|
||||
* 19 | jsonpath "$.state" == "COMPLETED"
|
||||
* | actual: string <RUNNING>
|
||||
* | expected: string <COMPLETED>
|
||||
* |
|
||||
@ -103,6 +111,10 @@
|
||||
* ------------------------------------------------------------------------------
|
||||
* Executing entry 2
|
||||
*
|
||||
* Entry options:
|
||||
* retry: true
|
||||
* retry-interval: 100
|
||||
*
|
||||
* Cookie store:
|
||||
*
|
||||
* Request:
|
||||
@ -126,9 +138,9 @@
|
||||
<
|
||||
*
|
||||
* Assert failure
|
||||
* --> tests_ok/retry.hurl:16:0
|
||||
* --> tests_ok/option_retry.hurl:19:0
|
||||
* |
|
||||
* 16 | jsonpath "$.state" == "COMPLETED"
|
||||
* 19 | jsonpath "$.state" == "COMPLETED"
|
||||
* | actual: string <RUNNING>
|
||||
* | expected: string <COMPLETED>
|
||||
* |
|
||||
@ -137,6 +149,10 @@
|
||||
* ------------------------------------------------------------------------------
|
||||
* Executing entry 2
|
||||
*
|
||||
* Entry options:
|
||||
* retry: true
|
||||
* retry-interval: 100
|
||||
*
|
||||
* Cookie store:
|
||||
*
|
||||
* Request:
|
||||
@ -160,9 +176,9 @@
|
||||
<
|
||||
*
|
||||
* Assert failure
|
||||
* --> tests_ok/retry.hurl:16:0
|
||||
* --> tests_ok/option_retry.hurl:19:0
|
||||
* |
|
||||
* 16 | jsonpath "$.state" == "COMPLETED"
|
||||
* 19 | jsonpath "$.state" == "COMPLETED"
|
||||
* | actual: string <RUNNING>
|
||||
* | expected: string <COMPLETED>
|
||||
* |
|
||||
@ -171,6 +187,10 @@
|
||||
* ------------------------------------------------------------------------------
|
||||
* Executing entry 2
|
||||
*
|
||||
* Entry options:
|
||||
* retry: true
|
||||
* retry-interval: 100
|
||||
*
|
||||
* Cookie store:
|
||||
*
|
||||
* Request:
|
||||
|
28
integration/tests_ok/option_retry.html
Normal file
28
integration/tests_ok/option_retry.html
Normal file
@ -0,0 +1,28 @@
|
||||
<pre><code class="language-hurl"><span class="hurl-entry"><span class="request"><span class="line"></span><span class="comment"># Create a new job</span>
|
||||
<span class="line"><span class="method">POST</span> <span class="url">http://localhost:8000/jobs</span></span>
|
||||
</span><span class="response"><span class="line"></span>
|
||||
<span class="line"><span class="version">HTTP/*</span> <span class="number">201</span></span>
|
||||
<span class="line section-header">[Captures]</span>
|
||||
<span class="line"><span class="name">job_id</span><span>:</span> <span class="query-type">jsonpath</span> <span class="string">"$.id"</span></span>
|
||||
<span class="line section-header">[Asserts]</span>
|
||||
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.state"</span> <span class="predicate-type">==</span> <span class="string">"RUNNING"</span></span>
|
||||
</span></span><span class="hurl-entry"><span class="request"><span class="line"></span>
|
||||
<span class="line"></span>
|
||||
<span class="line"></span><span class="comment"># Pull job status until it is completed</span>
|
||||
<span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/jobs/{{job_id}}</span></span>
|
||||
<span class="line section-header">[Options]</span>
|
||||
<span class="line"><span class="string">retry</span><span>:</span> <span class="boolean">true</span></span>
|
||||
<span class="line"><span class="string">retry-interval</span><span>:</span> <span class="number">100</span></span>
|
||||
</span><span class="response"><span class="line"></span>
|
||||
<span class="line"><span class="version">HTTP/*</span> <span class="number">200</span></span>
|
||||
<span class="line section-header">[Asserts]</span>
|
||||
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.state"</span> <span class="predicate-type">==</span> <span class="string">"COMPLETED"</span></span>
|
||||
</span></span><span class="hurl-entry"><span class="request"><span class="line"></span>
|
||||
<span class="line"></span>
|
||||
<span class="line"></span><span class="comment"># Delete the job</span>
|
||||
<span class="line"><span class="method">DELETE</span> <span class="url">http://localhost:8000/jobs/{{job_id}}</span></span>
|
||||
</span><span class="response"><span class="line"><span class="version">HTTP/*</span> <span class="number">200</span></span>
|
||||
</span></span><span class="hurl-entry"><span class="request"><span class="line"></span>
|
||||
<span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/jobs/{{job_id}}</span></span>
|
||||
</span><span class="response"><span class="line"><span class="version">HTTP/*</span> <span class="number">404</span></span>
|
||||
</span></span></code></pre>
|
@ -12,6 +12,7 @@ jsonpath "$.state" == "RUNNING"
|
||||
GET http://localhost:8000/jobs/{{job_id}}
|
||||
[Options]
|
||||
retry: true
|
||||
retry-interval: 100
|
||||
|
||||
HTTP/* 200
|
||||
[Asserts]
|
||||
|
2
integration/tests_ok/option_retry.options
Normal file
2
integration/tests_ok/option_retry.options
Normal file
@ -0,0 +1,2 @@
|
||||
--verbose
|
||||
--json
|
File diff suppressed because one or more lines are too long
@ -16,6 +16,7 @@
|
||||
*
|
||||
*/
|
||||
use std::collections::HashMap;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::cli::Logger;
|
||||
use crate::http;
|
||||
@ -301,6 +302,10 @@ pub fn get_entry_options(
|
||||
runner_options.retry = option.value;
|
||||
logger.debug(format!("retry: {}", option.value).as_str());
|
||||
}
|
||||
EntryOption::RetryInterval(option) => {
|
||||
runner_options.retry_interval = Duration::from_millis(option.value);
|
||||
logger.debug(format!("retry-interval: {}", option.value).as_str());
|
||||
}
|
||||
EntryOption::Variable(VariableOption {
|
||||
value: VariableDefinition { name, value, .. },
|
||||
..
|
||||
|
@ -677,6 +677,7 @@ pub enum EntryOption {
|
||||
FollowLocation(FollowLocationOption),
|
||||
MaxRedirect(MaxRedirectOption),
|
||||
Retry(RetryOption),
|
||||
RetryInterval(RetryIntervalOption),
|
||||
Variable(VariableOption),
|
||||
Verbose(VerboseOption),
|
||||
VeryVerbose(VeryVerboseOption),
|
||||
@ -722,6 +723,16 @@ pub struct RetryOption {
|
||||
pub line_terminator0: LineTerminator,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct RetryIntervalOption {
|
||||
pub line_terminators: Vec<LineTerminator>,
|
||||
pub space0: Whitespace,
|
||||
pub space1: Whitespace,
|
||||
pub space2: Whitespace,
|
||||
pub value: u64,
|
||||
pub line_terminator0: LineTerminator,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct VerboseOption {
|
||||
pub line_terminators: Vec<LineTerminator>,
|
||||
|
@ -238,6 +238,7 @@ impl Htmlable for EntryOption {
|
||||
EntryOption::FollowLocation(option) => option.to_html(),
|
||||
EntryOption::MaxRedirect(option) => option.to_html(),
|
||||
EntryOption::Retry(option) => option.to_html(),
|
||||
EntryOption::RetryInterval(option) => option.to_html(),
|
||||
EntryOption::Variable(option) => option.to_html(),
|
||||
EntryOption::Verbose(option) => option.to_html(),
|
||||
EntryOption::VeryVerbose(option) => option.to_html(),
|
||||
@ -347,6 +348,23 @@ impl Htmlable for RetryOption {
|
||||
}
|
||||
}
|
||||
|
||||
impl Htmlable for RetryIntervalOption {
|
||||
fn to_html(&self) -> String {
|
||||
let mut buffer = String::from("");
|
||||
add_line_terminators(&mut buffer, self.line_terminators.clone());
|
||||
buffer.push_str("<span class=\"line\">");
|
||||
buffer.push_str(self.space0.to_html().as_str());
|
||||
buffer.push_str("<span class=\"string\">retry-interval</span>");
|
||||
buffer.push_str(self.space1.to_html().as_str());
|
||||
buffer.push_str("<span>:</span>");
|
||||
buffer.push_str(self.space2.to_html().as_str());
|
||||
buffer.push_str(format!("<span class=\"number\">{}</span>", self.value).as_str());
|
||||
buffer.push_str("</span>");
|
||||
buffer.push_str(self.line_terminator0.to_html().as_str());
|
||||
buffer
|
||||
}
|
||||
}
|
||||
|
||||
impl Htmlable for VariableOption {
|
||||
fn to_html(&self) -> String {
|
||||
let mut buffer = String::from("");
|
||||
|
@ -350,6 +350,7 @@ fn option(reader: &mut Reader) -> ParseResult<'static, EntryOption> {
|
||||
option_follow_location,
|
||||
option_max_redirect,
|
||||
option_retry,
|
||||
option_retry_interval,
|
||||
option_variable,
|
||||
option_verbose,
|
||||
option_very_verbose,
|
||||
@ -492,6 +493,28 @@ fn option_retry(reader: &mut Reader) -> ParseResult<'static, EntryOption> {
|
||||
Ok(EntryOption::Retry(option))
|
||||
}
|
||||
|
||||
fn option_retry_interval(reader: &mut Reader) -> ParseResult<'static, EntryOption> {
|
||||
let line_terminators = optional_line_terminators(reader)?;
|
||||
let space0 = zero_or_more_spaces(reader)?;
|
||||
try_literal("retry-interval", reader)?;
|
||||
let space1 = zero_or_more_spaces(reader)?;
|
||||
try_literal(":", reader)?;
|
||||
let space2 = zero_or_more_spaces(reader)?;
|
||||
let value = nonrecover(natural, reader)?;
|
||||
let line_terminator0 = line_terminator(reader)?;
|
||||
|
||||
let option = RetryIntervalOption {
|
||||
line_terminators,
|
||||
space0,
|
||||
space1,
|
||||
space2,
|
||||
value,
|
||||
line_terminator0,
|
||||
};
|
||||
|
||||
Ok(EntryOption::RetryInterval(option))
|
||||
}
|
||||
|
||||
fn option_variable(reader: &mut Reader) -> ParseResult<'static, EntryOption> {
|
||||
let line_terminators = optional_line_terminators(reader)?;
|
||||
let space0 = zero_or_more_spaces(reader)?;
|
||||
|
@ -825,6 +825,7 @@ impl Tokenizable for EntryOption {
|
||||
EntryOption::FollowLocation(option) => option.tokenize(),
|
||||
EntryOption::MaxRedirect(option) => option.tokenize(),
|
||||
EntryOption::Retry(option) => option.tokenize(),
|
||||
EntryOption::RetryInterval(option) => option.tokenize(),
|
||||
EntryOption::Variable(option) => option.tokenize(),
|
||||
EntryOption::Verbose(option) => option.tokenize(),
|
||||
EntryOption::VeryVerbose(option) => option.tokenize(),
|
||||
@ -958,6 +959,27 @@ impl Tokenizable for RetryOption {
|
||||
}
|
||||
}
|
||||
|
||||
impl Tokenizable for RetryIntervalOption {
|
||||
fn tokenize(&self) -> Vec<Token> {
|
||||
let mut tokens: Vec<Token> = vec![];
|
||||
tokens.append(
|
||||
&mut self
|
||||
.line_terminators
|
||||
.iter()
|
||||
.flat_map(|e| e.tokenize())
|
||||
.collect(),
|
||||
);
|
||||
tokens.append(&mut self.space0.tokenize());
|
||||
tokens.push(Token::String("retry-interval".to_string()));
|
||||
tokens.append(&mut self.space1.tokenize());
|
||||
tokens.push(Token::Colon(String::from(":")));
|
||||
tokens.append(&mut self.space2.tokenize());
|
||||
tokens.push(Token::Number(self.value.to_string()));
|
||||
tokens.append(&mut self.line_terminator0.tokenize());
|
||||
tokens
|
||||
}
|
||||
}
|
||||
|
||||
impl Tokenizable for VariableOption {
|
||||
fn tokenize(&self) -> Vec<Token> {
|
||||
let mut tokens: Vec<Token> = vec![];
|
||||
|
Loading…
Reference in New Issue
Block a user