Skip to content
This repository has been archived by the owner on Feb 18, 2025. It is now read-only.

Event recovery does not record last_version correctly #30

Closed
jrudolph opened this issue Jun 24, 2024 · 3 comments · Fixed by #32
Closed

Event recovery does not record last_version correctly #30

jrudolph opened this issue Jun 24, 2024 · 3 comments · Fixed by #32

Comments

@jrudolph
Copy link
Contributor

Instead it always sets the last_version field to None in

last_version: None,
so that when an entity is reinstantiated it will fail after handling the next command in
return Err(Error::UnexpectedVersion(version, last_version));

@jrudolph
Copy link
Contributor Author

Here's a diff for the tests that makes it fail:

diff --git a/src/entity.rs b/src/entity.rs
index 6f6a367..7728e73 100644
--- a/src/entity.rs
+++ b/src/entity.rs
@@ -625,7 +625,7 @@ mod tests {
 
         let id = Uuid::from_u128(0);
 
-        let mut counter = Counter::default().entity().build(id, pool).await?;
+        let mut counter = Counter::default().entity().build(id, pool.clone()).await?;
         assert_eq!(counter.entity, Counter(0));
 
         let result = counter.handle_command(Decrease(1)).await?;
@@ -633,8 +633,12 @@ mod tests {
 
         let result = counter.handle_command(Increase(40)).await?;
         assert_eq!(result, Ok(&Counter(40)));
+
         let result = counter.handle_command(Decrease(20)).await?;
         assert_eq!(result, Ok(&Counter(20)));
+
+        // reinstantiate the counter (to test that event recovery works)
+        let mut counter = Counter::default().entity().build(id, pool).await?;
         let result = counter.handle_command(Increase(22)).await?;
         assert_eq!(result, Ok(&Counter(42)));

@jrudolph
Copy link
Contributor Author

Btw. what's the difference between version and seq_no?

@jrudolph
Copy link
Contributor Author

Ok, seq_no seems to be the global sequence number across all entities of all types.

jrudolph added a commit to jrudolph/evented that referenced this issue Jun 24, 2024
hseeberger pushed a commit that referenced this issue Jun 26, 2024
* fix: record last version after recovery

Fixes #30

* simplify code
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant