Skip to content

Commit b38f2fc

Browse files
committed
fix: fixes a typo which blocks the correct behaviour of retryable_writes: true (#287)
1 parent 96e7d6a commit b38f2fc

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/mongo/session.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,9 @@ defmodule Mongo.Session do
393393
end
394394

395395
def init(topology, conn, address, server_session, wire_version, opts) do
396-
## in case of `:retryable_write` we need to inc the transaction id
396+
## in case of `:retryable_writes` we need to inc the transaction id
397397
server_session =
398-
case opts[:retryable_write] do
398+
case opts[:retryable_writes] do
399399
true -> ServerSession.next_txn_num(server_session)
400400
_ -> server_session
401401
end

test/mongo/retryable_writes_test.exs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,15 @@ defmodule Mongo.RetryableWritesTest do
4242

4343
assert [:delete | _] = EventCatcher.retry_write_events(catcher) |> Enum.map(fn event -> event.command_name end)
4444
end
45+
46+
test "retryable writes: replace one", %{pid: top} do
47+
coll = unique_collection()
48+
49+
assert {:ok, %Mongo.InsertOneResult{acknowledged: true, inserted_id: 42}} = Mongo.insert_one(top, coll, %{"_id" => 42, "name" => "Waldo"}, retryable_writes: true)
50+
assert %{"_id" => 42, "name" => "Waldo"} = Mongo.find_one(top, coll, %{"_id" => 42})
51+
assert {:ok, %Mongo.UpdateResult{acknowledged: true, matched_count: 1, modified_count: 1}} = Mongo.replace_one(top, coll, %{"_id" => 42}, %{"_id" => 42, "name" => "Greta"}, retryable_writes: true)
52+
assert %{"_id" => 42, "name" => "Greta"} = Mongo.find_one(top, coll, %{"_id" => 42})
53+
assert {:ok, %Mongo.UpdateResult{acknowledged: true, matched_count: 1, modified_count: 1}} = Mongo.replace_one(top, coll, %{"_id" => 42}, %{"_id" => 42, "name" => "Merlin"}, retryable_writes: true)
54+
assert %{"_id" => 42, "name" => "Merlin"} = Mongo.find_one(top, coll, %{"_id" => 42})
55+
end
4556
end

0 commit comments

Comments
 (0)