Skip to content

Commit

Permalink
Add test for Client::delete_job
Browse files Browse the repository at this point in the history
  • Loading branch information
rustworthy committed Sep 7, 2024
1 parent 559921d commit 3832603
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/client/public/job_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl Client {
}

/// Delete a job from a queue.
pub async fn delete_job<Q>(&self, queue_name: Q, job_id: Uuid) -> Result<(), Error>
pub async fn delete_job<Q>(&self, queue_name: Q, job_id: Uuid) -> Result<bool, Error>
where
Q: AsRef<str>,
{
Expand All @@ -100,7 +100,6 @@ impl Client {
.bind([job_id])
.fetch_one(&self.pool)
.await?;
println!("{:?}", deleted_count);
Ok(())
Ok(deleted_count.0 == 1)
}
}
31 changes: 26 additions & 5 deletions tests/e2e/job_delete.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::utils;
use pgboss::Client;
use pgboss::{Client, Job};
use uuid::Uuid;

#[tokio::test]
Expand All @@ -12,20 +12,41 @@ async fn delete_job_queue_does_not_exist() {
let job_id = Uuid::new_v4();
let queue_name = "jobtype";

let _ = c.delete_job(queue_name, job_id).await.unwrap();
let deleted = c.delete_job(queue_name, job_id).await.unwrap();
assert!(!deleted)
}

#[tokio::test]
async fn delete_job_does_not_exist() {
let local = "delete_job_does_not_exist";
utils::drop_schema(&local).await.unwrap();

let c = Client::builder().schema(local).connect().await.unwrap();
c.create_standard_queue("jobtype").await.unwrap();

let job_id = Uuid::new_v4();
let queue_name = "jobtype";

let deleted = c.delete_job(queue_name, job_id).await.unwrap();
assert!(!deleted);
}

#[tokio::test]
async fn delete_job() {
let local = "fetch_job";
let local = "delete_job";
utils::drop_schema(&local).await.unwrap();

let c = Client::builder().schema(local).connect().await.unwrap();
c.create_standard_queue("jobtype").await.unwrap();

let job_id = Uuid::new_v4();
let queue_name = "jobtype";
let job = Job::builder().id(job_id).queue_name(queue_name).build();

c.send_job(job).await.unwrap();

let deleted = c.delete_job(queue_name, job_id).await.unwrap();
assert!(deleted);

// fetch one
let _ = c.delete_job(queue_name, job_id).await.unwrap();
assert!(c.fetch_job(queue_name).await.unwrap().is_none());
}

0 comments on commit 3832603

Please sign in to comment.