Skip to content

Commit

Permalink
Make queue control tests use newly introduced Client::current_info (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
rustworthy authored Jun 22, 2024
1 parent 3c966bd commit d51a95b
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions tests/real/community.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::{assert_gte, skip_check};
use faktory::{Client, Job, JobBuilder, JobId, Worker, WorkerBuilder, WorkerId};
use serde_json::Value;
use std::{io, sync};
use std::{io, sync, time::Duration};
use tokio::time as tokio_time;

#[tokio::test(flavor = "multi_thread")]
async fn hello_client() {
Expand Down Expand Up @@ -118,6 +119,9 @@ async fn server_state() {
.await
.unwrap();

// let's give Faktory a second to get updated
tokio_time::sleep(Duration::from_secs(1)).await;

// we only pushed 1 job on this queue
let server_state = client.current_info().await.unwrap();
assert_eq!(*server_state.data.queues.get(local).unwrap(), 1);
Expand Down Expand Up @@ -159,16 +163,15 @@ async fn server_state() {
server_state.data.total_processed
);

// Uncomment when `Client::queue_remove` is delivered:
// client.queue_remove(&[local]).await.unwrap();
// assert!(client
// .current_info()
// .await
// .unwrap()
// .data
// .queues
// .get(local)
// .is_none());
client.queue_remove(&[local]).await.unwrap();
assert!(client
.current_info()
.await
.unwrap()
.data
.queues
.get(local)
.is_none());
}

#[tokio::test(flavor = "multi_thread")]
Expand Down Expand Up @@ -336,8 +339,8 @@ async fn queue_control_actions() {
assert!(rx.try_recv().is_ok());

// let's inspect the sever state
let server_state = client.info().await.unwrap();
let queues = &server_state.get("faktory").unwrap().get("queues").unwrap();
let server_state = client.current_info().await.unwrap();
let queues = &server_state.data.queues;
assert_eq!(*queues.get(local_1).unwrap(), 1); // 1 job remaining
assert_eq!(*queues.get(local_2).unwrap(), 1); // also 1 job remaining

Expand All @@ -351,8 +354,8 @@ async fn queue_control_actions() {
assert!(!rx.try_recv().is_ok());

// let's inspect the sever state again
let server_state = client.info().await.unwrap();
let queues = &server_state.get("faktory").unwrap().get("queues").unwrap();
let server_state = client.current_info().await.unwrap();
let queues = &server_state.data.queues;
// our queue are not even mentioned in the server report:
assert!(queues.get(local_1).is_none());
assert!(queues.get(local_2).is_none());
Expand Down Expand Up @@ -418,8 +421,8 @@ async fn queue_control_actions_wildcard() {
assert!(rx.try_recv().is_ok());

// let's inspect the sever state
let server_state = client.info().await.unwrap();
let queues = &server_state.get("faktory").unwrap().get("queues").unwrap();
let server_state = client.current_info().await.unwrap();
let queues = &server_state.data.queues;
assert_eq!(*queues.get(local_1).unwrap(), 1); // 1 job remaining
assert_eq!(*queues.get(local_2).unwrap(), 1); // also 1 job remaining

Expand All @@ -433,9 +436,8 @@ async fn queue_control_actions_wildcard() {
assert!(!rx.try_recv().is_ok());

// let's inspect the sever state again
let server_state = client.info().await.unwrap();
let queues = &server_state.get("faktory").unwrap().get("queues").unwrap();

let server_state = client.current_info().await.unwrap();
let queues = &server_state.data.queues;
// our queue are not even mentioned in the server report:
assert!(queues.get(local_1).is_none());
assert!(queues.get(local_2).is_none());
Expand Down

0 comments on commit d51a95b

Please sign in to comment.