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:
parent
d85bddaa34
commit
8c73798f95
@ -5,6 +5,7 @@ pub enum Action {
|
||||
Addition,
|
||||
Create,
|
||||
Delete,
|
||||
DocumentCreated,
|
||||
Error,
|
||||
OnAddition,
|
||||
OnDelete,
|
||||
@ -24,6 +25,7 @@ impl From<MsgAction> for Action {
|
||||
MsgAction::Addition(_) => Action::Addition,
|
||||
MsgAction::Create(_) => Action::Create,
|
||||
MsgAction::Delete(_) => Action::Delete,
|
||||
MsgAction::DocumentCreated => Action::DocumentCreated,
|
||||
MsgAction::Error(_) => Action::Error,
|
||||
MsgAction::OnAddition(_) => Action::OnAddition,
|
||||
MsgAction::OnDelete(_) => Action::OnDelete,
|
||||
|
||||
@ -8,6 +8,7 @@ pub enum MsgAction {
|
||||
Addition(Addition),
|
||||
Create(DocDef),
|
||||
Delete(Delete),
|
||||
DocumentCreated,
|
||||
Error(MTTError),
|
||||
OnAddition(Records),
|
||||
OnDelete(Records),
|
||||
@ -27,6 +28,7 @@ impl MessageAction for MsgAction {
|
||||
Self::Addition(data) => data.doc_name(),
|
||||
Self::Create(data) => data.doc_name(),
|
||||
Self::Delete(data) => data.doc_name(),
|
||||
Self::DocumentCreated => &NameType::None,
|
||||
Self::Error(data) => data.doc_name(),
|
||||
Self::OnAddition(data) => data.doc_name(),
|
||||
Self::OnDelete(data) => data.doc_name(),
|
||||
@ -100,7 +102,6 @@ impl From<UserAction> for MsgAction {
|
||||
fn from(value: UserAction) -> Self {
|
||||
match value {
|
||||
UserAction::Addition(data) => Self::Addition(data),
|
||||
UserAction::CreateDocument(data) => Self::Create(data),
|
||||
UserAction::Query(data) => Self::Query(data),
|
||||
UserAction::Update(data) => Self::Update(data),
|
||||
}
|
||||
|
||||
@ -4,7 +4,6 @@ use crate::{message::MessageAction, name::NameType};
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum UserAction {
|
||||
Addition(Addition),
|
||||
CreateDocument(DocDef),
|
||||
Query(Query),
|
||||
Update(Update),
|
||||
}
|
||||
@ -15,12 +14,6 @@ impl From<Addition> for UserAction {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DocDef> for UserAction {
|
||||
fn from(value: DocDef) -> Self {
|
||||
Self::CreateDocument(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Query> for UserAction {
|
||||
fn from(value: Query) -> Self {
|
||||
Self::Query(value)
|
||||
@ -37,7 +30,6 @@ impl MessageAction for UserAction {
|
||||
fn doc_name(&self) -> &NameType {
|
||||
match self {
|
||||
Self::Addition(data) => data.doc_name(),
|
||||
Self::CreateDocument(data) => data.doc_name(),
|
||||
Self::Query(data) => data.doc_name(),
|
||||
Self::Update(data) => data.doc_name(),
|
||||
}
|
||||
|
||||
@ -106,7 +106,7 @@ mod createdocs {
|
||||
fn create_document_creation() {
|
||||
let doc_creator = TestCreateDoc::new();
|
||||
let paths = [
|
||||
Path::new(Include::All, Include::All, Include::Just(Action::Reply)),
|
||||
Path::new(Include::All, Include::All, Include::Just(Action::DocumentCreated)),
|
||||
Path::new(Include::All, Include::All, Include::Just(Action::Records)),
|
||||
]
|
||||
.to_vec();
|
||||
@ -124,7 +124,7 @@ mod createdocs {
|
||||
rx
|
||||
);
|
||||
match result1.get_action() {
|
||||
MsgAction::Reply(_) => {}
|
||||
MsgAction::DocumentCreated => {}
|
||||
_ => unreachable!("got {:?}: should have been a reply.", result1.get_action()),
|
||||
}
|
||||
let msg2 = Message::new(Query::new(name.clone()));
|
||||
@ -547,7 +547,7 @@ impl DocumentFile {
|
||||
spawn(move || {
|
||||
doc.listen();
|
||||
});
|
||||
let reply = msg.response(Reply::new(names[0].clone()));
|
||||
let reply = msg.response(MsgAction::DocumentCreated);
|
||||
queue.send(reply.clone());
|
||||
}
|
||||
|
||||
|
||||
@ -23,7 +23,7 @@ impl Session {
|
||||
names
|
||||
}
|
||||
|
||||
pub fn start(mut queue: Queue) {
|
||||
pub fn document_definition() -> DocDef {
|
||||
let mut docdef = DocDef::with_names(Self::doc_names());
|
||||
|
||||
let mut calc = Calculation::new(Operand::Add);
|
||||
@ -63,20 +63,6 @@ impl Session {
|
||||
let delete_func = DocFuncType::Trigger(delete.into());
|
||||
docdef.add_route(Clock::get_path(), delete_func);
|
||||
|
||||
let (tx, rx) = channel();
|
||||
let sender_id = queue.add_sender(tx);
|
||||
let msg = Message::new(docdef);
|
||||
let msg_id = msg.get_message_id().clone();
|
||||
let path = Path::new(
|
||||
Include::Just(msg_id),
|
||||
Include::All,
|
||||
Include::Just(Action::Reply),
|
||||
);
|
||||
let reg_msg = Register::new(sender_id.clone(), RegMsg::AddRoute(path));
|
||||
queue.send(msg.response(reg_msg));
|
||||
rx.recv().unwrap();
|
||||
queue.send(msg);
|
||||
rx.recv().unwrap();
|
||||
queue.remove_sender(&sender_id);
|
||||
docdef
|
||||
}
|
||||
}
|
||||
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@ pub enum ErrorID {
|
||||
NameAlreadyExists,
|
||||
NameLanguageNotUnique,
|
||||
NameNotFound,
|
||||
TimeOut,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
||||
10
tests/document_test.rs
Normal file
10
tests/document_test.rs
Normal file
@ -0,0 +1,10 @@
|
||||
use morethantext::{action::*, MoreThanText, TestMoreThanText};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[test]
|
||||
fn is_document_created() {
|
||||
let mut mtt = MoreThanText::new();
|
||||
let doc_name = TestMoreThanText::random_name();
|
||||
let docdef = DocDef::new(doc_name.clone());
|
||||
mtt.create_document(docdef).unwrap();
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
use morethantext::{
|
||||
action::{DocDef, FieldType, Query},
|
||||
ErrorID, MTTError, MoreThanText, Name,
|
||||
};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[test]
|
||||
fn errors_on_missing_page() {
|
||||
let mtt = MoreThanText::new();
|
||||
let doc_name = "missing";
|
||||
match mtt.get_document(doc_name, "something") {
|
||||
Ok(data) => assert!(false, "got '{}', should have been not found error", data),
|
||||
Err(err) => {
|
||||
let err_id = err.error_id();
|
||||
match err_id {
|
||||
ErrorID::DocumentNotFound => {}
|
||||
_ => unreachable!("got {:?}, should have been not found", err),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn can_create_document() {
|
||||
let mut mtt = MoreThanText::new();
|
||||
let doc_name = Name::english(Uuid::new_v4().to_string().as_str());
|
||||
let mut docdef = DocDef::new(doc_name.clone());
|
||||
let field_name = Name::english(Uuid::new_v4().to_string().as_str());
|
||||
docdef.add_field(field_name.clone(), FieldType::Uuid);
|
||||
mtt.records(docdef);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user