Skip to content

Commit 5eeb88f

Browse files
committed
fixup! Break ties of PreferDistinct submissions with equal counts
Add doctest
1 parent 85a2c2e commit 5eeb88f

2 files changed

Lines changed: 27 additions & 8 deletions

File tree

‎justfile‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,14 @@ clean:
4141

4242
# Run all tests
4343
[group('test')]
44-
test: test-unit test-integration
44+
test: test-doc test-unit test-integration
45+
46+
# Run doctests
47+
# Nextest doesn't currently support doctests
48+
# c.f. https://nexte.st/docs/integrations/test-coverage/
49+
[group('test')]
50+
test-doc *TEST_ARGS:
51+
cargo test --doc --workspace {{TEST_ARGS}}
4552

4653
# Rust unit test suite
4754
[group('test')]

‎opsqueue/src/consumer/strategy.rs‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub enum Strategy {
1919
}
2020

2121
/// Iterator over the `meta_key`s of a chain of nested
22-
/// [`Strategy::PreferDistinct`]. outermost first. Stops at the first
22+
/// [`Strategy::PreferDistinct`], outermost first. Stops at the first
2323
/// non-`PreferDistinct` strategy, which can afterwards be retrieved with
2424
/// [`MetaKeysIter::take`].
2525
pub struct MetaKeysIter<'a> {
@@ -178,13 +178,25 @@ impl Strategy {
178178
}
179179
}
180180

181-
/// Append a query snippet to select from the `random_order` column on the
182-
/// given table using the "cutting the deck" technique.
183-
fn push_random_order_query<'a>(
181+
/// Append a query snippet to a `QueryBuilder` to select `columns` using the
182+
/// `random_order` column as a filter (the "cutting the deck" technique),
183+
/// from table `table`.
184+
///
185+
/// ```
186+
/// use opsqueue::consumer::strategy::Strategy;
187+
/// use sqlx::{QueryBuilder, Sqlite};
188+
/// let mut qb: QueryBuilder<Sqlite> = QueryBuilder::new("");
189+
/// Strategy::push_random_order_query(&mut qb, "id, name", "users", Some("status = 'active'"));
190+
/// let expected_sql = "SELECT id, name FROM users WHERE random_order >= ? AND status = 'active' \
191+
/// UNION ALL \
192+
/// SELECT id, name FROM users WHERE random_order < ? AND status = 'active'";
193+
/// assert_eq!(qb.sql(), expected_sql);
194+
/// ```
195+
pub fn push_random_order_query<'a>(
184196
qb: &'a mut QueryBuilder<Sqlite>,
185-
columns: &str,
186-
table_name: &str,
187-
condition: Option<&str>,
197+
columns: &'static str,
198+
table_name: &'static str,
199+
condition: Option<&'static str>,
188200
) -> &'a mut QueryBuilder<Sqlite> {
189201
let random_offset: u16 = rand::random();
190202
let push_select = |qb: &mut QueryBuilder<Sqlite>, operator: &str| {

0 commit comments

Comments
 (0)