Skip to content

Commit a50e526

Browse files
czartednwiebe
andauthored
GH 731 - review (#362)
* begining with test server_initializer_collected_params_combine_vlcs_properly * removed GatheredParams from server_initializer_collected_params, added bools for data_dir, config_file and real_user to MultiConfig, fixing the test * add ComputedVcl struct and its implementation, add VclType enum, to be able to push into Vcl Vector, add processing in MultiConfig, add processing in server_initializer_collected_params * back to VirtualCommandLine type without enum, passing different types to MultiConfig and selecting them to computed_value_names on behalf of their type * fixed data flow with Evironment and Command line arguments, need to fix config file arguments data * changes in test to access config.file for various scenarios, add machinery to determine if real-user is specified in config-file * try to get rid of redundant MultiConfig construction in determine_user_specific_data * handle computed arguments in multiconfig, closure for server_initializer_collected_params, closure for keeping in node_configurator, final removal of redundant construction of multiconfig * computing env_args and cmd_args in create_preorientation_args fn! * fix passing test server_initializer_collected_params_can_read_parameters_from_config_file, some optimization * fixed VclArg problem with withdrawing data from VirtualCommandline, sorted server_initializer_collected_params and determine_user_specific_data fncs, new fns value_opt for VclArg and tests for them * finalize preparing guts for multiconfig in server_initializer_collected_params, added handling for tilde in data_directory and config_file paths * fix windows test of real_user soecified * renaming, adding TODOs, removing resolved TODOS * fixing tests for windows os * fixed on windows * formatting * fixed real user for windows * removed filling specified and unspecified boxes from server_initializer_collected_params, fixed formatting for get_real_user_from_vcl * last fixes of extract_values_and_fill_boxes, and test server_initializer_collected_params_handle_config_file_from_commandline_and_real_user_from_config_file_with_data_dir_started_by_tilde * fixed windows test for tilde * fix tilde test for windows * renaming of tests and functions * remove GatheredParams (the goal), optimizing is_user_specified in MultiConfig, dealing with comments * remove value_opt form VclArg, remove test for that, change MultiConfig and schema (config-file no longer defaulted), change value_from_vcl to multiconfig and value_m * resolving comments from review * optimization of get_config_file_from_mc fn * fixed the config_path reference bin replace_dots fn * solving dereferencing path in replace_dots fn * solving config_path in replace_dots fn * fixed get_config_file_from_mc fn - optimized for readability * formatting * removed println, and formated * fixed windows tests * formatting * workaround for actual_server_drop test * forgotten u64 for another test in connection_termination_test.rs * add one more request to actual_serve_drop * remove forgotten piece of code * fixing comments from review2 * remove redundant lifetime, and remove convertion to PathBuf * fixing absolute path for tests of handle config-file and data directory relative * run the actions * merge master into GH-731 * fix ENV and CLAP Guards in tests * fix Windows panic message for server_initializer_collected_params_handles_only_path_in_config_file_param * formatting * removing debugging println from accountant * fix CLI UI issue with config file * remove canonicalize() from test uses home_dir() from dirs crate. Produces malfuncioning behaviour * Reformatted some code, added a comment * formatting, fix order of Vcls in setup_reporter, add assertion to node_configurator_standard --------- Co-authored-by: Dan Wiebe <[email protected]>
1 parent bd56d3f commit a50e526

File tree

10 files changed

+1044
-217
lines changed

10 files changed

+1044
-217
lines changed

masq_lib/src/multi_config.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ impl<'a> MultiConfig<'a> {
6363
) -> Result<MultiConfig<'a>, ConfiguratorError> {
6464
let initial: Box<dyn VirtualCommandLine> =
6565
Box::new(CommandLineVcl::new(vec![String::new()]));
66-
let merged: Box<dyn VirtualCommandLine> = vcls
66+
let merged = vcls
6767
.into_iter()
6868
.fold(initial, |so_far, vcl| merge(so_far, vcl));
69+
6970
let arg_matches = match schema
7071
.clone()
7172
.get_matches_from_safe(merged.args().into_iter())
@@ -78,6 +79,7 @@ impl<'a> MultiConfig<'a> {
7879
_ => return Err(Self::make_configurator_error(e)),
7980
},
8081
};
82+
8183
Ok(MultiConfig { arg_matches })
8284
}
8385

@@ -224,6 +226,9 @@ impl NameOnlyVclArg {
224226
pub trait VirtualCommandLine {
225227
fn vcl_args(&self) -> Vec<&dyn VclArg>;
226228
fn args(&self) -> Vec<String>;
229+
fn is_computed(&self) -> bool {
230+
false
231+
}
227232
}
228233

229234
impl Debug for dyn VirtualCommandLine {
@@ -347,10 +352,19 @@ impl EnvironmentVcl {
347352
}
348353
}
349354

355+
#[derive(Debug)]
350356
pub struct ConfigFileVcl {
351357
vcl_args: Vec<Box<dyn VclArg>>,
352358
}
353359

360+
impl Clone for ConfigFileVcl {
361+
fn clone(&self) -> Self {
362+
ConfigFileVcl {
363+
vcl_args: self.vcl_args.iter().map(|arg| arg.dup()).collect(),
364+
}
365+
}
366+
}
367+
354368
impl VirtualCommandLine for ConfigFileVcl {
355369
fn vcl_args(&self) -> Vec<&dyn VclArg> {
356370
vcl_args_to_vcl_args(&self.vcl_args)
@@ -375,8 +389,8 @@ impl Display for ConfigFileVclError {
375389
match self {
376390
ConfigFileVclError::OpenError(path, _) => write!(
377391
fmt,
378-
"Couldn't open configuration file {:?}. Are you sure it exists?",
379-
path
392+
"Couldn't open configuration file \"{}\". Are you sure it exists?",
393+
path.to_string_lossy()
380394
),
381395
ConfigFileVclError::CorruptUtf8(path) => write!(
382396
fmt,

masq_lib/src/shared_schema.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ pub fn config_file_arg<'a>() -> Arg<'a, 'a> {
235235
Arg::with_name("config-file")
236236
.long("config-file")
237237
.value_name("FILE-PATH")
238-
.default_value("config.toml")
239238
.min_values(0)
240239
.max_values(1)
241240
.required(false)

multinode_integration_tests/tests/connection_termination_test.rs

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -116,27 +116,28 @@ fn actual_server_drop() {
116116
let mut server = real_node.make_server(server_port);
117117
let masquerader = JsonMasquerader::new();
118118
let (stream_key, return_route_id) = arbitrary_context();
119-
mock_node
120-
.transmit_package(
121-
mock_node.port_list()[0],
122-
create_request_icp(
123-
&mock_node,
124-
&real_node,
125-
stream_key,
126-
return_route_id,
127-
&server,
128-
cluster.chain,
129-
),
130-
&masquerader,
131-
real_node.main_public_key(),
132-
real_node.socket_addr(PortSelector::First),
133-
)
134-
.unwrap();
135-
server.wait_for_chunk(Duration::from_secs(2)).unwrap();
136-
server.send_chunk(HTTP_RESPONSE);
137-
mock_node
138-
.wait_for_package(&masquerader, Duration::from_secs(2))
139-
.unwrap();
119+
let index: u64 = 0;
120+
request_server_payload(
121+
index,
122+
&cluster,
123+
&real_node,
124+
&mock_node,
125+
&mut server,
126+
&masquerader,
127+
stream_key,
128+
return_route_id,
129+
);
130+
let index: u64 = 1;
131+
request_server_payload(
132+
index,
133+
&cluster,
134+
&real_node,
135+
&mock_node,
136+
&mut server,
137+
&masquerader,
138+
stream_key,
139+
return_route_id,
140+
);
140141

141142
server.shutdown();
142143

@@ -165,6 +166,40 @@ fn actual_server_drop() {
165166
assert!(payload.sequenced_packet.last_data);
166167
}
167168

169+
fn request_server_payload(
170+
index: u64,
171+
cluster: &MASQNodeCluster,
172+
real_node: &MASQRealNode,
173+
mock_node: &MASQMockNode,
174+
server: &mut MASQNodeServer,
175+
masquerader: &JsonMasquerader,
176+
stream_key: StreamKey,
177+
return_route_id: u32,
178+
) {
179+
mock_node
180+
.transmit_package(
181+
mock_node.port_list()[0],
182+
create_request_icp(
183+
index,
184+
&mock_node,
185+
&real_node,
186+
stream_key,
187+
return_route_id,
188+
&server,
189+
cluster.chain,
190+
),
191+
masquerader,
192+
real_node.main_public_key(),
193+
real_node.socket_addr(PortSelector::First),
194+
)
195+
.unwrap();
196+
server.wait_for_chunk(Duration::from_secs(2)).unwrap();
197+
server.send_chunk(HTTP_RESPONSE);
198+
mock_node
199+
.wait_for_package(masquerader, Duration::from_secs(2))
200+
.unwrap();
201+
}
202+
168203
#[test]
169204
// Given: Exit Node is real_node; originating Node is mock_node.
170205
// Given: A stream is established through the exit Node to a server.
@@ -178,10 +213,12 @@ fn reported_client_drop() {
178213
let mut server = real_node.make_server(server_port);
179214
let masquerader = JsonMasquerader::new();
180215
let (stream_key, return_route_id) = arbitrary_context();
216+
let index: u64 = 0;
181217
mock_node
182218
.transmit_package(
183219
mock_node.port_list()[0],
184220
create_request_icp(
221+
index,
185222
&mock_node,
186223
&real_node,
187224
stream_key,
@@ -309,6 +346,7 @@ fn arbitrary_context() -> (StreamKey, u32) {
309346
}
310347

311348
fn create_request_icp(
349+
index: u64,
312350
originating_node: &MASQMockNode,
313351
exit_node: &MASQRealNode,
314352
stream_key: StreamKey,
@@ -343,7 +381,7 @@ fn create_request_icp(
343381
&node_lib::sub_lib::migrations::client_request_payload::MIGRATIONS,
344382
&ClientRequestPayload_0v1 {
345383
stream_key,
346-
sequenced_packet: SequencedPacket::new(Vec::from(HTTP_REQUEST), 0, false),
384+
sequenced_packet: SequencedPacket::new(Vec::from(HTTP_REQUEST), index, false),
347385
target_hostname: Some(format!("{}", server.local_addr().ip())),
348386
target_port: server.local_addr().port(),
349387
protocol: ProxyProtocol::HTTP,

node/src/accountant/db_access_objects/utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use rusqlite::{Row, Statement, ToSql};
1717
use std::fmt::{Debug, Display};
1818
use std::iter::FlatMap;
1919
use std::path::{Path, PathBuf};
20+
use std::string::ToString;
2021
use std::time::Duration;
2122
use std::time::SystemTime;
2223

node/src/accountant/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4523,7 +4523,6 @@ mod tests {
45234523
let factory = Accountant::dao_factory(data_dir);
45244524
factory.make();
45254525
};
4526-
45274526
assert_on_initialization_with_panic_on_migration(&data_dir, &act);
45284527
}
45294528
}

0 commit comments

Comments
 (0)