-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathstartup_shutdown_tests_integration.rs
162 lines (137 loc) · 5.17 KB
/
startup_shutdown_tests_integration.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// Copyright (c) 2019, MASQ (https://masq.ai) and/or its affiliates. All rights reserved.
use crate::utils::{DaemonProcess, MasqProcess};
use masq_lib::test_utils::utils::{
ensure_node_home_directory_exists, is_running_under_github_actions,
};
use masq_lib::utils::find_free_port;
use regex::Regex;
use std::thread;
use std::time::Duration;
mod utils;
#[test]
fn masq_without_daemon_integration() {
let masq_handle = MasqProcess::new().start_noninteractive(vec!["setup"]);
let (stdout, stderr, exit_code) = masq_handle.stop();
assert_eq!(&stdout, "", "{}", stdout);
assert!(
stderr.contains("Can't connect to Daemon or Node"),
"we got: {}",
stderr
);
assert_eq!(exit_code.unwrap(), 1);
}
#[test]
fn masq_terminates_immediately_after_clap_gets_furious_about_params_which_it_does_not_recognize_integration(
) {
let masq_handle = MasqProcess::new().start_noninteractive(vec!["uninvented-command"]);
let (stdout, stderr, exit_code) = masq_handle.stop();
assert_eq!(&stdout, "", "{}", stdout);
assert!(stderr.contains("Found argument 'uninvented-command' which wasn't expected, or isn't valid in this context"),
"we got: {}",
stderr
);
assert_eq!(exit_code.unwrap(), 1);
}
#[test]
fn masq_propagates_errors_related_to_default_terminal_integration() {
//the port is irrelevant; it hits the error before it gets to trying to connect to the Daemon
let masq_handle = MasqProcess::new().start_interactive(22222, false);
let (stdout, stderr, exit_code) = masq_handle.stop();
assert_eq!(exit_code.unwrap(), 1);
let regex = Regex::new(r"\x1B\[\?\d\d[lh]").unwrap();
assert_eq!(regex.replace_all(&stdout, ""), "", "{}", stdout);
#[cfg(not(target_os = "windows"))]
let expected_error_message = "Pre-configuration error: Preparing terminal interface:";
#[cfg(target_os = "windows")]
let expected_error_message = "Pre-configuration error: Local terminal recognition: ";
assert!(
stderr.contains(expected_error_message),
"unlike what we expected stderr was: {}",
stderr
);
}
#[test]
fn masq_terminates_based_on_loss_of_connection_to_the_daemon_integration() {
let dir_path = ensure_node_home_directory_exists(
"masq_integration_tests",
"masq_terminates_based_on_loss_of_connection_to_the_daemon_integration",
);
let port = find_free_port();
let daemon_handle = DaemonProcess::new().start(port);
let mut masq_handle = MasqProcess::new().start_interactive(port, true);
let mut stdin_handle = masq_handle.create_stdin_handle();
stdin_handle.type_command(&format!(
"setup --data-directory {}",
dir_path.to_str().unwrap()
));
thread::sleep(Duration::from_millis(300));
daemon_handle.kill();
let (stdout, stderr, exit_code) = masq_handle.stop();
#[cfg(not(target_os = "windows"))]
assert_eq!(exit_code, None);
#[cfg(target_os = "windows")]
assert_eq!(exit_code.unwrap(), 1);
assert!(stdout.contains("neighborhood-mode standard Default"));
assert_eq!(
stderr,
"\nThe Daemon is no longer running; masq is terminating.\n\n"
);
}
#[test]
fn handles_startup_and_shutdown_integration() {
if cfg!(windows) && is_running_under_github_actions() {
eprintln!("This test is not run in Actions under Windows, because it's flaky there.");
return;
}
let dir_path = ensure_node_home_directory_exists(
"masq_integration_tests",
"handles_startup_and_shutdown_integration",
);
let port = find_free_port();
let daemon_handle = DaemonProcess::new().start(port);
let masq_handle = MasqProcess::new().start_noninteractive(vec![
"--ui-port",
&port.to_string(),
"setup",
"--log-level",
"error",
"--neighborhood-mode",
"zero-hop",
"--data-directory",
dir_path.to_str().unwrap(),
"--blockchain-service-url",
"https://nonexistentblockchainservice.com",
]);
let (stdout, stderr, exit_code) = masq_handle.stop();
assert_eq!(&stderr, "", "setup phase: {}", stderr);
assert_eq!(
stdout.contains("neighborhood-mode zero-hop"),
true,
"{}",
stdout
);
assert_eq!(exit_code.unwrap(), 0);
let masq_handle =
MasqProcess::new().start_noninteractive(vec!["--ui-port", &port.to_string(), "start"]);
let (stdout, stderr, exit_code) = masq_handle.stop();
assert_eq!(&stderr, "", "start phase: {}", stderr);
assert_eq!(
stdout.contains("MASQNode successfully started in process"),
true,
"{}",
stdout
);
assert_eq!(exit_code.unwrap(), 0);
let masq_handle =
MasqProcess::new().start_noninteractive(vec!["--ui-port", &port.to_string(), "shutdown"]);
let (stdout, stderr, exit_code) = masq_handle.stop();
assert_eq!(&stderr, "", "shutdown phase: {}", stderr);
assert_eq!(
stdout.contains("MASQNode was instructed to shut down and has broken its connection"),
true,
"{}",
stdout
);
assert_eq!(exit_code.unwrap(), 0);
daemon_handle.kill();
}