From 62c606824aadb3d3fc7786f6e5af5b6f3cb0f8ca Mon Sep 17 00:00:00 2001 From: Pavel Mikhalkevich Date: Mon, 8 Jan 2024 15:01:34 +0500 Subject: [PATCH 1/6] Add queue check step to 'ent_unique_job_bypass_unique_lock' test --- tests/real/enterprise.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/real/enterprise.rs b/tests/real/enterprise.rs index d1f651f1..67264f9a 100644 --- a/tests/real/enterprise.rs +++ b/tests/real/enterprise.rs @@ -325,15 +325,14 @@ fn ent_unique_job_until_start() { #[test] fn ent_unique_job_bypass_unique_lock() { use faktory::error; - use serde_json::Value; skip_if_not_enterprise!(); let url = learn_faktory_url(); let mut producer = Producer::connect(Some(&url)).unwrap(); - + let queue_name = "ent_unique_job_bypass_unique_lock"; let job1 = Job::builder("order") - .queue("ent_unique_job_bypass_unique_lock") + .queue(queue_name) .unique_for(60) .build(); @@ -341,7 +340,7 @@ fn ent_unique_job_bypass_unique_lock() { // the uniqueness lock will be bypassed on the server. This special case is mentioned in the docs: // https://github.com/contribsys/faktory/wiki/Ent-Unique-Jobs#bypassing-uniqueness let job2 = Job::builder("order") // same jobtype and args (args are just not set) - .queue("ent_unique_job_bypass_unique_lock") // same queue + .queue(queue_name) // same queue .build(); // NB: `unique_for` not set producer.enqueue(job1).unwrap(); @@ -349,7 +348,7 @@ fn ent_unique_job_bypass_unique_lock() { // This _is_ a 'duplicate'. let job3 = Job::builder("order") - .queue("ent_unique_job_bypass_unique_lock") + .queue(queue_name) .unique_for(60) // NB .build(); @@ -360,4 +359,14 @@ fn ent_unique_job_bypass_unique_lock() { } else { panic!("Expected protocol error.") } + + // let's consume three times from the queue to verify that the first two jobs + // have been enqueued for real, while the last one has not. + let mut c = ConsumerBuilder::default(); + c.register("order", |j| -> io::Result<_> { Ok(eprintln!("{:?}", j)) }); + let mut c = c.connect(Some(&url)).unwrap(); + + assert!(c.run_one(0, &[queue_name]).unwrap()); + assert!(c.run_one(0, &[queue_name]).unwrap()); + assert!(!c.run_one(0, &[queue_name]).unwrap()); // empty; } From 3b9171543ffee5fc5d398a39de2abce0411ba90f Mon Sep 17 00:00:00 2001 From: Pavel Mikhalkevich Date: Mon, 8 Jan 2024 15:32:12 +0500 Subject: [PATCH 2/6] Resolce check warnings in error module --- src/error.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/error.rs b/src/error.rs index 38e14ec8..1f54f7a0 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,10 +1,10 @@ //! Enumerates all errors that this crate may return. //! -//! [`Error`] is the top level error enum. +//! [`enum@Error`] is the top level error enum. //! Most consumers should only need to interact with this type. //! This is also where more generic errors such as I/O errors are placed, -//! whereas the more specific errors ([`Connection`] and [`Protocol`]) are -//! related to logic. +//! whereas the more specific errors ([`Connect`] and [`Protocol`]) +//! are related to logic. //! //! [`Connect`] describes errors specific to the connection logic, for example //! version mismatches or an invalid URL. From fafb4f4e3578d2bb3a90e9672f76967b2b6123d6 Mon Sep 17 00:00:00 2001 From: Pavel Mikhalkevich Date: Mon, 8 Jan 2024 15:58:07 +0500 Subject: [PATCH 3/6] Mark 'tls' and 'ent' functionality with doc cfg attr --- Cargo.toml | 4 ++++ src/error.rs | 2 ++ src/lib.rs | 3 +++ src/proto/single/mod.rs | 1 + 4 files changed, 10 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index ae4edcfc..872de090 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,3 +45,7 @@ openssl = { version = "0.10.60", optional = true } name = "loadtest" path = "src/bin/loadtest.rs" required-features = ["binaries"] + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] diff --git a/src/error.rs b/src/error.rs index 1f54f7a0..b63ca11d 100644 --- a/src/error.rs +++ b/src/error.rs @@ -44,6 +44,7 @@ pub enum Error { /// Indicates an error in the underlying TLS stream. #[cfg(feature = "tls")] + #[cfg_attr(docsrs, doc(cfg(feature = "tls")))] #[error("underlying tls stream")] TlsStream(#[source] native_tls::Error), } @@ -95,6 +96,7 @@ pub enum Protocol { /// The server reported a unique constraint violation. #[cfg(feature = "ent")] + #[cfg_attr(docsrs, doc(cfg(feature = "ent")))] #[error("server reported unique constraint violation: {msg}")] UniqueConstraintViolation { /// The error message given by the server. diff --git a/src/lib.rs b/src/lib.rs index 5a83286e..89a88c54 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -55,6 +55,7 @@ //! } //! ``` #![deny(missing_docs)] +#![cfg_attr(docsrs, feature(doc_cfg))] #![warn(rust_2018_idioms)] #[macro_use] @@ -66,8 +67,10 @@ mod producer; mod proto; #[cfg(feature = "tls")] +#[cfg_attr(docsrs, doc(cfg(feature = "tls")))] mod tls; #[cfg(feature = "tls")] +#[cfg_attr(docsrs, doc(cfg(feature = "tls")))] pub use tls::TlsStream; pub use crate::consumer::{Consumer, ConsumerBuilder}; diff --git a/src/proto/single/mod.rs b/src/proto/single/mod.rs index a02df87b..86657b1b 100644 --- a/src/proto/single/mod.rs +++ b/src/proto/single/mod.rs @@ -8,6 +8,7 @@ mod resp; mod utils; #[cfg(feature = "ent")] +#[cfg_attr(docsrs, doc(cfg(feature = "ent")))] mod ent; use crate::error::Error; From c8fb66e0f8154f4ca5876a91d8961bd0c997b4a2 Mon Sep 17 00:00:00 2001 From: Pavel Mikhalkevich Date: Mon, 8 Jan 2024 15:58:38 +0500 Subject: [PATCH 4/6] Rm unused single::Hi export --- src/proto/mod.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/proto/mod.rs b/src/proto/mod.rs index d8af3c0c..74386f84 100644 --- a/src/proto/mod.rs +++ b/src/proto/mod.rs @@ -15,9 +15,6 @@ pub use self::single::{ Ack, Fail, Heartbeat, Info, Job, JobBuilder, Push, QueueAction, QueueControl, }; -// responses that users can see -pub use self::single::Hi; - pub(crate) fn get_env_url() -> String { use std::env; let var = env::var("FAKTORY_PROVIDER").unwrap_or_else(|_| "FAKTORY_URL".to_string()); From 20332a9d5ab054e825c26675daaab84059f9b9f0 Mon Sep 17 00:00:00 2001 From: Pavel Mikhalkevich Date: Mon, 8 Jan 2024 16:00:07 +0500 Subject: [PATCH 5/6] Rm extra diff in error module --- src/error.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/error.rs b/src/error.rs index b63ca11d..d55bdb75 100644 --- a/src/error.rs +++ b/src/error.rs @@ -3,8 +3,8 @@ //! [`enum@Error`] is the top level error enum. //! Most consumers should only need to interact with this type. //! This is also where more generic errors such as I/O errors are placed, -//! whereas the more specific errors ([`Connect`] and [`Protocol`]) -//! are related to logic. +//! whereas the more specific errors ([`Connect`] and [`Protocol`]) are +//! related to logic. //! //! [`Connect`] describes errors specific to the connection logic, for example //! version mismatches or an invalid URL. From 2b045e1e0f43ec7e831b9444f64d33b092d31480 Mon Sep 17 00:00:00 2001 From: Pavel Mikhalkevich Date: Mon, 8 Jan 2024 16:00:29 +0500 Subject: [PATCH 6/6] Rm extra diff in error module --- src/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/error.rs b/src/error.rs index d55bdb75..89de50ff 100644 --- a/src/error.rs +++ b/src/error.rs @@ -3,7 +3,7 @@ //! [`enum@Error`] is the top level error enum. //! Most consumers should only need to interact with this type. //! This is also where more generic errors such as I/O errors are placed, -//! whereas the more specific errors ([`Connect`] and [`Protocol`]) are +//! whereas the more specific errors ([`Connect`] and [`Protocol`]) are //! related to logic. //! //! [`Connect`] describes errors specific to the connection logic, for example