Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature flags in crate's docs.rs documentation #46

Merged
merged 6 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
6 changes: 4 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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),
}
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
//! }
//! ```
#![deny(missing_docs)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![warn(rust_2018_idioms)]

#[macro_use]
Expand All @@ -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};
Expand Down
3 changes: 0 additions & 3 deletions src/proto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
jonhoo marked this conversation as resolved.
Show resolved Hide resolved

pub(crate) fn get_env_url() -> String {
use std::env;
let var = env::var("FAKTORY_PROVIDER").unwrap_or_else(|_| "FAKTORY_URL".to_string());
Expand Down
1 change: 1 addition & 0 deletions src/proto/single/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod resp;
mod utils;

#[cfg(feature = "ent")]
#[cfg_attr(docsrs, doc(cfg(feature = "ent")))]
mod ent;

use crate::error::Error;
Expand Down
19 changes: 14 additions & 5 deletions tests/real/enterprise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,31 +325,30 @@ 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();

// Now the following job is _technically_ a 'duplicate', BUT if the `unique_for` value is not set,
// 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();
producer.enqueue(job2).unwrap(); // bypassing the 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();

Expand All @@ -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());
jonhoo marked this conversation as resolved.
Show resolved Hide resolved
assert!(!c.run_one(0, &[queue_name]).unwrap()); // empty;
}
Loading