Apply suggestions from code review

Co-authored-by: ryneeverett <ryneeverett@gmail.com>
This commit is contained in:
Dustin J. Mitchell 2025-07-17 12:00:22 -04:00 committed by GitHub
parent 309abce339
commit 8b1f7e2b30
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 22 deletions

View file

@ -59,4 +59,6 @@ jobs:
override: true override: true
- name: test - name: test
run: TEST_DB_URL=postgresql://test_user:test_password@localhost:5432/test_db cargo test env:
TEST_DB_URL: postgresql://test_user:test_password@localhost:5432/test_db
run: cargo test

View file

@ -20,8 +20,8 @@ for more on how to use this project.
The repository is comprised of three crates: The repository is comprised of three crates:
- `taskchampion-sync-server-core` implements the core of the protocol - `taskchampion-sync-server-core` implements the core of the protocol
- `taskchmpaion-sync-server-storage-sqlite` implements an SQLite backend for the core - `taskchampion-sync-server-storage-sqlite` implements an SQLite backend for the core
- `taskchmpaion-sync-server-storage-posrgres` implements a Postgres backend for the core - `taskchampion-sync-server-storage-postgres` implements a Postgres backend for the core
- `taskchampion-sync-server` implements a simple HTTP server for the protocol - `taskchampion-sync-server` implements a simple HTTP server for the protocol
### Building From Source ### Building From Source

View file

@ -153,7 +153,7 @@ impl StorageTxn for Txn {
async fn new_client(&mut self, latest_version_id: Uuid) -> anyhow::Result<()> { async fn new_client(&mut self, latest_version_id: Uuid) -> anyhow::Result<()> {
self.db_client() self.db_client()
.execute( .execute(
"INSERT into clients (client_id, latest_version_id) values ($1, $2)", "INSERT INTO clients (client_id, latest_version_id) VALUES ($1, $2)",
&[&self.client_id, &latest_version_id], &[&self.client_id, &latest_version_id],
) )
.await .await
@ -166,11 +166,11 @@ impl StorageTxn for Txn {
self.db_client() self.db_client()
.execute( .execute(
"UPDATE clients "UPDATE clients
set snapshot_version_id = $1, SET snapshot_version_id = $1,
versions_since_snapshot = $2, versions_since_snapshot = $2,
snapshot_timestamp = $3, snapshot_timestamp = $3,
snapshot = $4 snapshot = $4
where client_id = $5", WHERE client_id = $5",
&[ &[
&snapshot.version_id, &snapshot.version_id,
&(snapshot.versions_since as i32), &(snapshot.versions_since as i32),
@ -553,19 +553,6 @@ mod test {
.await .await
} }
#[tokio::test]
async fn test_get_version_none() -> anyhow::Result<()> {
with_db(async |connection_string, db_client| {
let storage = PostgresStorage::new(connection_string).await?;
let client_id = make_client(&db_client).await?;
let mut txn = storage.txn(client_id).await?;
assert_eq!(txn.get_version_by_parent(Uuid::new_v4()).await?, None);
assert_eq!(txn.get_version(Uuid::new_v4()).await?, None);
Ok(())
})
.await
}
#[tokio::test] #[tokio::test]
async fn test_get_version() -> anyhow::Result<()> { async fn test_get_version() -> anyhow::Result<()> {
with_db(async |connection_string, db_client| { with_db(async |connection_string, db_client| {
@ -603,7 +590,7 @@ mod test {
} }
#[tokio::test] #[tokio::test]
async fn add_version() -> anyhow::Result<()> { async fn test_add_version() -> anyhow::Result<()> {
with_db(async |connection_string, db_client| { with_db(async |connection_string, db_client| {
let storage = PostgresStorage::new(connection_string).await?; let storage = PostgresStorage::new(connection_string).await?;
let client_id = make_client(&db_client).await?; let client_id = make_client(&db_client).await?;
@ -628,7 +615,7 @@ mod test {
/// When an add_version call specifies an incorrect `parent_version_id, it fails. This is /// When an add_version call specifies an incorrect `parent_version_id, it fails. This is
/// typically avoided by calling `get_client` beforehand, which (due to repeatable reads) /// typically avoided by calling `get_client` beforehand, which (due to repeatable reads)
/// allows the caller to check the `latest_version_id` before calling `add_version`. /// allows the caller to check the `latest_version_id` before calling `add_version`.
async fn add_version_mismatch() -> anyhow::Result<()> { async fn test_add_version_mismatch() -> anyhow::Result<()> {
with_db(async |connection_string, db_client| { with_db(async |connection_string, db_client| {
let storage = PostgresStorage::new(connection_string).await?; let storage = PostgresStorage::new(connection_string).await?;
let client_id = make_client(&db_client).await?; let client_id = make_client(&db_client).await?;
@ -649,7 +636,7 @@ mod test {
#[tokio::test] #[tokio::test]
/// Adding versions to two different clients can proceed concurrently. /// Adding versions to two different clients can proceed concurrently.
async fn add_version_no_conflict_different_clients() -> anyhow::Result<()> { async fn test_add_version_no_conflict_different_clients() -> anyhow::Result<()> {
with_db(async |connection_string, db_client| { with_db(async |connection_string, db_client| {
let storage = PostgresStorage::new(connection_string).await?; let storage = PostgresStorage::new(connection_string).await?;