Skip to content

Commit

Permalink
Fix config wasm (#144)
Browse files Browse the repository at this point in the history
* Removed references to SystemTest (#134)

* Added README instructions for building and link to examples (#136)

* Zip all map (#138)

* add ZipAllMap, and some doc comments and tests

* add doctests to pr.sh

---------

Co-authored-by: Zachery Olson <[email protected]>

* Adds skipBody CLI argument - Skips Request and Response Body in Try Output (#140)

* Cargo version upgrade

* Updated the Guide to include the new available flag options for instructional purposes

* Added the ability to include skipBody argument in TryConfig and modified output to honor new skip flag

* included the new argument in the TmpTryConfig for testing purposes

* change version upgrade back to original as requested

* Removed unnessesary matches as requested

* Changes made to output format as requested

* Format changes as requested

* format changes as requested by Rustfmt in the github checks

* Manually fixed format errors

* Fixed additional fmt failure after updating rust to 1.72

---------

Co-authored-by: Trevor McMaster <[email protected]>

* Added additional tests to the config-wasm tests

- Added all example files to validate
- Added all the legacy examples and legacy integration tests to validate

* Added additional tests to validate the legacy yaml

* Updated the config-wasm and config::LoadTestEither to check old and new yaml

- Added the additional functions missing to the LoadTestEither
- Changed the config wasm to compile with feature legacy and use LoadTestEither instead of v2::LoadTest

* Updated dependencies and fixed deprecations (#143)

* Updated dependencies and fixed deprecations

* Updated Wasm-pack to match the version in the 0.6.0 scripting branch

* Updated the README for the current changes

---------

Co-authored-by: Zachery Olson <[email protected]>
Co-authored-by: Idel <[email protected]>
  • Loading branch information
3 people authored Sep 1, 2023
1 parent 3cc1899 commit e8bdc90
Show file tree
Hide file tree
Showing 40 changed files with 3,818 additions and 1,686 deletions.
257 changes: 127 additions & 130 deletions Cargo.lock

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,30 @@ C:\vcpkg> set VCPKGRS_DYNAMIC=1 (or simply set it as your environment variable)
```

## Changelog
### v0.6.0
Changes:
- Major changes: Javascript scripting!

Bugs:
- Collect returns an array of strings regardless of input type
- auto-converter removes code templates. Leave in and TODO
- for_each doesn't let you do templates/js
- global loggers may not be running in try script

Bug fixes:

### v0.5.13
Changes:
- use IsTerminal trait (Rust 1.70.0), removing (direct) dependency on atty crate. (#130)
- Added example yaml files under /examples
- Adds skipBody CLI argument - Skips Request and Response Body in Try Output (#140)

Bug fixes:
- Updated dependencies and fixed deprecations (#143)
- Fixed the HDR Histogram build for webpack (#119)
- Use clap derive, fixing behavior of --include flag. (#121)
- Fix yaml loggers (#129)

### v0.5.12
Changes:
- Try Run: Clap no longer allows multiple occurences, it only allows multiple passed on one occurence. See [Simplify the takes_value API (range-based takes_values)](https://github.com/clap-rs/clap/issues/2688) and [Clap CHANGELOG](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md#400---2022-09-28). This does introduce a bug that if you specify the config file immediately after --include(s) it will think it's part of the --include. The user must either pass another option after -i or put the config file before the -i
Expand Down
3,135 changes: 1,658 additions & 1,477 deletions guide/results-viewer-react/package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions guide/results-viewer-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "results-viewer-react",
"version": "1.0.4",
"version": "1.0.5",
"description": "",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -30,7 +30,7 @@
"dependencies": {
"@fs/config-gen": "file:./lib/config-gen",
"@fs/hdr-histogram-wasm": "file:./lib/hdr-histogram-wasm",
"chart.js": "~4.3.0",
"chart.js": "~4.4.0",
"chartjs-adapter-date-fns": "^3.0.0",
"date-fns": "^2.29.3",
"file-saver": "^2.0.5",
Expand Down
2 changes: 1 addition & 1 deletion lib/config-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license.workspace = true
crate-type = ["cdylib"]

[dependencies]
config.workspace = true
config = { workspace = true, features = ["legacy"] }
js-sys.workspace = true
serde.workspace = true
serde-wasm-bindgen = "0.5"
Expand Down
63 changes: 17 additions & 46 deletions lib/config-wasm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use config::{endpoints::FileBody, EndPointBody, LoadTest, ProviderType};
use config::LoadTestEither;
use js_sys::Map;
use log::{debug, LevelFilter};
use std::{path::PathBuf, str::FromStr};
use log::LevelFilter;
use std::str::FromStr;
use wasm_bindgen::{prelude::wasm_bindgen, throw_str, JsValue, UnwrapThrowExt};

// Only valid because we are using this in a WebAssembly context without threads.
Expand Down Expand Up @@ -43,7 +43,7 @@ fn init_logging(log_level: Option<String>) {
}

#[wasm_bindgen]
pub struct Config(LoadTest);
pub struct Config(LoadTestEither);

#[allow(clippy::unused_unit)]
#[wasm_bindgen]
Expand All @@ -57,12 +57,8 @@ impl Config {
) -> Result<Config, JsValue> {
init_logging(log_level);
let env_vars = serde_wasm_bindgen::from_value(env_vars.into())?;
let load_test = LoadTest::from_yaml(
std::str::from_utf8(bytes).expect("TODO"),
PathBuf::default().into(),
&env_vars,
)
.map_err(|e| JsValue::from_str(&format!("{e:?}")))?;
let load_test = LoadTestEither::parse(std::str::from_utf8(bytes).expect("TODO"), &env_vars)
.map_err(|e| JsValue::from_str(&format!("{e:?}")))?;
Ok(Config(load_test))
}

Expand All @@ -76,60 +72,35 @@ impl Config {
#[wasm_bindgen(js_name = getLoggerFiles)]
pub fn get_logger_files(&self) -> Box<[JsValue]> {
self.0
.loggers
.values()
.map(|l| l.to.as_str().into())
.get_logger_files()
.into_iter()
.map(|l| l.into())
.collect::<Vec<_>>()
.into_boxed_slice()
}

// return the bucket size for the test
#[wasm_bindgen(js_name = getBucketSize)]
pub fn get_bucket_size(&self) -> u64 {
self.0.config.general.bucket_size.get().as_secs()
self.0.get_bucket_size()
}

// return a string array of files used to feed providers
#[wasm_bindgen(js_name = getInputFiles)]
pub fn get_input_files(&self) -> Box<[JsValue]> {
// We also need to include file bodies so we can validate that we have those as well.
// Endpoint file bodies - BodyTemplate(File)
let mut body_files: Vec<JsValue> = self
.0
.endpoints
.iter()
.filter_map(|endpoint| {
if let Some(EndPointBody::File(FileBody { path: template, .. })) = &endpoint.body {
// The path is the base path, the template.pieces has the real path
debug!("endpoint::body::file.template={:?}", template);
Some(template.evaluate_with_star().into())
} else {
None
}
})
.collect::<Vec<_>>();
// file providers
let mut provider_files = self
.0
.providers
.iter()
.filter_map(|(_, v)| {
if let ProviderType::File(f) = v {
Some(f.path.get().as_str().into())
} else {
None
}
})
.collect::<Vec<_>>();
provider_files.append(&mut body_files);
provider_files.into_boxed_slice()
self.0
.get_input_files()
.into_iter()
.map(|l| l.into())
.collect::<Vec<_>>()
.into_boxed_slice()
}

// returns nothing if the config file has no errors, throws an error containing a string description, if the config file has errors
#[wasm_bindgen(js_name = checkOk)]
pub fn check_ok(&self) -> Result<(), JsValue> {
self.0
.ok_for_loadtest()
.check_ok()
.map_err(|e| JsValue::from_str(&format!("{e:?}")))
}
}
26 changes: 26 additions & 0 deletions lib/config-wasm/tests/legacy_examples/body_file.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Run this file with the test-server, then specify the PORT as a parameter to this try or run script.

vars:
port: "${PORT}"

load_pattern:
- linear:
from: 10%
to: 100%
over: 15s

loggers:
test:
to: stderr

endpoints:
- method: POST
url: http://localhost:${port}
headers:
Content-Type: 'image/jpeg'
body:
file: pewpew.jpg
peak_load: 1hps
logs:
test:
select: response.status
37 changes: 37 additions & 0 deletions lib/config-wasm/tests/legacy_examples/body_formdata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Run this file with the test-server, then specify the PORT as a parameter to this try or run script.
# This file also requires a PASSWORD environment variable. Any value will work and the the password will be scrubbed from the logs.

# This version will always put in new sessions and slowly replace the old ones

vars:
port: ${PORT}
username: test-user
password: test-password
dev_key: dev-key-001

load_pattern:
- linear:
from: 100%
to: 100%
over: 15s

loggers:
test:
to: stderr

endpoints:
- method: POST
url: http://localhost:${port}
headers:
Accept-Language: en-us
Content-Type: application/x-www-form-urlencoded
body: username=${username}&password=${password}&grant_type=password&client_id=${dev_key}
peak_load: 1hps
logs:
test:
select:
ts: epoch("ms")
response: request.body
token: response.body.token
on_demand: true

35 changes: 35 additions & 0 deletions lib/config-wasm/tests/legacy_examples/body_json.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Run this file with the test-server, then specify the PORT as a parameter to this try or run script.

vars:
port: "${PORT}"

load_pattern:
- linear:
from: 10%
to: 100%
over: 15s

loggers:
test:
to: stderr

endpoints:
- method: POST
url: http://localhost:${port}
headers:
Content-Type: application/json
body: '{
"a": "A long string",
"b": 42,
"c": true,
"d": ["array","of","values"],
"e": ${port},
"f": {
g: "sub",
h: "object"
}
}'
peak_load: 1hps
logs:
test:
select: response.status
36 changes: 36 additions & 0 deletions lib/config-wasm/tests/legacy_examples/body_multipart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Run this file with the test-server, then specify the PORT as a parameter to this try or run script.

vars:
port: "${PORT}"

load_pattern:
- linear:
from: 10%
to: 100%
over: 15s

loggers:
test:
to: stderr

endpoints:
- method: POST
url: http://localhost:${port}
headers:
Content-Type: multipart/form-data
body:
multipart:
modelProperties:
headers:
Content-Disposition: form-data; name="modelProperties"
body: 'english'
file:
headers:
Content-Disposition: form-data; name="file"; filename="pewpew.jpg"
Content-Type: image/jpeg
body:
file: pewpew.jpg
peak_load: 1hps
logs:
test:
select: response.status
Loading

0 comments on commit e8bdc90

Please sign in to comment.