Added on_query response to query.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 2s
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 2s
This commit is contained in:
parent
830189a58d
commit
eb64b6bfd5
@ -64,6 +64,7 @@ impl From<MsgAction> for Action {
|
|||||||
MsgAction::Create(_) => Action::Create,
|
MsgAction::Create(_) => Action::Create,
|
||||||
MsgAction::Delete(_) => Action::Delete,
|
MsgAction::Delete(_) => Action::Delete,
|
||||||
MsgAction::Error(_) => Action::Error,
|
MsgAction::Error(_) => Action::Error,
|
||||||
|
MsgAction::OnQuery(_) => Action::OnQuery,
|
||||||
MsgAction::Query(_) => Action::Query,
|
MsgAction::Query(_) => Action::Query,
|
||||||
MsgAction::Records(_) => Action::Records,
|
MsgAction::Records(_) => Action::Records,
|
||||||
MsgAction::Register(_) => Action::Register,
|
MsgAction::Register(_) => Action::Register,
|
||||||
@ -128,6 +129,7 @@ enum MsgAction {
|
|||||||
// Alter
|
// Alter
|
||||||
// Remove
|
// Remove
|
||||||
Error(MTTError),
|
Error(MTTError),
|
||||||
|
OnQuery(Records),
|
||||||
Query(Query),
|
Query(Query),
|
||||||
Records(Records),
|
Records(Records),
|
||||||
Register(Register),
|
Register(Register),
|
||||||
@ -4674,7 +4676,10 @@ impl DocumentFile {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
let recs = Records::with_data(self.docdef.get_field_names().clone(), records);
|
let recs = Records::with_data(self.docdef.get_field_names().clone(), records);
|
||||||
self.queue.send(msg.response(recs)).unwrap();
|
self.queue.send(msg.response(recs.clone())).unwrap();
|
||||||
|
self.queue
|
||||||
|
.send(msg.response(MsgAction::OnQuery(recs)))
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, msg: &Message) {
|
fn update(&mut self, msg: &Message) {
|
||||||
@ -4801,6 +4806,21 @@ mod document_files {
|
|||||||
&self.rx
|
&self.rx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_name_id(&self) -> Uuid {
|
||||||
|
let reg_request = RegMsg::GetNameID(self.docdef.get_document_names()[0].clone());
|
||||||
|
let reg_msg = Register::new(self.get_sender_id(), reg_request);
|
||||||
|
let msg = Message::new(NameType::None, reg_msg);
|
||||||
|
self.queue.send(msg).unwrap();
|
||||||
|
let result = self.rx.recv().unwrap();
|
||||||
|
match result.get_action() {
|
||||||
|
MsgAction::Register(data) => match data.get_msg() {
|
||||||
|
RegMsg::DocumentNameID(output) => output.clone(),
|
||||||
|
_ => unreachable!("should return a name id"),
|
||||||
|
},
|
||||||
|
_ => unreachable!("should return a name id"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn get_sender_id(&self) -> Uuid {
|
fn get_sender_id(&self) -> Uuid {
|
||||||
self.sender_id.clone()
|
self.sender_id.clone()
|
||||||
}
|
}
|
||||||
@ -4968,7 +4988,6 @@ mod document_files {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[ignore]
|
|
||||||
fn query_sends_on_query_message() {
|
fn query_sends_on_query_message() {
|
||||||
let count = 5;
|
let count = 5;
|
||||||
let mut data: HashSet<Field> = HashSet::new();
|
let mut data: HashSet<Field> = HashSet::new();
|
||||||
@ -4978,6 +4997,7 @@ mod document_files {
|
|||||||
}
|
}
|
||||||
let mut test_doc = TestDocument::new([FieldType::Uuid].to_vec());
|
let mut test_doc = TestDocument::new([FieldType::Uuid].to_vec());
|
||||||
let doc_name = test_doc.get_docdef().get_document_names()[0].clone();
|
let doc_name = test_doc.get_docdef().get_document_names()[0].clone();
|
||||||
|
let queue = test_doc.get_queue();
|
||||||
let routes = [Path::new(
|
let routes = [Path::new(
|
||||||
Include::All,
|
Include::All,
|
||||||
Include::All,
|
Include::All,
|
||||||
@ -4985,11 +5005,37 @@ mod document_files {
|
|||||||
)]
|
)]
|
||||||
.to_vec();
|
.to_vec();
|
||||||
test_doc.start(routes);
|
test_doc.start(routes);
|
||||||
|
let name_id: NameType = test_doc.get_name_id().into();
|
||||||
for item in data.iter() {
|
for item in data.iter() {
|
||||||
test_doc.populate([item.clone()].to_vec());
|
test_doc.populate([item.clone()].to_vec());
|
||||||
}
|
}
|
||||||
test_doc.send(Query::new());
|
let msg = Message::new(doc_name.clone(), Query::new());
|
||||||
|
queue.send(msg.clone()).unwrap();
|
||||||
let result = test_doc.get_receiver().recv_timeout(TIMEOUT).unwrap();
|
let result = test_doc.get_receiver().recv_timeout(TIMEOUT).unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
result.get_message_id(),
|
||||||
|
msg.get_message_id(),
|
||||||
|
"message ids should match"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
result.get_document_id(),
|
||||||
|
&name_id,
|
||||||
|
"document name ids should match"
|
||||||
|
);
|
||||||
|
match result.get_action() {
|
||||||
|
MsgAction::OnQuery(output) => {
|
||||||
|
assert_eq!(
|
||||||
|
output.len(),
|
||||||
|
count,
|
||||||
|
"wrong number of entries: got {:?}",
|
||||||
|
output
|
||||||
|
);
|
||||||
|
for rec in output.iter() {
|
||||||
|
assert!(data.contains(&rec.get(Name::english("field0")).unwrap()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => unreachable!("should never get here"),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user