Skip to content

Commit

Permalink
Make in-memory :any work without explict locks
Browse files Browse the repository at this point in the history
Guarantees
When there are many threads (or processes) writing concurrently (at the same time) to a stream with expected_version set to :any, all of those writes should succeed.
When you later try to read those events you from a stream, you don't have a guarantee about particular order you are going to get them in.
Example: If 3 processes A,B,C publish events to stream foo-1 at the same time, all of them should succeed. When you read events from stream foo-1 you will get events A,B,C or A,C,B or B,A,C or B,C,A or C,A,B or C,B,A.
Should never fail
When a single thread (or process) writes events A, B to a stream, it is guaranteed you will retrieve events A,B in that exact order when reading from a stream.

as in http://railseventstore.org/docs/expected_version/

We use lock (mutex) under the hood but that's not an issue. SQL DBs also
somewhere deep down might use locks to when updating (uniq) indexes
(which ActiveRecordRepository used).

So this more closely resembles production behavior of :any

Refs: #188
  • Loading branch information
paneq committed Feb 23, 2018
1 parent 89533e6 commit 6d72633
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion ruby_event_store/spec/in_memory_repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module RubyEventStore
RSpec.describe InMemoryRepository do
# There is no way to use in-memory adapter in a
# lock-free, unlimited concurrency way
let(:test_race_conditions_any) { false }
let(:test_race_conditions_any) { true }
let(:test_race_conditions_auto) { true }
let(:test_expected_version_auto) { true }
let(:test_link_events_to_stream) { true }
Expand Down

0 comments on commit 6d72633

Please sign in to comment.