Fixed FoundationDB tests.

This commit is contained in:
Mauro D 2023-07-07 10:53:14 +00:00
parent 6ba892f7d6
commit df3c34c656
5 changed files with 34 additions and 19 deletions

View file

@ -279,6 +279,7 @@ impl JMAP {
Ok(response)
}
#[allow(clippy::too_many_arguments)]
pub async fn copy_message(
&self,
from_account_id: u32,

View file

@ -105,7 +105,7 @@ impl JMAP {
.map_err(|_| MethodError::ServerPartialFail)?
.into_iter()
.next()
.map(|email| Value::Text(email))
.map(Value::Text)
.unwrap_or(Value::Null),
_ => Value::Null,
};

View file

@ -42,9 +42,9 @@ pub enum Event {
}
enum SimpleCron {
EveryDay { hour: u32, minute: u32 },
EveryWeek { day: u32, hour: u32, minute: u32 },
EveryHour { minute: u32 },
Day { hour: u32, minute: u32 },
Week { day: u32, hour: u32, minute: u32 },
Hour { minute: u32 },
}
const TASK_PURGE_DB: usize = 0;
@ -164,7 +164,7 @@ impl SimpleCron {
}
} else if pos == 1 {
if value.as_bytes().first().failed("parse cron weekday") == &b'*' {
return SimpleCron::EveryHour { minute };
return SimpleCron::Hour { minute };
} else {
hour = value.parse::<u32>().failed("parse cron hour");
if !(0..=23).contains(&hour) {
@ -173,7 +173,7 @@ impl SimpleCron {
}
} else if pos == 2 {
if value.as_bytes().first().failed("parse cron weekday") == &b'*' {
return SimpleCron::EveryDay { hour, minute };
return SimpleCron::Day { hour, minute };
} else {
let day = value.parse::<u32>().failed("parse cron weekday");
if !(1..=7).contains(&hour) {
@ -183,7 +183,7 @@ impl SimpleCron {
));
}
return SimpleCron::EveryWeek { day, hour, minute };
return SimpleCron::Week { day, hour, minute };
}
}
}
@ -194,7 +194,7 @@ impl SimpleCron {
pub fn time_to_next(&self) -> Duration {
let now = chrono::Local::now();
let next = match self {
SimpleCron::EveryDay { hour, minute } => {
SimpleCron::Day { hour, minute } => {
let next = chrono::Local
.with_ymd_and_hms(now.year(), now.month(), now.day(), *hour, *minute, 0)
.unwrap();
@ -204,7 +204,7 @@ impl SimpleCron {
next
}
}
SimpleCron::EveryWeek { day, hour, minute } => {
SimpleCron::Week { day, hour, minute } => {
let next = chrono::Local
.with_ymd_and_hms(now.year(), now.month(), now.day(), *hour, *minute, 0)
.unwrap();
@ -216,7 +216,7 @@ impl SimpleCron {
next
}
}
SimpleCron::EveryHour { minute } => {
SimpleCron::Hour { minute } => {
let next = chrono::Local
.with_ymd_and_hms(now.year(), now.month(), now.day(), now.hour(), *minute, 0)
.unwrap();

View file

@ -414,12 +414,13 @@ impl Store {
true,
);
let mut delete_keys = Vec::new();
while let Some(values) = iter.next().await {
for value in values.unwrap() {
let key = value.key();
let key_ = value.key();
let value = value.value();
let subspace = key[0];
let key = &key[1..];
let subspace = key_[0];
let key = &key_[1..];
match subspace {
SUBSPACE_INDEXES => {
@ -435,19 +436,23 @@ impl Store {
}
SUBSPACE_VALUES => {
// Ignore lastId counter and ID mappings
if (key.len() == 4
if key[0..4] == u32::MAX.to_be_bytes() {
continue;
} else if key.len() == 4
&& value.len() == 8
&& u32::deserialize(key).is_ok()
&& u64::deserialize(value).is_ok())
|| &key[0..4] == u32::MAX.to_be_bytes()
&& u64::deserialize(value).is_ok()
{
if u32::deserialize(key).unwrap() != u32::MAX {
delete_keys.push(key.to_vec());
}
continue;
}
panic!("Table values is not empty: {key:?} {value:?}");
}
SUBSPACE_BITMAPS => {
if &key[0..4] != u32::MAX.to_be_bytes() {
if key[0..4] != u32::MAX.to_be_bytes() {
panic!(
"Table bitmaps is not empty, account {}, collection {}, family {}, field {}, key {:?}: {:?}",
u32::from_be_bytes(key[0..4].try_into().unwrap()),
@ -466,7 +471,9 @@ impl Store {
panic!("Table quotas is not empty: {k:?} = {v:?} (key {key:?})");
}
}
SUBSPACE_LOGS => (),
SUBSPACE_LOGS => {
delete_keys.push(key.to_vec());
}
_ => panic!("Invalid key found in database: {key:?} for subspace {subspace}"),
}
@ -474,7 +481,13 @@ impl Store {
}
// Empty database
self.destroy().await;
let trx = self.db.create_trx().unwrap();
for key in delete_keys {
trx.clear(&key);
}
trx.commit().await.unwrap();
//self.destroy().await;
crate::backend::foundationdb::write::BITMAPS.lock().clear();
}
}

View file

@ -56,6 +56,7 @@ pub async fn store_tests() {
if insert {
db.destroy().await;
}
#[cfg(feature = "foundationdb")]
assign_id::test(db.clone()).await;
query::test(db, insert).await;
temp_dir.delete();