Merge 'Serialize compat tests and use Mutex::lock() instead of Mutex::try_lock() in UnixIO' from Jussi Saurio

Closes #2715
1. Since our multithreading isn't proven correct (and is actually
probably all kinds of incorrect), let's serialize these tests since they
operate on the same database
2. Use `lock()` instead of `try_lock()` - i.e. wait to obtain the lock
on the file instead of immediately erroring if we can't

Closes #2729
This commit is contained in:
Pekka Enberg
2025-08-22 15:39:26 +03:00
committed by GitHub
2 changed files with 8 additions and 26 deletions

View File

@@ -87,9 +87,9 @@ reset-db:
.PHONY: reset-db
test-sqlite3: reset-db
cargo test -p turso_sqlite3 --test compat
cargo test -p turso_sqlite3 --test compat -- --test-threads=1
./scripts/clone_test_db.sh
cargo test -p turso_sqlite3 --test compat --features sqlite3
cargo test -p turso_sqlite3 --test compat --features sqlite3 -- --test-threads=1
.PHONY: test-sqlite3
test-json:

View File

@@ -193,10 +193,7 @@ impl File for UnixFile {
#[instrument(err, skip_all, level = Level::TRACE)]
fn pread(&self, pos: usize, c: Completion) -> Result<Completion> {
let file = self
.file
.try_lock()
.ok_or_else(|| LimboError::LockingError("Failed locking file".to_string()))?;
let file = self.file.lock();
let result = unsafe {
let r = c.as_read();
let buf = r.buf();
@@ -221,10 +218,7 @@ impl File for UnixFile {
#[instrument(err, skip_all, level = Level::TRACE)]
fn pwrite(&self, pos: usize, buffer: Arc<crate::Buffer>, c: Completion) -> Result<Completion> {
let file = self
.file
.try_lock()
.ok_or_else(|| LimboError::LockingError("Failed locking file".to_string()))?;
let file = self.file.lock();
let result = { rustix::io::pwrite(file.as_fd(), buffer.as_slice(), pos as u64) };
match result {
Ok(n) => {
@@ -248,10 +242,7 @@ impl File for UnixFile {
// use `pwrite` for single buffer
return self.pwrite(pos, buffers[0].clone(), c);
}
let file = self
.file
.try_lock()
.ok_or_else(|| LimboError::LockingError("Failed locking file".to_string()))?;
let file = self.file.lock();
match try_pwritev_raw(file.as_raw_fd(), pos as u64, &buffers, 0, 0) {
Ok(written) => {
@@ -267,10 +258,7 @@ impl File for UnixFile {
#[instrument(err, skip_all, level = Level::TRACE)]
fn sync(&self, c: Completion) -> Result<Completion> {
let file = self
.file
.try_lock()
.ok_or_else(|| LimboError::LockingError("Failed locking file".to_string()))?;
let file = self.file.lock();
let result = unsafe { libc::fsync(file.as_raw_fd()) };
if result == -1 {
let e = std::io::Error::last_os_error();
@@ -284,19 +272,13 @@ impl File for UnixFile {
#[instrument(err, skip_all, level = Level::TRACE)]
fn size(&self) -> Result<u64> {
let file = self
.file
.try_lock()
.ok_or_else(|| LimboError::LockingError("Failed locking file".to_string()))?;
let file = self.file.lock();
Ok(file.metadata()?.len())
}
#[instrument(err, skip_all, level = Level::INFO)]
fn truncate(&self, len: usize, c: Completion) -> Result<Completion> {
let file = self
.file
.try_lock()
.ok_or_else(|| LimboError::LockingError("Failed locking file".to_string()))?;
let file = self.file.lock();
let result = file.set_len(len as u64);
match result {
Ok(()) => {