Skip to content
Merged
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
23 changes: 22 additions & 1 deletion test/event/reset_batch_event_handler_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ defmodule Commanded.Event.BatchResetEventHandlerTest do
test "should be reset when starting from `:current`" do
stream_uuid = UUID.uuid4()

# Ignored initial events
# Ignored initial events - add these BEFORE starting the handler
initial_events = [%BankAccountOpened{account_number: "ACC123", initial_balance: 1_000}]
:ok = EventStore.append_to_stream(BankApp, stream_uuid, 0, to_event_data(initial_events))

# Start handler with :current - should ignore existing events
handler = start_supervised!({BankAccountBatchHandler, start_from: :current})

Wait.until(fn ->
Expand All @@ -53,8 +54,28 @@ defmodule Commanded.Event.BatchResetEventHandlerTest do

:ok = BankAccountBatchHandler.change_prefix("PREF_")

# Use a more robust reset approach with proper synchronization
ref = Process.monitor(handler)
send(handler, :reset)

# Wait for the reset message to be processed
receive do
{:DOWN, ^ref, :process, ^handler, _reason} ->
# Handler died, this shouldn't happen
flunk("Handler died during reset")
after
# Reset message should be processed by now
100 -> :ok
end

Process.demonitor(ref)

# Ensure reset completed and accounts are cleared
Wait.until(fn ->
assert BankAccountBatchHandler.current_accounts() == []
end)

# Add new event after reset
new_event = [%BankAccountOpened{account_number: "ACC1234", initial_balance: 1_000}]
:ok = EventStore.append_to_stream(BankApp, stream_uuid, 1, to_event_data(new_event))

Expand Down