Corrected external add document issue.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s
This commit is contained in:
64
src/lib.rs
64
src/lib.rs
@@ -12,7 +12,10 @@ use queue::{
|
||||
data_director::{Include, Path, RegMsg, Register},
|
||||
router::Queue,
|
||||
};
|
||||
use std::sync::mpsc::{channel, Receiver};
|
||||
use std::{
|
||||
sync::mpsc::{channel, Receiver},
|
||||
time::Duration,
|
||||
};
|
||||
use uuid::Uuid;
|
||||
|
||||
pub use mtterror::{ErrorID, MTTError};
|
||||
@@ -25,6 +28,8 @@ mod support_tests {
|
||||
pub static TIMEOUT: Duration = Duration::from_millis(500);
|
||||
}
|
||||
|
||||
static TIMEOUT: Duration = Duration::from_secs(10);
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct MoreThanText {
|
||||
queue: Queue,
|
||||
@@ -33,10 +38,11 @@ pub struct MoreThanText {
|
||||
impl MoreThanText {
|
||||
pub fn new() -> Self {
|
||||
let queue = Queue::new();
|
||||
let mut output = Self { queue: queue.clone()};
|
||||
Clock::start(queue.clone());
|
||||
CreateDoc::start(queue.clone());
|
||||
Session::start(queue.clone());
|
||||
Self { queue: queue }
|
||||
output.create_document(Session::document_definition()).unwrap();
|
||||
output
|
||||
}
|
||||
|
||||
fn new_session() -> UserAction {
|
||||
@@ -110,13 +116,51 @@ impl MoreThanText {
|
||||
rx.recv().unwrap(); // Wait for completion.
|
||||
}
|
||||
self.queue.send(msg);
|
||||
let result = rx.recv().unwrap();
|
||||
let output = match rx.recv_timeout(TIMEOUT) {
|
||||
Ok(data) => match data.get_action() {
|
||||
MsgAction::Records(data) => Ok(data.clone()),
|
||||
MsgAction::Error(err) => Err(err.clone()),
|
||||
_ => unreachable!("should only receive records or errors")
|
||||
}
|
||||
Err(_) => Err(MTTError::new(NameType::None, ErrorID::TimeOut)),
|
||||
};
|
||||
self.queue.remove_sender(&sender_id);
|
||||
match result.get_action() {
|
||||
MsgAction::Records(data) => Ok(data.clone()),
|
||||
MsgAction::Error(err) => Err(err.clone()),
|
||||
_ => unreachable!("should only receive records or errors"),
|
||||
output
|
||||
}
|
||||
|
||||
pub fn create_document(&mut self, docdef: DocDef) -> Result<(), MTTError> {
|
||||
let (tx, rx) = channel();
|
||||
let sender_id = self.queue.add_sender(tx);
|
||||
let msg = Message::new(docdef);
|
||||
let msg_id = msg.get_message_id();
|
||||
let paths = [
|
||||
Path::new(
|
||||
Include::Just(msg_id.clone()),
|
||||
Include::All,
|
||||
Include::Just(Action::DocumentCreated),
|
||||
),
|
||||
Path::new(
|
||||
Include::Just(msg_id.clone()),
|
||||
Include::All,
|
||||
Include::Just(Action::Error),
|
||||
),
|
||||
];
|
||||
for path in paths.iter() {
|
||||
let reg_msg = Register::new(sender_id.clone(), RegMsg::AddRoute(path.clone()));
|
||||
self.queue.send(Message::new(reg_msg));
|
||||
rx.recv().unwrap(); // Wait for completion.
|
||||
}
|
||||
self.queue.send(msg);
|
||||
let output = match rx.recv_timeout(TIMEOUT) {
|
||||
Ok(data) => match data.get_action() {
|
||||
MsgAction::DocumentCreated => Ok(()),
|
||||
MsgAction::Error(err) => Err(err.clone()),
|
||||
_ => unreachable!("should only receive records or errors")
|
||||
}
|
||||
Err(_) => Err(MTTError::new(NameType::None, ErrorID::TimeOut)),
|
||||
};
|
||||
self.queue.remove_sender(&sender_id);
|
||||
output
|
||||
}
|
||||
|
||||
pub fn get_document(&self, name: &str, id: &str) -> Result<String, MTTError> {
|
||||
@@ -158,4 +202,8 @@ impl TestMoreThanText {
|
||||
let msg = Clock::gen_message();
|
||||
self.queue.send(msg);
|
||||
}
|
||||
|
||||
pub fn random_name() -> Name {
|
||||
Name::english(Uuid::new_v4().to_string().as_str())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user