Skip to content

Commit

Permalink
Merge pull request tag1consulting#423 from jeremyandrews/clippy
Browse files Browse the repository at this point in the history
clippy fixes from latest rust verison
  • Loading branch information
jeremyandrews authored Mar 21, 2022
2 parents 5f06851 + 64708ee commit bb59d74
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 105 deletions.
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1742,7 +1742,7 @@ impl GooseConfiguration {
// Use GooseDefault if not already set and not Worker.
GooseValue {
value: defaults.expect_workers,
filter: !self.expect_workers.is_some() && self.worker,
filter: self.expect_workers.is_none() && self.worker,
message: "expect_workers",
},
]);
Expand Down
2 changes: 1 addition & 1 deletion src/goose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1515,7 +1515,7 @@ impl GooseUser {
let built_request = request_builder.build()?;

// Get a string version of request path for logging.
let path = match Url::parse(&built_request.url().to_string()) {
let path = match Url::parse(built_request.url().as_ref()) {
Ok(u) => u.path().to_string(),
Err(e) => {
error!("failed to parse url: {}", e);
Expand Down
45 changes: 22 additions & 23 deletions src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,16 @@ fn merge_requests_from_worker(
// Only accrue overhead of merging status_code_counts if we're going to display the results
if status_codes {
for (status_code, count) in &user_request.status_code_counts {
let new_count;
// Add user count into global count
if let Some(existing_status_code_count) =
let new_count = if let Some(existing_status_code_count) =
merged_request.status_code_counts.get(status_code)
{
new_count = *existing_status_code_count + *count;
*existing_status_code_count + *count
}
// No global count exists yet, so start with user count
else {
new_count = *count;
}
*count
};
merged_request
.status_code_counts
.insert(*status_code, new_count);
Expand Down Expand Up @@ -193,17 +192,17 @@ fn merge_request_metrics(goose_attack: &mut GooseAttack, requests: GooseRequestM
debug!("requests metrics received: {:?}", requests.len());
for (request_key, request) in requests {
trace!("request_key: {}", request_key);
let merged_request;
if let Some(parent_request) = goose_attack.metrics.requests.get(&request_key) {
merged_request = merge_requests_from_worker(
parent_request,
&request,
goose_attack.configuration.status_codes,
);
} else {
// First time seeing this request, simply insert it.
merged_request = request.clone();
}
let merged_request =
if let Some(parent_request) = goose_attack.metrics.requests.get(&request_key) {
merge_requests_from_worker(
parent_request,
&request,
goose_attack.configuration.status_codes,
)
} else {
// First time seeing this request, simply insert it.
request.clone()
};
goose_attack
.metrics
.requests
Expand Down Expand Up @@ -231,13 +230,13 @@ fn merge_error_metrics(goose_attack: &mut GooseAttack, errors: GooseErrorMetrics
debug!("errors received: {:?}", errors.len());
for (error_key, error) in errors {
trace!("error_key: {}", error_key);
let merged_error;
if let Some(parent_error) = goose_attack.metrics.errors.get(&error_key) {
merged_error = merge_errors_from_worker(parent_error, &error);
} else {
// First time seeing this error, simply insert it.
merged_error = error.clone();
}
let merged_error =
if let Some(parent_error) = goose_attack.metrics.errors.get(&error_key) {
merge_errors_from_worker(parent_error, &error)
} else {
// First time seeing this error, simply insert it.
error.clone()
};
goose_attack
.metrics
.errors
Expand Down
40 changes: 18 additions & 22 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2122,12 +2122,11 @@ impl Serialize for GooseMetrics {
let mut s = serializer.serialize_struct("GooseMetrics", 10)?;
s.serialize_field("hash", &self.hash)?;
// Convert started field to a unix timestamp.
let timestamp;
if let Some(started) = self.started {
timestamp = started.timestamp();
let timestamp = if let Some(started) = self.started {
started.timestamp()
} else {
timestamp = 0;
}
0
};
s.serialize_field("started", &timestamp)?;
s.serialize_field("duration", &self.duration)?;
s.serialize_field("users", &self.users)?;
Expand Down Expand Up @@ -2939,24 +2938,22 @@ impl GooseAttack {
}

// Only build the tasks template if --no-task-metrics isn't enabled.
let errors_template: String;
if !self.metrics.errors.is_empty() {
let errors_template: String = if !self.metrics.errors.is_empty() {
let mut error_rows = Vec::new();
for error in self.metrics.errors.values() {
error_rows.push(report::error_row(error));
}

errors_template = report::errors_template(
report::errors_template(
&error_rows.join("\n"),
self.graph_data.get_errors_per_second_graph(),
);
)
} else {
errors_template = "".to_string();
}
"".to_string()
};

// Only build the status_code template if --status-codes is enabled.
let status_code_template: String;
if self.configuration.status_codes {
let status_code_template: String = if self.configuration.status_codes {
let mut status_code_metrics = Vec::new();
let mut aggregated_status_code_counts: HashMap<u16, usize> = HashMap::new();
for (request_key, request) in self.metrics.requests.iter().sorted() {
Expand Down Expand Up @@ -3000,12 +2997,11 @@ impl GooseAttack {
}

// Compile the status_code metrics template.
status_code_template =
report::status_code_metrics_template(&status_code_rows.join("\n"));
report::status_code_metrics_template(&status_code_rows.join("\n"))
} else {
// If --status-codes is not enabled, return an empty template.
status_code_template = "".to_string();
}
"".to_string()
};

// Compile the report template.
let report = report::build_report(
Expand Down Expand Up @@ -3170,13 +3166,13 @@ pub(crate) fn prepare_status_codes(
);
}
if let Some(aggregate_status_code_counts) = aggregate_counts.as_mut() {
let new_count;
if let Some(existing_status_code_count) = aggregate_status_code_counts.get(status_code)
let new_count = if let Some(existing_status_code_count) =
aggregate_status_code_counts.get(status_code)
{
new_count = *existing_status_code_count + *count;
*existing_status_code_count + *count
} else {
new_count = *count;
}
*count
};
aggregate_status_code_counts.insert(*status_code, new_count);
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,17 +598,17 @@ mod tests {
#[test]
fn valid_host() {
assert!(is_valid_host("http://example.com").is_ok());
assert!(!is_valid_host("example.com").is_ok());
assert!(is_valid_host("example.com").is_err());
assert!(is_valid_host("http://example.com/").is_ok());
assert!(!is_valid_host("example.com/").is_ok());
assert!(is_valid_host("example.com/").is_err());
assert!(is_valid_host("https://www.example.com/and/with/path").is_ok());
assert!(!is_valid_host("www.example.com/and/with/path").is_ok());
assert!(is_valid_host("www.example.com/and/with/path").is_err());
assert!(is_valid_host("foo://example.com").is_ok());
assert!(is_valid_host("file:///path/to/file").is_ok());
assert!(!is_valid_host("/path/to/file").is_ok());
assert!(!is_valid_host("http://").is_ok());
assert!(is_valid_host("/path/to/file").is_err());
assert!(is_valid_host("http://").is_err());
assert!(is_valid_host("http://foo").is_ok());
assert!(is_valid_host("http:///example.com").is_ok());
assert!(!is_valid_host("http:// example.com").is_ok());
assert!(is_valid_host("http:// example.com").is_err());
}
}
8 changes: 4 additions & 4 deletions tests/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ async fn test_no_defaults() {
"--users",
&USERS.to_string(),
"--hatch-rate",
&HATCH_RATE.to_string(),
HATCH_RATE,
"--run-time",
&RUN_TIME.to_string(),
"--request-log",
Expand Down Expand Up @@ -444,7 +444,7 @@ async fn test_no_defaults_gaggle() {
vec![
"--worker",
"--manager-host",
&HOST.to_string(),
HOST,
"--manager-port",
&PORT.to_string(),
"--request-log",
Expand Down Expand Up @@ -477,13 +477,13 @@ async fn test_no_defaults_gaggle() {
"--expect-workers",
&EXPECT_WORKERS.to_string(),
"--manager-bind-host",
&HOST.to_string(),
HOST,
"--manager-bind-port",
&PORT.to_string(),
"--users",
&USERS.to_string(),
"--hatch-rate",
&HATCH_RATE.to_string(),
HATCH_RATE,
"--run-time",
&RUN_TIME.to_string(),
"--no-reset-metrics",
Expand Down
46 changes: 21 additions & 25 deletions tests/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,32 +262,31 @@ async fn run_standalone_test(test_type: &TestType, scheduler: &GooseScheduler) {
// Build common configuration.
let configuration = common_build_configuration(&server, None, None);

let goose_attack;
match test_type {
let goose_attack = match test_type {
TestType::TaskSets => {
// Get the tasksets, start and stop tasks to build a load test.
let (taskset1, taskset2, start_task, stop_task) = get_tasksets();
// Set up the common base configuration.
goose_attack = crate::GooseAttack::initialize_with_config(configuration)
crate::GooseAttack::initialize_with_config(configuration)
.unwrap()
.register_taskset(taskset1)
.register_taskset(taskset2)
.test_start(start_task)
.test_stop(stop_task)
.set_scheduler(scheduler.clone());
.set_scheduler(scheduler.clone())
}
TestType::Tasks => {
// Get the taskset, start and stop tasks to build a load test.
let (taskset1, start_task, stop_task) = get_tasks();
// Set up the common base configuration.
goose_attack = crate::GooseAttack::initialize_with_config(configuration)
crate::GooseAttack::initialize_with_config(configuration)
.unwrap()
.register_taskset(taskset1)
.test_start(start_task)
.test_stop(stop_task)
.set_scheduler(scheduler.clone());
.set_scheduler(scheduler.clone())
}
}
};

// Run the Goose Attack.
common::run_load_test(goose_attack, None).await;
Expand Down Expand Up @@ -339,34 +338,31 @@ async fn run_gaggle_test(test_type: &TestType, scheduler: &GooseScheduler) {
// Build Manager configuration.
let manager_configuration = common_build_configuration(&server, None, Some(EXPECT_WORKERS));

let manager_goose_attack;
match test_type {
let manager_goose_attack = match test_type {
TestType::TaskSets => {
// Get the tasksets, start and stop tasks to build a load test.
let (taskset1, taskset2, start_task, stop_task) = get_tasksets();
// Build the load test for the Manager.
manager_goose_attack =
crate::GooseAttack::initialize_with_config(manager_configuration)
.unwrap()
.register_taskset(taskset1)
.register_taskset(taskset2)
.test_start(start_task)
.test_stop(stop_task)
.set_scheduler(scheduler.clone());
crate::GooseAttack::initialize_with_config(manager_configuration)
.unwrap()
.register_taskset(taskset1)
.register_taskset(taskset2)
.test_start(start_task)
.test_stop(stop_task)
.set_scheduler(scheduler.clone())
}
TestType::Tasks => {
// Get the taskset, start and stop tasks to build a load test.
let (taskset1, start_task, stop_task) = get_tasks();
// Build the load test for the Manager.
manager_goose_attack =
crate::GooseAttack::initialize_with_config(manager_configuration)
.unwrap()
.register_taskset(taskset1)
.test_start(start_task)
.test_stop(stop_task)
.set_scheduler(scheduler.clone());
crate::GooseAttack::initialize_with_config(manager_configuration)
.unwrap()
.register_taskset(taskset1)
.test_start(start_task)
.test_stop(stop_task)
.set_scheduler(scheduler.clone())
}
}
};

// Run the Goose Attack.
common::run_load_test(manager_goose_attack, Some(worker_handles)).await;
Expand Down
42 changes: 19 additions & 23 deletions tests/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,10 @@ async fn run_standalone_test(test_type: TestType) {
// Get the taskset, start and stop tasks to build a load test.
let (taskset, start_task, stop_task) = get_tasks(&test_type);

let goose_attack;
match test_type {
let goose_attack = match test_type {
TestType::NotSequenced | TestType::SequencedRoundRobin => {
// Set up the common base configuration.
goose_attack = crate::GooseAttack::initialize_with_config(configuration)
crate::GooseAttack::initialize_with_config(configuration)
.unwrap()
.register_taskset(taskset)
.test_start(start_task)
Expand All @@ -253,14 +252,14 @@ async fn run_standalone_test(test_type: TestType) {
}
TestType::SequencedSerial => {
// Set up the common base configuration.
goose_attack = crate::GooseAttack::initialize_with_config(configuration)
crate::GooseAttack::initialize_with_config(configuration)
.unwrap()
.register_taskset(taskset)
.test_start(start_task)
.test_stop(stop_task)
.set_scheduler(GooseScheduler::Serial)
}
}
};

// Run the Goose Attack.
common::run_load_test(goose_attack, None).await;
Expand Down Expand Up @@ -310,30 +309,27 @@ async fn run_gaggle_test(test_type: TestType) {
// Build Manager configuration.
let manager_configuration = common_build_configuration(&server, None, Some(EXPECT_WORKERS));

let manager_goose_attack;
match test_type {
let manager_goose_attack = match test_type {
TestType::NotSequenced | TestType::SequencedRoundRobin => {
// Set up the common base configuration.
manager_goose_attack =
crate::GooseAttack::initialize_with_config(manager_configuration)
.unwrap()
.register_taskset(taskset)
.test_start(start_task)
.test_stop(stop_task)
// Unnecessary as this is the default.
.set_scheduler(GooseScheduler::RoundRobin);
crate::GooseAttack::initialize_with_config(manager_configuration)
.unwrap()
.register_taskset(taskset)
.test_start(start_task)
.test_stop(stop_task)
// Unnecessary as this is the default.
.set_scheduler(GooseScheduler::RoundRobin)
}
TestType::SequencedSerial => {
// Set up the common base configuration.
manager_goose_attack =
crate::GooseAttack::initialize_with_config(manager_configuration)
.unwrap()
.register_taskset(taskset)
.test_start(start_task)
.test_stop(stop_task)
.set_scheduler(GooseScheduler::Serial);
crate::GooseAttack::initialize_with_config(manager_configuration)
.unwrap()
.register_taskset(taskset)
.test_start(start_task)
.test_stop(stop_task)
.set_scheduler(GooseScheduler::Serial)
}
}
};

// Run the Goose Attack.
common::run_load_test(manager_goose_attack, Some(worker_handles)).await;
Expand Down

0 comments on commit bb59d74

Please sign in to comment.