-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathnode_exits_from_future_panic_test.rs
More file actions
105 lines (94 loc) · 3.13 KB
/
node_exits_from_future_panic_test.rs
File metadata and controls
105 lines (94 loc) · 3.13 KB
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
// Copyright (c) 2019, MASQ (https://masq.ai) and/or its affiliates. All rights reserved.
pub mod utils;
use crate::utils::CommandConfig;
use masq_lib::constants::DEFAULT_CHAIN;
use masq_lib::test_utils::utils::ensure_node_home_directory_exists;
use masq_lib::utils::add_chain_specific_directory;
use std::fs::create_dir_all;
#[cfg(not(target_os = "windows"))]
use std::process;
#[cfg(not(target_os = "windows"))]
use std::thread;
#[cfg(not(target_os = "windows"))]
use std::time::Duration;
use utils::MASQNode;
#[test]
fn node_exits_from_future_panic_integration() {
let panic_config = CommandConfig::new().pair("--crash-point", "panic");
let mut node = MASQNode::start_standard(
"node_exits_from_future_panic_integration",
Some(panic_config),
true,
true,
false,
false,
);
let success = node.wait_for_exit().unwrap().status.success();
assert!(!success, "Did not fail as expected");
}
#[test]
fn node_logs_panic_integration() {
let data_directory =
ensure_node_home_directory_exists("integration", "node_logs_panic_integration");
let data_dir_chain_path = add_chain_specific_directory(DEFAULT_CHAIN, &data_directory);
create_dir_all(&data_dir_chain_path).expect(
"Could not create chain directory inside node_logs_panic_integration home/MASQ directory",
);
let panic_config = CommandConfig::new()
.pair("--crash-point", "panic")
.pair("--chain", "polygon-mainnet")
.pair("--data-directory", data_directory.to_str().unwrap());
let mut node = MASQNode::start_standard(
"node_logs_panic_integration",
Some(panic_config),
true,
true,
false,
false,
);
node.wait_for_log("std::panicking::", Some(5000));
}
#[cfg(target_os = "linux")]
const STAT_FORMAT_PARAM_NAME: &str = "-c";
#[cfg(target_os = "macos")]
const STAT_FORMAT_PARAM_NAME: &str = "-f";
#[cfg(not(target_os = "windows"))]
#[test]
fn node_logfile_does_not_belong_to_root_integration() {
let mut node = MASQNode::start_standard(
"node_logfile_does_not_belong_to_root_integration",
Some(CommandConfig::new().pair("--chain", "polygon-amoy")),
true,
true,
false,
true,
);
let logfile_path = MASQNode::path_to_logfile(&node.data_dir);
thread::sleep(Duration::from_secs(2));
node.kill().unwrap();
let mut command = process::Command::new("stat");
command.args(vec![
STAT_FORMAT_PARAM_NAME,
"%u:%g",
logfile_path.display().to_string().as_str(),
]);
let output = command.output().unwrap();
let stdout = String::from_utf8(output.clone().stdout).unwrap();
let stderr = String::from_utf8(output.clone().stderr).unwrap();
assert_eq!(stderr, "".to_string());
let ids: Vec<&str> = stdout.split(":").into_iter().collect();
assert_ne!(
ids[0],
"0".to_string(),
"stat didn't say UID for {:?} was not 0: {:?}",
&logfile_path,
&output
);
assert_ne!(
ids[1],
"0".to_string(),
"stat didn't say GID for {:?} was not 0: {:?}",
&logfile_path,
&output
);
}