-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathstartup_test.rs
90 lines (72 loc) · 2.54 KB
/
startup_test.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
mod util;
use dura::config::Config;
use dura::database::RuntimeLock;
use std::fs;
/// How many seconds to wait, at most, for dura to start?
const START_TIMEOUT: u64 = 8;
#[test]
fn start_serve() {
let mut dura = util::dura::Dura::new();
assert_eq!(None, dura.pid(true));
assert_eq!(None, dura.get_runtime_lock());
dura.start_async(&["serve"], true);
dura.primary
.as_ref()
.map(|d| d.read_line(START_TIMEOUT).unwrap());
assert_ne!(None, dura.pid(true));
let runtime_lock = dura.get_runtime_lock();
assert_ne!(None, runtime_lock);
assert_eq!(dura.pid(true), runtime_lock.unwrap().pid);
}
#[test]
fn start_serve_with_null_pid_in_config() {
let mut dura = util::dura::Dura::new();
let mut runtime_lock = RuntimeLock::empty();
runtime_lock.pid = None;
dura.save_runtime_lock(&runtime_lock);
assert_eq!(None, dura.pid(true));
assert_ne!(None, dura.get_runtime_lock());
dura.start_async(&["serve"], true);
dura.primary
.as_ref()
.map(|d| d.read_line(START_TIMEOUT).unwrap());
assert_ne!(None, dura.pid(true));
let runtime_lock = dura.get_runtime_lock();
assert_ne!(None, runtime_lock);
assert_eq!(dura.pid(true), runtime_lock.unwrap().pid);
}
#[test]
fn start_serve_with_other_pid_in_config() {
let mut dura = util::dura::Dura::new();
let mut runtime_lock = RuntimeLock::empty();
runtime_lock.pid = Some(12345);
dura.save_runtime_lock(&runtime_lock);
println!("db:: {:?}", dura.get_runtime_lock());
assert_eq!(None, dura.pid(true));
assert_ne!(None, dura.get_runtime_lock());
dura.start_async(&["serve"], true);
dura.primary
.as_ref()
.map(|d| d.read_line(START_TIMEOUT).unwrap());
assert_ne!(None, dura.pid(true));
let runtime_lock = dura.get_runtime_lock();
assert_ne!(None, runtime_lock);
assert_eq!(dura.pid(true), runtime_lock.unwrap().pid);
}
#[test]
fn start_serve_with_invalid_json() {
let mut dura = util::dura::Dura::new();
let runtime_lock_path = dura.runtime_lock_path();
Config::create_dir(runtime_lock_path.as_path());
fs::write(runtime_lock_path, "{\"pid\":34725").unwrap();
assert_eq!(None, dura.pid(true));
assert_eq!(None, dura.get_runtime_lock());
dura.start_async(&["serve"], true);
dura.primary
.as_ref()
.map(|d| d.read_line(START_TIMEOUT).unwrap());
assert_ne!(None, dura.pid(true));
let runtime_lock = dura.get_runtime_lock();
assert_ne!(None, runtime_lock);
assert_eq!(dura.pid(true), runtime_lock.unwrap().pid);
}