Skip to content

Commit

Permalink
Fix CI Tests (#530)
Browse files Browse the repository at this point in the history
* FIX-CI: Many attempts to resolve macOS node_exits_from_future_panic_integration test failure.
  • Loading branch information
substratumservices authored Sep 3, 2019
1 parent 1d58070 commit a292d46
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 55 deletions.
35 changes: 19 additions & 16 deletions node-ui/test/main_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ describe('After application launch: ', function () {
await client.waitUntil(async () => (await client.getText('#node-status-label')) === 'Serving')
assert.strictEqual((await client.getText('#node-status-label')), 'Serving')
printConsoleForDebugging(client, false)
assert.notStrictEqual(await client.getText('#node-descriptor'), '')
await client.waitUntil(async () => (await client.getText('#node-descriptor')) !== '')

await indexPage.off.click()
assert.strictEqual(await uiInterface.verifyNodeDown(10000), true)
Expand Down Expand Up @@ -159,10 +159,10 @@ describe('After application launch: ', function () {
await client.waitUntilWindowLoaded()

assert.strictEqual(await uiInterface.verifyNodeUp(10000), true)
await client.waitUntil(async () => (await client.getText('#node-status-label')) === 'Serving')
assert.strictEqual((await client.getText('#node-status-label')), 'Serving')

await client.waitUntilTextExists('#node-status-label', 'Serving')
printConsoleForDebugging(client, false)
assert.notStrictEqual(await client.getText('#node-descriptor'), '')
await client.waitUntil(async () => (await indexPage.nodeDescriptor.getText()) !== '')

await indexPage.settingsButton.click()
await indexPage.networkSettings.click()
Expand All @@ -171,7 +171,7 @@ describe('After application launch: ', function () {
client.element('#cancel').click()
await client.waitUntilWindowLoaded()

assert.notStrictEqual(await client.getText('#node-descriptor'), '')
await client.waitUntil(async () => (await client.getText('#node-descriptor')) !== '')

await indexPage.off.click()
assert.strictEqual(await uiInterface.verifyNodeDown(10000), true)
Expand All @@ -187,26 +187,25 @@ describe('After application launch: ', function () {
await configComponent.blockchainServiceUrl.setValue('https://127.0.0.1')
await client.waitUntil(() => configComponent.saveConfig.isEnabled())
client.element('#save-config').click()
await client.waitUntilWindowLoaded()

await indexPage.serving.click()
await client.waitUntil(async () => (await client.getText('#node-status-label')) === 'Serving')
await client.waitUntilTextExists('#node-status-label', 'Serving')
assert.strictEqual(await uiInterface.verifyNodeUp(10000), true)

printConsoleForDebugging(client, false)
assert.notStrictEqual(await client.getText('#node-descriptor'), '')
await client.waitUntil(async () => (await client.getText('#node-descriptor')) !== '')

await indexPage.off.click()
assert.strictEqual(await uiInterface.verifyNodeDown(10000), true)
await client.waitUntil(async () => (await client.getText('#node-status-label')) === 'Off')

await client.waitUntilTextExists('#node-status-label', 'Off')

await indexPage.serving.click()

await client.waitUntilWindowLoaded()
await client.waitUntil(async () => (await client.getText('#node-status-label')) === 'Serving')
await client.waitUntilTextExists('#node-status-label', 'Serving')
assert.strictEqual(await uiInterface.verifyNodeUp(10000), true)
printConsoleForDebugging(client, false)
assert.notStrictEqual(await client.getText('#node-descriptor'), '')
await client.waitUntil(async () => (await client.getText('#node-descriptor')) !== '')

await indexPage.off.click()
})
Expand All @@ -226,10 +225,10 @@ describe('After application launch: ', function () {
client.element('#save-config').click()
await client.waitUntilWindowLoaded()

await client.waitUntil(async () => (await client.getText('#node-status-label')) === 'Serving')
await client.waitUntilTextExists('#node-status-label', 'Serving')
assert.strictEqual(await uiInterface.verifyNodeUp(10000), true)
printConsoleForDebugging(client, false)
assert.notStrictEqual(await client.getText('#node-descriptor'), '')
await client.waitUntil(async () => (await indexPage.nodeDescriptor.getText()) !== '')

await indexPage.settingsButton.click()
await indexPage.openSettings.click()
Expand All @@ -238,10 +237,10 @@ describe('After application launch: ', function () {
client.element('#save-config').click()
await client.waitUntilWindowLoaded()

await client.waitUntil(async () => (await client.getText('#node-status-label')) === 'Off')
await client.waitUntilTextExists('#node-status-label', 'Off')
assert.strictEqual(await uiInterface.verifyNodeDown(10000), true)
printConsoleForDebugging(client, false)
assert.strictEqual(await client.getText('#node-descriptor'), '')
await client.waitUntil(async () => (await indexPage.nodeDescriptor.getText()) === '')
})
})

Expand Down Expand Up @@ -282,6 +281,10 @@ class IndexPage {
get networkSettings () {
return this.client.element('#network-settings-menu')
}

get nodeDescriptor () {
return this.client.element('#node-descriptor')
}
}

class ConfigComponent {
Expand Down
19 changes: 17 additions & 2 deletions node/src/accountant/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use futures::future::Future;
use lazy_static::lazy_static;
use payable_dao::PayableDao;
use receivable_dao::ReceivableDao;
use std::thread;
use std::time::{Duration, SystemTime};

pub const DEFAULT_PAYABLE_SCAN_INTERVAL: u64 = 3600; // one hour
Expand Down Expand Up @@ -379,7 +380,14 @@ impl Accountant {
warning!(future_logger, "{}", e);
Ok(())
}
Err(e) => panic!("Unable to send ReportAccountsPayable: {}", e),
Err(e) => {
error!(
future_logger,
"Unable to send ReportAccountsPayable: {:?}", e
);
thread::sleep(Duration::from_secs(1));
panic!("Unable to send ReportAccountsPayable: {:?}", e);
}
});
actix::spawn(future);
}
Expand Down Expand Up @@ -458,7 +466,14 @@ impl Accountant {
);
Err(())
}
_ => unimplemented!(),
Err(e) => {
error!(
future_logger,
"Unable to send to Blockchain Bridge: {:?}", e
);
thread::sleep(Duration::from_secs(1));
panic!("Unable to send to Blockchain Bridge: {:?}", e);
}
});
actix::spawn(future);
}
Expand Down
5 changes: 2 additions & 3 deletions node/src/run_modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ fn run_the_node(args: &Vec<String>, streams: &mut StdStreams<'_>) -> i32 {
server_initializer.go(streams, args);

actix::spawn(server_initializer.map_err(|_| {
System::current().stop();
System::current().stop_with_code(1);
}));

system.run();
1
system.run()
}

fn generate_wallet(args: &Vec<String>, streams: &mut StdStreams<'_>) -> i32 {
Expand Down
6 changes: 3 additions & 3 deletions node/src/server_initializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl LoggerInitializerWrapper for LoggerInitializerWrapperReal {
fn init(&mut self, file_path: PathBuf, real_user: &RealUser, log_level: LevelFilter) {
Logger::with(LogSpecification::default(log_level).finalize())
.log_to_file()
.directory(&file_path.to_str().expect("Bad logfile directory")[..])
.directory(file_path.clone())
.print_message()
.duplicate_to_stderr(Duplicate::Info)
.suppress_timestamp()
Expand All @@ -114,8 +114,8 @@ impl LoggerInitializerWrapper for LoggerInitializerWrapperReal {
)
.start()
.expect("Logging subsystem failed to start");
let logfile_name = file_path.join("SubstratumNode_rCURRENT.log");
let privilege_dropper = PrivilegeDropperReal::new();
let logfile_name = file_path.join("SubstratumNode_rCURRENT.log");
privilege_dropper.chown(&logfile_name, real_user);
std::panic::set_hook(Box::new(|panic_info| {
panic_hook(AltPanicInfo::from(panic_info))
Expand Down Expand Up @@ -159,7 +159,6 @@ impl<'a> From<&'a PanicInfo<'a>> for AltPanicInfo<'a> {
}

fn panic_hook(panic_info: AltPanicInfo) {
let logger = sub_lib::logger::Logger::new("PanicHandler");
let location = match panic_info.location {
None => "<unknown location>".to_string(),
Some(location) => format!("{}:{}:{}", location.file, location.line, location.col),
Expand All @@ -171,6 +170,7 @@ fn panic_hook(panic_info: AltPanicInfo) {
} else {
"<message indecipherable>".to_string()
};
let logger = sub_lib::logger::Logger::new("PanicHandler");
error!(logger, "{} - {}", location, message);
let backtrace = Backtrace::new();
error!(logger, "{:?}", backtrace);
Expand Down
2 changes: 1 addition & 1 deletion node/tests/configuration_mode_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2017-2019, Substratum LLC (https://substratum.net) and/or its affiliates. All rights reserved.

mod utils;
pub mod utils;

use bip39::{Language, Mnemonic, Seed};
use node_lib::blockchain::bip32::Bip32ECKeyPair;
Expand Down
2 changes: 1 addition & 1 deletion node/tests/dns_resolve_failure_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2017-2019, Substratum LLC (https://substratum.net) and/or its affiliates. All rights reserved.

mod utils;
pub mod utils;

use node_lib::test_utils::{assert_string_contains, read_until_timeout};
use std::io::Write;
Expand Down
2 changes: 1 addition & 1 deletion node/tests/dns_round_trip_test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2017-2019, Substratum LLC (https://substratum.net) and/or its affiliates. All rights reserved.
mod utils;
pub mod utils;
use node_lib::entry_dns::packet_facade::PacketFacade;
use serial_test_derive::serial;
use std::net::UdpSocket;
Expand Down
2 changes: 1 addition & 1 deletion node/tests/http_through_node_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2017-2019, Substratum LLC (https://substratum.net) and/or its affiliates. All rights reserved.

mod utils;
pub mod utils;

use node_lib::test_utils::read_until_timeout;
use std::io::Write;
Expand Down
2 changes: 1 addition & 1 deletion node/tests/initialization_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2017-2019, Substratum LLC (https://substratum.net) and/or its affiliates. All rights reserved.

mod utils;
pub mod utils;

use node_lib::database::db_initializer::DATABASE_FILE;
use utils::CommandConfig;
Expand Down
2 changes: 1 addition & 1 deletion node/tests/node_exits_from_future_error_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2017-2019, Substratum LLC (https://substratum.net) and/or its affiliates. All rights reserved.

mod utils;
pub mod utils;

use crate::utils::CommandConfig;

Expand Down
39 changes: 17 additions & 22 deletions node/tests/node_exits_from_future_panic_test.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,28 @@
// Copyright (c) 2017-2019, Substratum LLC (https://substratum.net) and/or its affiliates. All rights reserved.

mod utils;
pub mod utils;

use crate::utils::CommandConfig;
use std::path::Path;
#[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;

#[cfg(not(target_os = "windows"))]
#[test]
fn node_exits_from_future_panic_integration() {
let panic_config = CommandConfig::new().pair("--crash-point", "panic");
let mut node = utils::SubstratumNode::start_standard(Some(panic_config));

let exit_code = node.wait_for_exit().unwrap().status.code();
assert_eq!(Some(101), exit_code);
}

#[cfg(target_os = "windows")]
#[test]
fn node_exits_from_future_panic_integration() {
let _ = remove_logfile();
let panic_config = CommandConfig::new().pair("--crash-point", "panic");
let mut node = utils::SubstratumNode::start_standard(Some(panic_config));

let exit_code = node.wait_for_exit().unwrap().status.code();
// Sometimes 1, sometimes 101
assert_ne!(exit_code, Some(0));
let success = node.wait_for_exit().unwrap().status.success();
assert!(!success, "Did not fail as expected");
}

#[test]
fn node_logs_panic_integration() {
let _ = remove_logfile();
let panic_config = CommandConfig::new().pair("--crash-point", "panic");
let mut node = utils::SubstratumNode::start_standard(Some(panic_config));

Expand All @@ -48,12 +38,7 @@ const STAT_FORMAT_PARAM_NAME: &str = "-f";
#[cfg(not(target_os = "windows"))]
#[test]
fn node_logfile_does_not_belong_to_root_integration() {
let logfile_path = utils::SubstratumNode::path_to_logfile();
match std::fs::remove_file(&logfile_path) {
Ok(_) => (),
Err(ref e) if e.kind() == std::io::ErrorKind::NotFound => (),
Err(ref e) => panic!("{:?}", e),
}
let logfile_path = remove_logfile();

let mut node = utils::SubstratumNode::start_standard(None);

Expand Down Expand Up @@ -85,3 +70,13 @@ fn node_logfile_does_not_belong_to_root_integration() {
&output
);
}

fn remove_logfile() -> Box<Path> {
let logfile_path = utils::SubstratumNode::path_to_logfile();
match std::fs::remove_file(&logfile_path) {
Ok(_) => (),
Err(ref e) if e.kind() == std::io::ErrorKind::NotFound => (),
Err(ref e) => panic!("{:?}", e),
}
logfile_path
}
2 changes: 1 addition & 1 deletion node/tests/tls_through_node_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2017-2019, Substratum LLC (https://substratum.net) and/or its affiliates. All rights reserved.

mod utils;
pub mod utils;

use native_tls::HandshakeError;
use native_tls::TlsConnector;
Expand Down
2 changes: 1 addition & 1 deletion node/tests/ui_gateway_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2017-2018, Substratum LLC (https://substratum.net) and/or its affiliates. All rights reserved.

mod utils;
pub mod utils;

use futures::future::*;
use node_lib::sub_lib::ui_gateway::DEFAULT_UI_PORT;
Expand Down
5 changes: 4 additions & 1 deletion node/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ impl Drop for SubstratumNode {

impl SubstratumNode {
pub fn data_dir() -> Box<Path> {
env::temp_dir().into_boxed_path()
let cur_dir = env::current_dir().unwrap();
let generated_dir = cur_dir.join(Path::new("generated"));
generated_dir.into_boxed_path()
}

pub fn path_to_logfile() -> Box<Path> {
Expand All @@ -67,6 +69,7 @@ impl SubstratumNode {
#[allow(dead_code)]
pub fn start_standard(config: Option<CommandConfig>) -> SubstratumNode {
let mut command = SubstratumNode::make_node_command(config);
eprintln!("{:?}", command);
let child = command.spawn().unwrap();
thread::sleep(Duration::from_millis(500)); // needs time to open logfile and sockets
SubstratumNode {
Expand Down

0 comments on commit a292d46

Please sign in to comment.