-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A bunch of additional tests + Fixed an issue with the state machine h…
…anging in case the input is closed, but we're still waiting for entries to replay
- Loading branch information
1 parent
456ca9c
commit 747cd01
Showing
7 changed files
with
312 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
use super::*; | ||
|
||
use crate::service_protocol::messages::{ | ||
ErrorMessage, GetStateEntryMessage, InputEntryMessage, OneWayCallEntryMessage, StartMessage, | ||
}; | ||
use std::fmt; | ||
use test_log::test; | ||
|
||
#[test] | ||
fn got_closed_stream_before_end_of_replay() { | ||
let mut vm = CoreVM::mock_init(Version::V1); | ||
let encoder = Encoder::new(Version::V1); | ||
|
||
vm.notify_input( | ||
encoder | ||
.encode(&StartMessage { | ||
id: Bytes::from_static(b"123"), | ||
debug_id: "123".to_string(), | ||
// 2 expected entries! | ||
known_entries: 2, | ||
..Default::default() | ||
}) | ||
.to_vec(), | ||
); | ||
vm.notify_input(encoder.encode(&InputEntryMessage::default()).to_vec()); | ||
|
||
// Now notify input closed | ||
vm.notify_input_closed(); | ||
|
||
// Try to check if input is ready, this should fail | ||
assert_that!( | ||
vm.is_ready_to_execute(), | ||
err(eq_vm_error(vm::errors::INPUT_CLOSED_WHILE_WAITING_ENTRIES)) | ||
); | ||
|
||
let mut output = OutputIterator::collect_vm(&mut vm); | ||
assert_that!( | ||
output.next_decoded::<ErrorMessage>().unwrap(), | ||
error_message_as_vm_error(vm::errors::INPUT_CLOSED_WHILE_WAITING_ENTRIES) | ||
); | ||
assert_eq!(output.next(), None); | ||
} | ||
|
||
#[test] | ||
fn get_state_entry_mismatch() { | ||
test_entry_mismatch( | ||
GetStateEntryMessage { | ||
key: Bytes::from_static(b"my-key"), | ||
..Default::default() | ||
}, | ||
GetStateEntryMessage { | ||
key: Bytes::from_static(b"another-key"), | ||
..Default::default() | ||
}, | ||
|vm| vm.sys_get_state("another-key".to_owned()), | ||
); | ||
} | ||
|
||
#[test] | ||
fn one_way_call_entry_mismatch() { | ||
test_entry_mismatch( | ||
OneWayCallEntryMessage { | ||
service_name: "greeter".to_owned(), | ||
handler_name: "greet".to_owned(), | ||
key: "my-key".to_owned(), | ||
parameter: Bytes::from_static(b"123"), | ||
..Default::default() | ||
}, | ||
OneWayCallEntryMessage { | ||
service_name: "greeter".to_owned(), | ||
handler_name: "greet".to_owned(), | ||
key: "my-key".to_owned(), | ||
parameter: Bytes::from_static(b"456"), | ||
..Default::default() | ||
}, | ||
|vm| { | ||
vm.sys_send( | ||
Target { | ||
service: "greeter".to_owned(), | ||
handler: "greet".to_owned(), | ||
key: Some("my-key".to_owned()), | ||
}, | ||
b"456".to_vec(), | ||
None, | ||
) | ||
}, | ||
); | ||
} | ||
|
||
fn test_entry_mismatch<M: WriteableRestateMessage + Clone, T: fmt::Debug>( | ||
expected: M, | ||
actual: M, | ||
user_code: impl FnOnce(&mut CoreVM) -> Result<T, VMError>, | ||
) { | ||
let mut output = VMTestCase::new(Version::V1) | ||
.input(StartMessage { | ||
id: Bytes::from_static(b"123"), | ||
debug_id: "123".to_string(), | ||
known_entries: 2, | ||
partial_state: true, | ||
..Default::default() | ||
}) | ||
.input(InputEntryMessage { | ||
headers: vec![], | ||
value: Bytes::from_static(b"my-data"), | ||
..InputEntryMessage::default() | ||
}) | ||
.input(expected.clone()) | ||
.run(|vm| { | ||
vm.sys_input().unwrap(); | ||
|
||
assert_that!( | ||
user_code(vm), | ||
err(eq_vm_error( | ||
vm::errors::EntryMismatchError::new(expected.clone(), actual.clone(),).into() | ||
)) | ||
); | ||
}); | ||
|
||
assert_that!( | ||
output.next_decoded::<ErrorMessage>().unwrap(), | ||
error_message_as_vm_error(vm::errors::EntryMismatchError::new(expected, actual,).into()) | ||
); | ||
assert_eq!(output.next(), 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 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