Skip to content

Commit 63aec6f

Browse files
committed
ignore footer when comparing sqlite and libsql db files
1 parent 2bcb04a commit 63aec6f

4 files changed

Lines changed: 21 additions & 5 deletions

File tree

libsql-wal/src/replication/replicator.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,11 @@ mod test {
311311
replica_content[offset..offset + 4096].copy_from_slice(frame.data());
312312
}
313313

314-
assert_eq!(replica_content, db_content);
314+
assert_eq!(db_payload(&replica_content), db_payload(&db_content));
315+
}
316+
317+
fn db_payload(db: &[u8]) -> &[u8] {
318+
let size = (db.len() / 4096) * 4096;
319+
&db[..size]
315320
}
316321
}

libsql-wal/src/segment/current.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ mod test {
794794
let mut copy = Vec::new();
795795
tmp.read_to_end(&mut copy).unwrap();
796796

797-
assert_eq!(copy, orig);
797+
assert_eq!(db_payload(&copy), db_payload(&orig));
798798
}
799799

800800
#[tokio::test]
@@ -1064,4 +1064,9 @@ mod test {
10641064
.unwrap();
10651065
}
10661066
}
1067+
1068+
fn db_payload(db: &[u8]) -> &[u8] {
1069+
let size = (db.len() / 4096) * 4096;
1070+
&db[..size]
1071+
}
10671072
}

libsql-wal/src/segment/list.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ mod test {
441441
.read_to_end(&mut orig_bytes)
442442
.unwrap();
443443

444-
assert_eq!(orig_bytes, copy_ytes);
444+
assert_eq!(db_payload(&orig_bytes), db_payload(&copy_bytes));
445445
}
446446

447447
#[tokio::test]
@@ -567,7 +567,7 @@ mod test {
567567
.read_to_end(&mut orig_bytes)
568568
.unwrap();
569569

570-
assert_eq!(copy_bytes, orig_bytes);
570+
assert_eq!(db_payload(&copy_bytes), db_payload(&orig_bytes));
571571
}
572572

573573
#[tokio::test]
@@ -605,4 +605,9 @@ mod test {
605605
assert_eq!(count, 1);
606606
assert_eq!(replicated_from, 13);
607607
}
608+
609+
fn db_payload(db: &[u8]) -> &[u8] {
610+
let size = (db.len() / 4096) * 4096;
611+
&db[..size]
612+
}
608613
}

libsql-wal/tests/oracle.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ fn compare_db_files(sqlite: &Path, libsql: &Path) {
170170
let len1 = db1.metadata().unwrap().len();
171171
let len2 = db2.metadata().unwrap().len();
172172

173-
assert_eq!(len1, len2);
173+
// sqlite file may contain a footer, compare only the data portions of the db files.
174+
assert_eq!(len1, 4096 * (len2 / 4096));
174175

175176
let n_pages = len1 / 4096;
176177
let mut buf1 = [0; 4096];

0 commit comments

Comments
 (0)