Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/commanded/aggregates/aggregate_state_builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ defmodule Commanded.Aggregates.AggregateStateBuilder do
agg = %Aggregate{
state
| aggregate_version: source_version,
aggregate_state: data
aggregate_state: data,
snapshotting: %{snapshotting | snapshot_version: source_version}
}

{agg, true, source_version}
Expand Down
20 changes: 20 additions & 0 deletions test/aggregates/snapshotting_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,26 @@ defmodule Commanded.Aggregates.SnapshottingTest do

assert_aggregate_version(ExampleAggregate, aggregate_uuid, 5)
end

test "should not snapshot again until interval reached since restored snapshot" do
aggregate_uuid = UUID.uuid4()
append_items(aggregate_uuid, 10)

restart_aggregate(ExampleAggregate, aggregate_uuid)

# Fewer events than `snapshot_every` since the restored snapshot
append_items(aggregate_uuid, 1)
assert_aggregate_version(ExampleAggregate, aggregate_uuid, 11)

assert {:ok, %SnapshotData{source_version: 10}} =
EventStore.read_snapshot(DefaultApp, aggregate_uuid)

append_items(aggregate_uuid, 9)
assert_aggregate_version(ExampleAggregate, aggregate_uuid, 20)

assert {:ok, %SnapshotData{source_version: 20}} =
EventStore.read_snapshot(DefaultApp, aggregate_uuid)
end
end

describe "mismatched snapshot versions" do
Expand Down
Loading