Skip to content

Commit 0bae8f3

Browse files
committed
add test case
1 parent 0465327 commit 0bae8f3

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

src/mvcc_stream.rs

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ pub struct MvccStream<I: DoubleEndedIterator<Item = crate::Result<InternalValue>
1313
}
1414

1515
impl<I: DoubleEndedIterator<Item = crate::Result<InternalValue>>> MvccStream<I> {
16-
/// Initializes a new merge iterator
16+
/// Initializes a new multi-version-aware iterator.
1717
#[must_use]
1818
pub fn new(iter: I) -> Self {
1919
Self {
2020
inner: iter.double_ended_peekable(),
2121
}
2222
}
2323

24+
// Drains all entries for the given user key from the front of the iterator.
2425
fn drain_key_min(&mut self, key: &UserKey) -> crate::Result<()> {
2526
loop {
2627
let Some(next) = self.inner.next_if(|kv| {
@@ -139,6 +140,57 @@ mod tests {
139140
};
140141
}
141142

143+
#[test]
144+
#[expect(clippy::unwrap_used)]
145+
fn mvcc_stream_error() -> crate::Result<()> {
146+
{
147+
let vec = [
148+
Ok(InternalValue::from_components(
149+
"a",
150+
"new",
151+
999,
152+
ValueType::Value,
153+
)),
154+
Err(crate::Error::Io(std::io::Error::other("test error"))),
155+
];
156+
157+
let iter = Box::new(vec.into_iter());
158+
let mut iter = MvccStream::new(iter);
159+
160+
// Because next calls drain_key_min, the error is immediately first, even though
161+
// the first item is technically Ok
162+
assert!(matches!(iter.next().unwrap(), Err(crate::Error::Io(_))));
163+
iter_closed!(iter);
164+
}
165+
166+
{
167+
let vec = [
168+
Ok(InternalValue::from_components(
169+
"a",
170+
"new",
171+
999,
172+
ValueType::Value,
173+
)),
174+
Err(crate::Error::Io(std::io::Error::other("test error"))),
175+
];
176+
177+
let iter = Box::new(vec.into_iter());
178+
let mut iter = MvccStream::new(iter);
179+
180+
assert!(matches!(
181+
iter.next_back().unwrap(),
182+
Err(crate::Error::Io(_))
183+
));
184+
assert_eq!(
185+
InternalValue::from_components(*b"a", *b"new", 999, ValueType::Value),
186+
iter.next_back().unwrap()?,
187+
);
188+
iter_closed!(iter);
189+
}
190+
191+
Ok(())
192+
}
193+
142194
#[test]
143195
#[expect(clippy::unwrap_used)]
144196
fn mvcc_queue_reverse_almost_gone() -> crate::Result<()> {

0 commit comments

Comments
 (0)