From 80fbaa077a77ac26b910b9b9096587f8c09f6fc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavie=C5=82=20Michalkievi=C4=8D?= <117771945+rustworthy@users.noreply.github.com> Date: Sat, 20 Jan 2024 15:30:50 +0500 Subject: [PATCH] Feature flags in crate's docs.rs documentation (#46) --- Cargo.toml | 4 ++++ src/error.rs | 6 ++++-- src/lib.rs | 3 +++ src/proto/mod.rs | 3 --- src/proto/single/mod.rs | 1 + tests/real/enterprise.rs | 19 ++++++++++++++----- 6 files changed, 26 insertions(+), 10 deletions(-) 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 38e14ec8..89de50ff 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,9 +1,9 @@ //! 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 +//! whereas the more specific errors ([`Connect`] and [`Protocol`]) are //! related to logic. //! //! [`Connect`] describes errors specific to the connection logic, for example @@ -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/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()); 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; 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; }