-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
106 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,4 @@ scan_dir = "0.2.0" | |
time = "0.1.32" | ||
rand = "0.3.11" | ||
libc = "0.1.10" | ||
matches = "0.1.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use time::SteadyTime; | ||
|
||
|
||
#[derive(PartialEq, Eq, Debug)] | ||
pub enum Action { | ||
LeaderPing, | ||
} | ||
|
||
#[derive(PartialEq, Eq, Debug)] | ||
pub struct ActionList { | ||
pub next_wakeup: SteadyTime, | ||
pub action: Option<Action>, | ||
} | ||
|
||
impl Action { | ||
pub fn and_wait(self, time: SteadyTime) -> ActionList { | ||
ActionList { | ||
next_wakeup: time, | ||
action: Some(self), | ||
} | ||
} | ||
pub fn wait(time: SteadyTime) -> ActionList { | ||
ActionList { | ||
next_wakeup: time, | ||
action: None, | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//! Tests for the case of single node | ||
//! | ||
use time::SteadyTime; | ||
|
||
use super::{Node, Machine}; | ||
use super::action::Action; | ||
use super::test_util::TimeScale; | ||
|
||
|
||
#[test] | ||
fn test_starting() { | ||
let mut scale = TimeScale::new(); | ||
let node = Node::new("one", scale.now()); | ||
assert!(matches!(node.machine, Machine::Starting { .. })); | ||
} | ||
|
||
#[test] | ||
fn test_alone() { | ||
let mut scale = TimeScale::new(); | ||
let node = Node::new("one", scale.now()); | ||
assert!(matches!(node.machine, Machine::Starting { .. })); | ||
scale.advance_ms(100); // Small time, just continue starting | ||
let (node, act) = node.time_passed(scale.now()); | ||
assert!(matches!(node.machine, Machine::Starting { .. })); | ||
assert!(act.action == None); | ||
scale.advance_ms(10000); // Large timeout, should already become a leader | ||
let (node, act) = node.time_passed(scale.now()); | ||
assert!(matches!(node.machine, Machine::Leader { .. })); | ||
assert!(act.action == Some(Action::LeaderPing)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters