looplab / eventhorizon

Event Sourcing for Go!
Apache License 2.0
1.57k stars 196 forks source link

Fix setting aggregate version after snapshot was loaded #416

Open totemcaf opened 7 months ago

totemcaf commented 7 months ago

Description

When an aggregate is loaded from a Snapshot, and no additional events are applied, the version is left in 0.

Affected Components

Related Issues

414

Solution and Design

After the snapshot was read from DB and applied to the Aggregate, the aggregate version is set to the corresponding to the Snapshot:

a.SetAggregateVersion(snapshot.Version)

Steps to test and verify

See TestAggregateStore_TakeSnapshot_no_additional_events_after_snapshot_was_saved

  1. Create an aggregate
  2. Set a snapshot policy to store every 3 events
  3. Add 3 events to aggregate (same number than policy or a multiple of it)
  4. Save snapshot
  5. Load aggregate from Snapshot
  6. Aggregate version will be 0
coveralls commented 7 months ago

Coverage Status

coverage: 67.319% (-0.04%) from 67.361% when pulling 6a31b3c9c0d9824228d8b3f1aaf20cff31c8a3c6 on AltScore:fix/414-set-version-on-snapshot-load into ac3a97277ea36ba535abd96e0bdad033bd243193 on looplab:main.

totemcaf commented 7 months ago

@maxekman can you give a look at this?