Added more tests back in.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s

This commit is contained in:
Jeff Baskin 2025-10-16 13:53:04 -04:00
parent 922d88b177
commit 7674734021

View File

@ -3847,6 +3847,7 @@ impl Oid {
} }
} }
#[derive(Debug)]
struct Index { struct Index {
data: HashMap<Field, HashSet<Oid>>, data: HashMap<Field, HashSet<Oid>>,
unique: bool, unique: bool,
@ -3867,6 +3868,18 @@ impl Index {
} }
} }
fn internal_add(&mut self, field: &Field, oid: Oid) {
let storage = match self.data.get_mut(field) {
Some(data) => data,
None => {
let data = HashSet::new();
self.data.insert(field.clone(), data);
self.data.get_mut(field).unwrap()
}
};
storage.insert(oid);
}
fn add(&mut self, field: Field, oid: Oid) -> Result<(), MTTError> { fn add(&mut self, field: Field, oid: Oid) -> Result<(), MTTError> {
let oids = match self.data.get_mut(&field) { let oids = match self.data.get_mut(&field) {
Some(data) => data, Some(data) => data,
@ -3952,7 +3965,9 @@ impl Indexes {
} }
fn pull(&self, field_id: &Uuid, calc: &Calculation) -> HashSet<Oid> { fn pull(&self, field_id: &Uuid, calc: &Calculation) -> HashSet<Oid> {
self.get_index(field_id).pull(calc) println!("{:?}", field_id);
println!("{:?}", self.data);
self.data.get(field_id).unwrap().pull(calc)
} }
fn add_to_index(&mut self, field_name: &Uuid, field: Field, oid: Oid) { fn add_to_index(&mut self, field_name: &Uuid, field: Field, oid: Oid) {
@ -3981,6 +3996,10 @@ impl Indexes {
} }
Ok(()) Ok(())
} }
fn iter_mut(&mut self) -> impl Iterator<Item = (&Uuid, &mut Index)> {
self.data.iter_mut()
}
} }
#[cfg(test)] #[cfg(test)]
@ -4285,7 +4304,11 @@ impl DocumentFile {
while self.docs.contains_key(&oid) { while self.docs.contains_key(&oid) {
oid = Oid::new(); oid = Oid::new();
} }
self.docs.insert(oid, holder.clone()); self.docs.insert(oid.clone(), holder.clone());
for (field_id, oids) in self.indexes.iter_mut() {
let value = holder.get(field_id).unwrap();
oids.internal_add(value, oid.clone());
}
records.insert(holder); records.insert(holder);
} }
records.into() records.into()
@ -4420,6 +4443,7 @@ impl DocumentFile {
let mut oids: HashSet<Oid> = self.docs.keys().cloned().collect(); let mut oids: HashSet<Oid> = self.docs.keys().cloned().collect();
for (field_id, calculation) in indexed.iter() { for (field_id, calculation) in indexed.iter() {
let holder = self.indexes.pull(field_id, calculation); let holder = self.indexes.pull(field_id, calculation);
println!("{:?}", holder);
oids = oids.intersection(&holder).cloned().collect(); oids = oids.intersection(&holder).cloned().collect();
} }
for (field_id, calculation) in unindexed.iter() { for (field_id, calculation) in unindexed.iter() {
@ -4863,37 +4887,36 @@ mod document_files {
} }
} }
/*
#[test] #[test]
fn gets_all_documents_in_query() { fn gets_all_documents_in_query() {
let mut doc = TestDocument::new([FieldType::Integer].to_vec()); let mut test_doc = TestDocument::new([FieldType::Integer].to_vec());
doc.start(); test_doc.start();
let values = [ let queue = test_doc.get_queue();
[1.into()].to_vec(), let data = 1;
[2.into()].to_vec(), let count = 5;
[1.into()].to_vec(), for i in 0..count {
[3.into()].to_vec(), let holder: i128 = (i + 5).try_into().unwrap();
[1.into()].to_vec(), test_doc.populate([holder.into()].to_vec());
[4.into()].to_vec(), test_doc.populate([data.into()].to_vec());
[1.into()].to_vec(),
[5.into()].to_vec(),
];
for value in values.iter() {
doc.populate(value.clone());
} }
let mut calc = Calculation::new(Operand::Equal); let mut calc = Calculation::new(Operand::Equal);
calc.add_value(1); calc.add_value(data.clone());
let mut query = Query::new(); let mut query = Query::new();
query.add("field0".to_string(), calc); query.add(Name::english("field0".to_string()), calc);
doc.send(query).unwrap(); queue.send(Message::new(test_doc.get_docdef().get_document_name(), query));
let result = doc.get_receiver().recv_timeout(TIMEOUT).unwrap(); let result = test_doc.get_receiver().recv_timeout(TIMEOUT).unwrap();
let action = result.get_action(); let action = result.get_action();
let input: Field = 1.into();
match action { match action {
MsgAction::Reply(data) => { MsgAction::Records(docs) => {
assert_eq!(data.len(), 4, "should return 4 entries"); assert_eq!(
for doc in data.iter() { docs.len(),
assert_eq!(doc.get_field("field0").unwrap(), input); count,
"should return one entry containing {:?} got:\n{:?}",
data,
action
);
for doc in docs.clone() {
assert_eq!(doc.get(&Name::english("field0".to_string())).unwrap(), data.into());
} }
} }
_ => unreachable!("got {:?}: should have been a reply", action), _ => unreachable!("got {:?}: should have been a reply", action),
@ -4917,21 +4940,21 @@ mod document_files {
let mut query = Query::new(); let mut query = Query::new();
let mut calc = Calculation::new(Operand::Equal); let mut calc = Calculation::new(Operand::Equal);
calc.add_value("a"); calc.add_value("a");
query.add("field0".to_string(), calc); query.add(Name::english("field0".to_string()), calc);
let mut calc = Calculation::new(Operand::Equal); let mut calc = Calculation::new(Operand::Equal);
calc.add_value("b"); calc.add_value("b");
query.add("field1".to_string(), calc); query.add(Name::english("field1".to_string()), calc);
doc.send(query).unwrap(); doc.send(query).unwrap();
let result = doc.get_receiver().recv_timeout(TIMEOUT).unwrap(); let result = doc.get_receiver().recv_timeout(TIMEOUT).unwrap();
let action = result.get_action(); let action = result.get_action();
match action { match action {
MsgAction::Reply(data) => { MsgAction::Records(data) => {
let afield: Field = "a".into(); let afield: Field = "a".into();
let bfield: Field = "b".into(); let bfield: Field = "b".into();
assert_eq!(data.len(), 1, "should return one entry:\n{:?}", action); assert_eq!(data.len(), 1, "should return one entry:\n{:?}", action);
for doc in data.iter() { for doc in data.clone() {
assert_eq!(doc.get_field("field0").unwrap(), afield); assert_eq!(doc.get(&Name::english("field0".to_string())).unwrap(), afield);
assert_eq!(doc.get_field("field1").unwrap(), bfield); assert_eq!(doc.get(&Name::english("field1".to_string())).unwrap(), bfield);
} }
} }
_ => unreachable!("got {:?}: should have been a reply", action), _ => unreachable!("got {:?}: should have been a reply", action),
@ -4943,8 +4966,8 @@ mod document_files {
let mut doc = let mut doc =
TestDocument::new([FieldType::StaticString, FieldType::StaticString].to_vec()); TestDocument::new([FieldType::StaticString, FieldType::StaticString].to_vec());
let docdef = doc.get_docdef_mut(); let docdef = doc.get_docdef_mut();
docdef.add_index("field0".to_string(), IndexType::Index); docdef.add_index(&Name::english("field0".to_string()), IndexType::Index);
docdef.add_index("field1".to_string(), IndexType::Index); docdef.add_index(&Name::english("field1".to_string()), IndexType::Index);
doc.start(); doc.start();
let values = [ let values = [
["a".into(), "a".into()].to_vec(), ["a".into(), "a".into()].to_vec(),
@ -4958,27 +4981,28 @@ mod document_files {
let mut query = Query::new(); let mut query = Query::new();
let mut calc = Calculation::new(Operand::Equal); let mut calc = Calculation::new(Operand::Equal);
calc.add_value("a"); calc.add_value("a");
query.add("field0".to_string(), calc); query.add(Name::english("field0".to_string()), calc);
let mut calc = Calculation::new(Operand::Equal); let mut calc = Calculation::new(Operand::Equal);
calc.add_value("b"); calc.add_value("b");
query.add("field1".to_string(), calc); query.add(Name::english("field1".to_string()), calc);
doc.send(query).unwrap(); doc.send(query).unwrap();
let result = doc.get_receiver().recv_timeout(TIMEOUT).unwrap(); let result = doc.get_receiver().recv_timeout(TIMEOUT).unwrap();
let action = result.get_action(); let action = result.get_action();
match action { match action {
MsgAction::Reply(data) => { MsgAction::Records(data) => {
let afield: Field = "a".into(); let afield: Field = "a".into();
let bfield: Field = "b".into(); let bfield: Field = "b".into();
assert_eq!(data.len(), 1, "should return one entry:\n{:?}", action); assert_eq!(data.len(), 1, "should return one entry:\n{:?}", action);
for doc in data.iter() { for doc in data.clone() {
assert_eq!(doc.get_field("field0").unwrap(), afield); assert_eq!(doc.get(&Name::english("field0".to_string())).unwrap(), afield);
assert_eq!(doc.get_field("field1").unwrap(), bfield); assert_eq!(doc.get(&Name::english("field1".to_string())).unwrap(), bfield);
} }
} }
_ => unreachable!("got {:?}: should have been a reply", action), _ => unreachable!("got {:?}: should have been a reply", action),
} }
} }
/*
#[test] #[test]
fn query_should_work_with_mixed_inexed_fields() { fn query_should_work_with_mixed_inexed_fields() {
let mut doc = let mut doc =