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

exec with in a request section #125

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
a nice feature would be running `exec` for every request.
I have tried this using the existing `exec` how ever if we run a `request` with-items (csv) the assign will store the last response only.

So I have implemented an `exec` within the request, due to the modular object oriented logic this feature was pretty easy (even though this is the first time I write in rust)

I'm willing to share the change with you and some example file
26 changes: 26 additions & 0 deletions example/exec-within-req.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# [iterations] - defines the number of times this will be invoked
# [concurrency] - defines the number of concurrent messages sent together
# [file_name:] - defines the csv file for getting the body content from.

---
base: "https://odedk.com"
iterations: 1
concurrency: 1
rampup: 2

plan:

- name: ExecWithinRequest
request:
url: https://{{item.tenant}}/login?auth_token={{item.headless_auth}}
method: GET
headers:
Host: '{{item.tenant}}'
assign: memory
with_items_from_csv:
file_name: ./headless_node_login.csv
quote_char: "'"
exec:
command: "echo \"{{item.tenant}}\" \"{{ memory.body }}\" | tee -a ./next_script.csv"

14 changes: 14 additions & 0 deletions src/actions/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use yaml_rust::Yaml;
use serde::{Deserialize, Serialize};
use serde_json::{json, Map, Value};

use crate::actions;
use crate::actions::{extract, extract_optional};
use crate::benchmark::{Context, Pool, Reports};
use crate::config::Config;
Expand All @@ -30,6 +31,7 @@ pub struct Request {
time: f64,
method: String,
headers: HashMap<String, String>,
pub exec: Option<actions::Exec>,
pub body: Option<String>,
pub with_item: Option<Yaml>,
pub index: Option<u32>,
Expand All @@ -51,6 +53,12 @@ impl Request {
let name = extract(item, "name");
let url = extract(&item["request"], "url");
let assign = extract_optional(item, "assign");
let mut exec: Option<actions::Exec> = None;
let exec_existance: bool = item["exec"].as_hash().is_some();

if exec_existance {
exec = Some(actions::Exec::new(item, None));
}

let method = if let Some(v) = extract_optional(&item["request"], "method") {
v.to_string().to_uppercase()
Expand Down Expand Up @@ -87,6 +95,7 @@ impl Request {
with_item,
index,
assign: assign.map(str::to_string),
exec,
}
}

Expand Down Expand Up @@ -316,6 +325,11 @@ impl Runnable for Request {
};

log_message_response.map(|msg| log_response(msg, &data));

match &self.exec {
Some(p) => p.execute(context, reports, &pool, &config).await,
None => (),
}
}
}
}
Expand Down