fix: offset be inclusive end

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2024-08-14 14:46:53 +02:00
parent 242dd2ce76
commit 101a266ea2
Signed by: kjuulh
GPG Key ID: 9AA7BC13CE474394
4 changed files with 102 additions and 6 deletions

88
Cargo.lock generated
View File

@ -30,6 +30,15 @@ dependencies = [
"zerocopy", "zerocopy",
] ]
[[package]]
name = "aho-corasick"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "allocator-api2" name = "allocator-api2"
version = "0.2.18" version = "0.2.18"
@ -1020,6 +1029,15 @@ dependencies = [
"tracing", "tracing",
] ]
[[package]]
name = "matchers"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558"
dependencies = [
"regex-automata 0.1.10",
]
[[package]] [[package]]
name = "matchit" name = "matchit"
version = "0.7.3" version = "0.7.3"
@ -1096,6 +1114,7 @@ dependencies = [
"tower-http", "tower-http",
"tracing", "tracing",
"tracing-subscriber", "tracing-subscriber",
"tracing-test",
"uuid", "uuid",
] ]
@ -1409,6 +1428,50 @@ dependencies = [
"bitflags 2.6.0", "bitflags 2.6.0",
] ]
[[package]]
name = "regex"
version = "1.10.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata 0.4.7",
"regex-syntax 0.8.4",
]
[[package]]
name = "regex-automata"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
dependencies = [
"regex-syntax 0.6.29",
]
[[package]]
name = "regex-automata"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax 0.8.4",
]
[[package]]
name = "regex-syntax"
version = "0.6.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
[[package]]
name = "regex-syntax"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
[[package]] [[package]]
name = "ring" name = "ring"
version = "0.17.8" version = "0.17.8"
@ -2212,14 +2275,39 @@ version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b"
dependencies = [ dependencies = [
"matchers",
"nu-ansi-term", "nu-ansi-term",
"once_cell",
"regex",
"sharded-slab", "sharded-slab",
"smallvec", "smallvec",
"thread_local", "thread_local",
"tracing",
"tracing-core", "tracing-core",
"tracing-log", "tracing-log",
] ]
[[package]]
name = "tracing-test"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "557b891436fe0d5e0e363427fc7f217abf9ccd510d5136549847bdcbcd011d68"
dependencies = [
"tracing-core",
"tracing-subscriber",
"tracing-test-macro",
]
[[package]]
name = "tracing-test-macro"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04659ddb06c87d233c566112c1c9c5b9e98256d9af50ec3bc9c8327f873a7568"
dependencies = [
"quote",
"syn 2.0.72",
]
[[package]] [[package]]
name = "try-lock" name = "try-lock"
version = "0.2.5" version = "0.2.5"

View File

@ -29,3 +29,6 @@ bytes = "1.7.1"
prost = "0.13.1" prost = "0.13.1"
prost-types = "0.13.1" prost-types = "0.13.1"
chrono = { version = "0.4.38", features = ["serde"] } chrono = { version = "0.4.38", features = ["serde"] }
[dev-dependencies]
tracing-test = "0.2.5"

View File

@ -144,6 +144,8 @@ impl ConsumersState for SharedState {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use tracing_test::traced_test;
use crate::services::staging::{Staging, StagingEvent}; use crate::services::staging::{Staging, StagingEvent};
use super::*; use super::*;
@ -165,22 +167,25 @@ mod test {
} }
#[tokio::test] #[tokio::test]
#[traced_test]
async fn can_notify_consumer() -> anyhow::Result<()> { async fn can_notify_consumer() -> anyhow::Result<()> {
let consumer_id = "some-consumer-id".to_string(); let consumer_id = "some-consumer-id".to_string();
let consumer_index = "some-consumer-index".to_string(); let consumer_index = "some-consumer-index".to_string();
let topic = "some-topic".to_string(); let topic = "some-topic".to_string();
let offset = 10usize; let offset = 9usize;
let staging = Staging::default(); let staging = Staging::default();
// Publish 10 messages // Publish 10 messages
for _ in 0..10 { for _ in 0..10 {
staging let offset = staging
.publish(StagingEvent { .publish(StagingEvent {
topic: topic.clone(), topic: topic.clone(),
key: "".into(), key: "".into(),
id: None, id: None,
}) })
.await?; .await?;
tracing::trace!("published offset: {}", offset);
} }
let consumers = Consumers::new(Handler::new(staging)); let consumers = Consumers::new(Handler::new(staging));
@ -191,7 +196,7 @@ mod test {
consumers.notify_update(&topic, None, offset)?; consumers.notify_update(&topic, None, offset)?;
let consumer = consumers.get_consumer(&consumer_id, &consumer_index); let consumer = consumers.get_consumer(&consumer_id, &consumer_index);
assert_eq!(Some(Consumer { offset: 10 }), consumer); assert_eq!(Some(Consumer { offset: 9 }), consumer);
Ok(()) Ok(())
} }

View File

@ -60,7 +60,7 @@ impl Staging {
} }
None => { None => {
part.insert(staging_event.key.to_owned(), vec![staging_event]); part.insert(staging_event.key.to_owned(), vec![staging_event]);
1 0
} }
}, },
None => { None => {
@ -74,7 +74,7 @@ impl Staging {
BTreeMap::from([(staging_event.key.to_owned(), vec![staging_event])]), BTreeMap::from([(staging_event.key.to_owned(), vec![staging_event])]),
); );
1 0
} }
}; };
@ -150,7 +150,7 @@ impl Staging {
) )
} }
Ok(partition[start..end].to_vec()) Ok(partition[start..=end].to_vec())
} }
} }