mongo 2.5.0.beta → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/lib/mongo/address.rb +1 -1
  5. data/lib/mongo/address/unix.rb +1 -1
  6. data/lib/mongo/auth/user.rb +0 -5
  7. data/lib/mongo/auth/user/view.rb +4 -4
  8. data/lib/mongo/bulk_write.rb +60 -32
  9. data/lib/mongo/client.rb +44 -8
  10. data/lib/mongo/cluster.rb +14 -12
  11. data/lib/mongo/cluster/periodic_executor.rb +106 -0
  12. data/lib/mongo/cluster/{cursor_reaper.rb → reapers/cursor_reaper.rb} +5 -37
  13. data/lib/mongo/cluster/reapers/socket_reaper.rb +59 -0
  14. data/lib/mongo/collection.rb +9 -6
  15. data/lib/mongo/collection/view.rb +2 -2
  16. data/lib/mongo/collection/view/builder/aggregation.rb +2 -1
  17. data/lib/mongo/collection/view/builder/find_command.rb +1 -1
  18. data/lib/mongo/collection/view/change_stream.rb +14 -1
  19. data/lib/mongo/collection/view/map_reduce.rb +30 -13
  20. data/lib/mongo/collection/view/readable.rb +5 -5
  21. data/lib/mongo/collection/view/writable.rb +98 -51
  22. data/lib/mongo/error.rb +3 -0
  23. data/lib/mongo/error/invalid_txt_record.rb +27 -0
  24. data/lib/mongo/error/invalid_uri.rb +7 -6
  25. data/lib/mongo/error/mismatched_domain.rb +27 -0
  26. data/lib/mongo/error/no_srv_records.rb +26 -0
  27. data/lib/mongo/error/unsupported_features.rb +0 -18
  28. data/lib/mongo/index/view.rb +2 -2
  29. data/lib/mongo/operation.rb +1 -0
  30. data/lib/mongo/operation/causally_consistent.rb +33 -0
  31. data/lib/mongo/operation/commands.rb +2 -1
  32. data/lib/mongo/operation/commands/aggregate.rb +2 -7
  33. data/lib/mongo/operation/commands/count.rb +27 -0
  34. data/lib/mongo/operation/commands/distinct.rb +27 -0
  35. data/lib/mongo/operation/commands/find.rb +3 -1
  36. data/lib/mongo/operation/commands/map_reduce.rb +1 -0
  37. data/lib/mongo/operation/commands/parallel_scan.rb +1 -0
  38. data/lib/mongo/operation/specifiable.rb +12 -0
  39. data/lib/mongo/operation/uses_command_op_msg.rb +36 -5
  40. data/lib/mongo/operation/write.rb +0 -5
  41. data/lib/mongo/operation/write/bulk/bulkable.rb +4 -8
  42. data/lib/mongo/operation/write/bulk/mergable.rb +2 -0
  43. data/lib/mongo/operation/write/command/create_index.rb +19 -0
  44. data/lib/mongo/operation/write/command/create_user.rb +19 -0
  45. data/lib/mongo/operation/write/command/delete.rb +1 -2
  46. data/lib/mongo/operation/write/command/drop_index.rb +19 -0
  47. data/lib/mongo/operation/write/command/insert.rb +1 -2
  48. data/lib/mongo/operation/write/command/remove_user.rb +19 -0
  49. data/lib/mongo/operation/write/command/update.rb +1 -2
  50. data/lib/mongo/operation/write/command/update_user.rb +19 -0
  51. data/lib/mongo/operation/write/write_command_enabled.rb +1 -3
  52. data/lib/mongo/protocol/compressed.rb +2 -1
  53. data/lib/mongo/protocol/serializers.rb +6 -6
  54. data/lib/mongo/retryable.rb +48 -5
  55. data/lib/mongo/server.rb +15 -0
  56. data/lib/mongo/server/connection.rb +21 -1
  57. data/lib/mongo/server/connection_pool.rb +3 -0
  58. data/lib/mongo/server/connection_pool/queue.rb +50 -5
  59. data/lib/mongo/server/description.rb +11 -3
  60. data/lib/mongo/server/description/features.rb +26 -7
  61. data/lib/mongo/session.rb +133 -6
  62. data/lib/mongo/session/server_session.rb +30 -0
  63. data/lib/mongo/session/session_pool.rb +20 -20
  64. data/lib/mongo/uri.rb +88 -44
  65. data/lib/mongo/uri/srv_protocol.rb +158 -0
  66. data/lib/mongo/version.rb +1 -1
  67. data/lib/mongo/write_concern/normalizable.rb +12 -0
  68. data/mongo.gemspec +1 -2
  69. data/spec/mongo/address_spec.rb +12 -0
  70. data/spec/mongo/auth/user/view_spec.rb +1 -5
  71. data/spec/mongo/bulk_write_spec.rb +232 -401
  72. data/spec/mongo/change_stream_examples_spec.rb +150 -0
  73. data/spec/mongo/client_spec.rb +142 -2
  74. data/spec/mongo/cluster/cursor_reaper_spec.rb +0 -70
  75. data/spec/mongo/cluster/socket_reaper_spec.rb +32 -0
  76. data/spec/mongo/cluster_spec.rb +11 -7
  77. data/spec/mongo/collection/view/aggregation_spec.rb +46 -1
  78. data/spec/mongo/collection/view/builder/find_command_spec.rb +15 -0
  79. data/spec/mongo/collection/view/change_stream_spec.rb +79 -12
  80. data/spec/mongo/collection/view/map_reduce_spec.rb +120 -4
  81. data/spec/mongo/collection/view/readable_spec.rb +23 -5
  82. data/spec/mongo/collection_spec.rb +292 -102
  83. data/spec/mongo/command_monitoring_spec.rb +26 -32
  84. data/spec/mongo/crud_spec.rb +1 -1
  85. data/spec/mongo/cursor_spec.rb +2 -3
  86. data/spec/mongo/database_spec.rb +30 -14
  87. data/spec/mongo/dns_seedlist_discovery_spec.rb +94 -0
  88. data/spec/mongo/grid/fs_bucket_spec.rb +1 -1
  89. data/spec/mongo/grid/stream/write_spec.rb +1 -1
  90. data/spec/mongo/index/view_spec.rb +8 -46
  91. data/spec/mongo/operation/write/bulk/delete_spec.rb +2 -2
  92. data/spec/mongo/operation/write/bulk/insert_spec.rb +2 -10
  93. data/spec/mongo/operation/write/{create_index_spec.rb → command/create_index_spec.rb} +2 -6
  94. data/spec/mongo/operation/write/command/delete_spec.rb +35 -7
  95. data/spec/mongo/operation/write/{drop_index_spec.rb → command/drop_index_spec.rb} +1 -1
  96. data/spec/mongo/operation/write/command/insert_spec.rb +37 -6
  97. data/spec/mongo/operation/write/{remove_user_spec.rb → command/remove_user_spec.rb} +2 -6
  98. data/spec/mongo/operation/write/command/update_spec.rb +34 -7
  99. data/spec/mongo/operation/write/{update_user_spec.rb → command/update_user_spec.rb} +1 -1
  100. data/spec/mongo/operation/write/create_user_spec.rb +1 -1
  101. data/spec/mongo/operation/write/delete_spec.rb +1 -1
  102. data/spec/mongo/operation/write/insert_spec.rb +2 -10
  103. data/spec/mongo/operation/write/update_spec.rb +3 -15
  104. data/spec/mongo/retryable_spec.rb +1 -1
  105. data/spec/mongo/retryable_writes_spec.rb +815 -0
  106. data/spec/mongo/server/connection_pool/queue_spec.rb +35 -2
  107. data/spec/mongo/server/connection_pool_spec.rb +234 -1
  108. data/spec/mongo/server/connection_spec.rb +10 -6
  109. data/spec/mongo/server/description/features_spec.rb +51 -37
  110. data/spec/mongo/server/description_spec.rb +6 -3
  111. data/spec/mongo/server_spec.rb +87 -0
  112. data/spec/mongo/session/server_session_spec.rb +43 -0
  113. data/spec/mongo/session/session_pool_spec.rb +63 -27
  114. data/spec/mongo/session_spec.rb +247 -0
  115. data/spec/mongo/shell_examples_spec.rb +2 -2
  116. data/spec/mongo/uri/srv_protocol_spec.rb +933 -0
  117. data/spec/mongo/uri_spec.rb +42 -3
  118. data/spec/mongo/write_concern/acknowledged_spec.rb +11 -0
  119. data/spec/mongo/write_concern/unacknowledged_spec.rb +11 -0
  120. data/spec/spec_helper.rb +11 -25
  121. data/spec/support/authorization.rb +2 -1
  122. data/spec/support/connection_string.rb +8 -4
  123. data/spec/support/crud.rb +38 -24
  124. data/spec/support/crud/write.rb +30 -3
  125. data/spec/support/crud_tests/read/aggregate-out.yml +21 -0
  126. data/spec/support/crud_tests/write/bulkWrite-arrayFilters.yml +44 -0
  127. data/spec/support/crud_tests/write/findOneAndUpdate-arrayFilters.yml +1 -1
  128. data/spec/support/crud_tests/write/insertMany.yml +1 -3
  129. data/spec/support/crud_tests/write/replaceOne.yml +1 -1
  130. data/spec/support/crud_tests/write/updateMany-arrayFilters.yml +1 -1
  131. data/spec/support/crud_tests/write/updateOne-arrayFilters.yml +1 -1
  132. data/spec/support/dns_seedlist_discovery_tests/longer-parent-in-return.yml +11 -0
  133. data/spec/support/dns_seedlist_discovery_tests/misformatted-option.yml +5 -0
  134. data/spec/support/dns_seedlist_discovery_tests/no-results.yml +5 -0
  135. data/spec/support/dns_seedlist_discovery_tests/not-enough-parts.yml +5 -0
  136. data/spec/support/dns_seedlist_discovery_tests/one-result-default-port.yml +10 -0
  137. data/spec/support/dns_seedlist_discovery_tests/one-txt-record-multiple-strings.yml +10 -0
  138. data/spec/support/dns_seedlist_discovery_tests/one-txt-record.yml +11 -0
  139. data/spec/support/dns_seedlist_discovery_tests/parent-part-mismatch1.yml +5 -0
  140. data/spec/support/dns_seedlist_discovery_tests/parent-part-mismatch2.yml +5 -0
  141. data/spec/support/dns_seedlist_discovery_tests/parent-part-mismatch3.yml +5 -0
  142. data/spec/support/dns_seedlist_discovery_tests/parent-part-mismatch4.yml +5 -0
  143. data/spec/support/dns_seedlist_discovery_tests/parent-part-mismatch5.yml +5 -0
  144. data/spec/support/dns_seedlist_discovery_tests/returned-parent-too-short.yml +5 -0
  145. data/spec/support/dns_seedlist_discovery_tests/returned-parent-wrong.yml +5 -0
  146. data/spec/support/dns_seedlist_discovery_tests/two-results-default-port.yml +11 -0
  147. data/spec/support/dns_seedlist_discovery_tests/two-results-nonstandard-port.yml +11 -0
  148. data/spec/support/dns_seedlist_discovery_tests/two-txt-records.yml +5 -0
  149. data/spec/support/dns_seedlist_discovery_tests/txt-record-not-allowed-option.yml +5 -0
  150. data/spec/support/dns_seedlist_discovery_tests/txt-record-with-overridden-ssl-option.yml +11 -0
  151. data/spec/support/dns_seedlist_discovery_tests/txt-record-with-overridden-uri-option.yml +11 -0
  152. data/spec/support/dns_seedlist_discovery_tests/txt-record-with-unallowed-option.yml +5 -0
  153. data/spec/support/dns_seedlist_discovery_tests/uri-with-port.yml +5 -0
  154. data/spec/support/dns_seedlist_discovery_tests/uri-with-two-hosts.yml +5 -0
  155. data/spec/support/retryable_writes_tests/bulkWrite.yml +305 -0
  156. data/spec/support/retryable_writes_tests/deleteOne.yml +51 -0
  157. data/spec/support/retryable_writes_tests/findOneAndDelete.yml +52 -0
  158. data/spec/support/retryable_writes_tests/findOneAndReplace.yml +57 -0
  159. data/spec/support/retryable_writes_tests/findOneAndUpdate.yml +56 -0
  160. data/spec/support/retryable_writes_tests/insertMany.yml +72 -0
  161. data/spec/support/retryable_writes_tests/insertOne.yml +55 -0
  162. data/spec/support/retryable_writes_tests/replaceOne.yml +60 -0
  163. data/spec/support/retryable_writes_tests/updateOne.yml +120 -0
  164. data/spec/support/shared/session.rb +525 -24
  165. metadata +437 -350
  166. metadata.gz.sig +0 -0
  167. data/lib/mongo/operation/commands/user_query.rb +0 -72
  168. data/lib/mongo/operation/write/create_index.rb +0 -67
  169. data/lib/mongo/operation/write/create_user.rb +0 -50
  170. data/lib/mongo/operation/write/drop_index.rb +0 -63
  171. data/lib/mongo/operation/write/remove_user.rb +0 -48
  172. data/lib/mongo/operation/write/update_user.rb +0 -50
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Mongo::Operation::Write::CreateIndex do
3
+ describe Mongo::Operation::Write::Command::CreateIndex do
4
4
 
5
5
  describe '#execute' do
6
6
 
@@ -49,15 +49,11 @@ describe Mongo::Operation::Write::CreateIndex do
49
49
  authorized_collection.indexes.drop_one('random_1')
50
50
  end
51
51
 
52
- it 'raises an exception', if: write_command_enabled? do
52
+ it 'raises an exception' do
53
53
  expect {
54
54
  second_operation.execute(authorized_primary)
55
55
  }.to raise_error(Mongo::Error::OperationFailure)
56
56
  end
57
-
58
- it 'does not raise an exception', unless: write_command_enabled? do
59
- expect(second_operation.execute(authorized_primary)).to be_successful
60
- end
61
57
  end
62
58
  end
63
59
  end
@@ -6,13 +6,15 @@ describe Mongo::Operation::Write::Command::Delete do
6
6
  Mongo::WriteConcern.get(WRITE_CONCERN)
7
7
  end
8
8
 
9
+ let(:session) { nil }
9
10
  let(:deletes) { [{:q => { :foo => 1 }, :limit => 1}] }
10
11
  let(:spec) do
11
12
  { :deletes => deletes,
12
13
  :db_name => authorized_collection.database.name,
13
14
  :coll_name => authorized_collection.name,
14
15
  :write_concern => write_concern,
15
- :ordered => true
16
+ :ordered => true,
17
+ :session => session
16
18
  }
17
19
  end
18
20
 
@@ -93,7 +95,8 @@ describe Mongo::Operation::Write::Command::Delete do
93
95
  delete: TEST_COLL,
94
96
  ordered: true,
95
97
  writeConcern: write_concern.options,
96
- '$db' => TEST_DB
98
+ '$db' => TEST_DB,
99
+ lsid: session.session_id
97
100
  }
98
101
  end
99
102
 
@@ -106,7 +109,11 @@ describe Mongo::Operation::Write::Command::Delete do
106
109
  }
107
110
  end
108
111
 
109
- context 'when the topology is sharded', if: sharded? && op_msg_enabled? do
112
+ let(:session) do
113
+ authorized_client.start_session
114
+ end
115
+
116
+ context 'when the topology is replica set or sharded', if: (replica_set? || sharded?) && op_msg_enabled? do
110
117
 
111
118
  let(:expected_global_args) do
112
119
  global_args.merge(Mongo::Operation::CLUSTER_TIME => authorized_client.cluster.cluster_time)
@@ -119,7 +126,7 @@ describe Mongo::Operation::Write::Command::Delete do
119
126
  end
120
127
  end
121
128
 
122
- context 'when the topology is not sharded', if: !sharded? && op_msg_enabled? do
129
+ context 'when the topology is standalone', if: standalone? && op_msg_enabled? do
123
130
 
124
131
  let(:expected_global_args) do
125
132
  global_args
@@ -130,6 +137,25 @@ describe Mongo::Operation::Write::Command::Delete do
130
137
  expect(Mongo::Protocol::Msg).to receive(:new).with([:none], {}, expected_global_args, expected_payload_1)
131
138
  op.send(:message, authorized_primary)
132
139
  end
140
+
141
+ context 'when an implicit session is created and the topology is then updated and the server does not support sessions' do
142
+
143
+ let(:expected_global_args) do
144
+ global_args.delete(:lsid)
145
+ global_args
146
+ end
147
+
148
+ before do
149
+ session.instance_variable_set(:@options, { implicit: true })
150
+ allow(authorized_primary.features).to receive(:sessions_enabled?).and_return(false)
151
+ end
152
+
153
+ it 'creates the correct OP_MSG message' do
154
+ authorized_client.command(ping:1)
155
+ expect(Mongo::Protocol::Msg).to receive(:new).with([:none], {}, expected_global_args, expected_payload_1)
156
+ op.send(:message, authorized_primary)
157
+ end
158
+ end
133
159
  end
134
160
 
135
161
  context 'when the write concern is 0' do
@@ -138,10 +164,11 @@ describe Mongo::Operation::Write::Command::Delete do
138
164
  Mongo::WriteConcern.get(w: 0)
139
165
  end
140
166
 
141
- context 'when the topology is sharded', if: sharded? && op_msg_enabled? do
167
+ context 'when the topology is replica set or sharded', if: (replica_set? || sharded?) && op_msg_enabled? do
142
168
 
143
169
  let(:expected_global_args) do
144
- global_args.merge(Mongo::Operation::CLUSTER_TIME => authorized_client.cluster.cluster_time)
170
+ global_args.delete(:lsid)
171
+ global_args.merge!(Mongo::Operation::CLUSTER_TIME => authorized_client.cluster.cluster_time)
145
172
  end
146
173
 
147
174
  it 'creates the correct OP_MSG message' do
@@ -151,9 +178,10 @@ describe Mongo::Operation::Write::Command::Delete do
151
178
  end
152
179
  end
153
180
 
154
- context 'when the topology is not sharded', if: !sharded? && op_msg_enabled? do
181
+ context 'when the topology is standalone', if: standalone? && op_msg_enabled? do
155
182
 
156
183
  let(:expected_global_args) do
184
+ global_args.delete(:lsid)
157
185
  global_args
158
186
  end
159
187
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Mongo::Operation::Write::DropIndex do
3
+ describe Mongo::Operation::Write::Command::DropIndex do
4
4
 
5
5
  describe '#execute' do
6
6
 
@@ -3,12 +3,14 @@ require 'spec_helper'
3
3
  describe Mongo::Operation::Write::Command::Insert do
4
4
 
5
5
  let(:documents) { [{ :_id => 1, :foo => 1 }] }
6
+ let(:session) { nil }
6
7
  let(:spec) do
7
8
  { :documents => documents,
8
9
  :db_name => authorized_collection.database.name,
9
10
  :coll_name => authorized_collection.name,
10
11
  :write_concern => write_concern,
11
- :ordered => true
12
+ :ordered => true,
13
+ :session => session
12
14
  }
13
15
  end
14
16
 
@@ -97,7 +99,8 @@ describe Mongo::Operation::Write::Command::Insert do
97
99
  insert: TEST_COLL,
98
100
  ordered: true,
99
101
  writeConcern: write_concern.options,
100
- '$db' => TEST_DB
102
+ '$db' => TEST_DB,
103
+ lsid: session.session_id
101
104
  }
102
105
  end
103
106
 
@@ -110,7 +113,11 @@ describe Mongo::Operation::Write::Command::Insert do
110
113
  }
111
114
  end
112
115
 
113
- context 'when the topology is sharded', if: sharded? && op_msg_enabled? do
116
+ let(:session) do
117
+ authorized_client.start_session
118
+ end
119
+
120
+ context 'when the topology is replica set or sharded', if: (replica_set? || sharded?) && op_msg_enabled? do
114
121
 
115
122
  let(:expected_global_args) do
116
123
  global_args.merge(Mongo::Operation::CLUSTER_TIME => authorized_client.cluster.cluster_time)
@@ -126,7 +133,7 @@ describe Mongo::Operation::Write::Command::Insert do
126
133
  end
127
134
  end
128
135
 
129
- context 'when the topology is not sharded', if: !sharded? && op_msg_enabled? do
136
+ context 'when the topology is standalone', if: standalone? && op_msg_enabled? do
130
137
 
131
138
  let(:expected_global_args) do
132
139
  global_args
@@ -140,6 +147,28 @@ describe Mongo::Operation::Write::Command::Insert do
140
147
  expected_payload_1)
141
148
  op.send(:message, authorized_primary)
142
149
  end
150
+
151
+ context 'when an implicit session is created and the topology is then updated and the server does not support sessions' do
152
+
153
+ let(:expected_global_args) do
154
+ global_args.delete(:lsid)
155
+ global_args
156
+ end
157
+
158
+ before do
159
+ session.instance_variable_set(:@options, { implicit: true })
160
+ allow(authorized_primary.features).to receive(:sessions_enabled?).and_return(false)
161
+ end
162
+
163
+ it 'creates the correct OP_MSG message' do
164
+ authorized_client.command(ping:1)
165
+ expect(Mongo::Protocol::Msg).to receive(:new).with([:none],
166
+ { validating_keys: true },
167
+ expected_global_args,
168
+ expected_payload_1)
169
+ op.send(:message, authorized_primary)
170
+ end
171
+ end
143
172
  end
144
173
 
145
174
  context 'when the write concern is 0' do
@@ -148,9 +177,10 @@ describe Mongo::Operation::Write::Command::Insert do
148
177
  Mongo::WriteConcern.get(w: 0)
149
178
  end
150
179
 
151
- context 'when the topology is sharded', if: sharded? && op_msg_enabled? do
180
+ context 'when the topology is replica set or sharded', if: (replica_set? || sharded?) && op_msg_enabled? do
152
181
 
153
182
  let(:expected_global_args) do
183
+ global_args.delete(:lsid)
154
184
  global_args.merge(Mongo::Operation::CLUSTER_TIME => authorized_client.cluster.cluster_time)
155
185
  end
156
186
 
@@ -164,9 +194,10 @@ describe Mongo::Operation::Write::Command::Insert do
164
194
  end
165
195
  end
166
196
 
167
- context 'when the topology is not sharded', if: !sharded? && op_msg_enabled? do
197
+ context 'when the topology is standalone', if: standalone? && op_msg_enabled? do
168
198
 
169
199
  let(:expected_global_args) do
200
+ global_args.delete(:lsid)
170
201
  global_args
171
202
  end
172
203
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Mongo::Operation::Write::RemoveUser do
3
+ describe Mongo::Operation::Write::Command::RemoveUser do
4
4
 
5
5
  describe '#execute' do
6
6
 
@@ -32,15 +32,11 @@ describe Mongo::Operation::Write::RemoveUser do
32
32
  operation.execute(root_authorized_primary)
33
33
  end
34
34
 
35
- it 'raises an exception', if: write_command_enabled? do
35
+ it 'raises an exception' do
36
36
  expect {
37
37
  operation.execute(root_authorized_primary)
38
38
  }.to raise_error(Mongo::Error::OperationFailure)
39
39
  end
40
-
41
- it 'does not raise an exception', unless: write_command_enabled? do
42
- expect(operation.execute(root_authorized_primary).written_count).to eq(0)
43
- end
44
40
  end
45
41
  end
46
42
  end
@@ -10,13 +10,14 @@ describe Mongo::Operation::Write::Command::Update do
10
10
  let(:write_concern) do
11
11
  Mongo::WriteConcern.get(WRITE_CONCERN)
12
12
  end
13
-
13
+ let(:session) { nil }
14
14
  let(:spec) do
15
15
  { :updates => updates,
16
16
  :db_name => TEST_DB,
17
17
  :coll_name => TEST_COLL,
18
18
  :write_concern => write_concern,
19
- :ordered => true
19
+ :ordered => true,
20
+ :session => session
20
21
  }
21
22
  end
22
23
 
@@ -100,7 +101,8 @@ describe Mongo::Operation::Write::Command::Update do
100
101
  update: TEST_COLL,
101
102
  ordered: true,
102
103
  writeConcern: write_concern.options,
103
- '$db' => TEST_DB
104
+ '$db' => TEST_DB,
105
+ lsid: session.session_id
104
106
  }
105
107
  end
106
108
 
@@ -113,7 +115,11 @@ describe Mongo::Operation::Write::Command::Update do
113
115
  }
114
116
  end
115
117
 
116
- context 'when the topology is sharded', if: sharded? && op_msg_enabled? do
118
+ let(:session) do
119
+ authorized_client.start_session
120
+ end
121
+
122
+ context 'when the topology is replica set or sharded', if: (replica_set? || sharded?) && op_msg_enabled? do
117
123
 
118
124
  let(:expected_global_args) do
119
125
  global_args.merge(Mongo::Operation::CLUSTER_TIME => authorized_client.cluster.cluster_time)
@@ -126,7 +132,7 @@ describe Mongo::Operation::Write::Command::Update do
126
132
  end
127
133
  end
128
134
 
129
- context 'when the topology is not sharded', if: !sharded? && op_msg_enabled? do
135
+ context 'when the topology is standalone', if: standalone? && op_msg_enabled? do
130
136
 
131
137
  let(:expected_global_args) do
132
138
  global_args
@@ -137,6 +143,25 @@ describe Mongo::Operation::Write::Command::Update do
137
143
  expect(Mongo::Protocol::Msg).to receive(:new).with([:none], {}, expected_global_args, expected_payload_1)
138
144
  op.send(:message, authorized_primary)
139
145
  end
146
+
147
+ context 'when an implicit session is created and the topology is then updated and the server does not support sessions' do
148
+
149
+ let(:expected_global_args) do
150
+ global_args.delete(:lsid)
151
+ global_args
152
+ end
153
+
154
+ before do
155
+ session.instance_variable_set(:@options, { implicit: true })
156
+ allow(authorized_primary.features).to receive(:sessions_enabled?).and_return(false)
157
+ end
158
+
159
+ it 'creates the correct OP_MSG message' do
160
+ authorized_client.command(ping:1)
161
+ expect(Mongo::Protocol::Msg).to receive(:new).with([:none], {}, expected_global_args, expected_payload_1)
162
+ op.send(:message, authorized_primary)
163
+ end
164
+ end
140
165
  end
141
166
 
142
167
  context 'when the write concern is 0' do
@@ -145,9 +170,10 @@ describe Mongo::Operation::Write::Command::Update do
145
170
  Mongo::WriteConcern.get(w: 0)
146
171
  end
147
172
 
148
- context 'when the topology is sharded', if: sharded? && op_msg_enabled? do
173
+ context 'when the topology is replica set or sharded', if: (replica_set? || sharded?) && op_msg_enabled? do
149
174
 
150
175
  let(:expected_global_args) do
176
+ global_args.delete(:lsid)
151
177
  global_args.merge(Mongo::Operation::CLUSTER_TIME => authorized_client.cluster.cluster_time)
152
178
  end
153
179
 
@@ -158,9 +184,10 @@ describe Mongo::Operation::Write::Command::Update do
158
184
  end
159
185
  end
160
186
 
161
- context 'when the topology is not sharded', if: !sharded? && op_msg_enabled? do
187
+ context 'when the topology is standalone', if: standalone? && op_msg_enabled? do
162
188
 
163
189
  let(:expected_global_args) do
190
+ global_args.delete(:lsid)
164
191
  global_args
165
192
  end
166
193
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Mongo::Operation::Write::UpdateUser do
3
+ describe Mongo::Operation::Write::Command::UpdateUser do
4
4
 
5
5
  describe '#execute' do
6
6
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Mongo::Operation::Write::CreateUser do
3
+ describe Mongo::Operation::Write::Command::CreateUser do
4
4
 
5
5
  describe '#execute' do
6
6
 
@@ -152,7 +152,7 @@ describe Mongo::Operation::Write::Delete do
152
152
  context 'when a delete fails' do
153
153
 
154
154
  let(:document) do
155
- failing_delete_doc
155
+ { q: { '$set' => { a: 1 } }, limit: 0 }
156
156
  end
157
157
 
158
158
  let(:result) do
@@ -115,14 +115,10 @@ describe Mongo::Operation::Write::Insert do
115
115
  insert.execute(authorized_primary)
116
116
  end
117
117
 
118
- it 'reports the correct written count', if: write_command_enabled? do
118
+ it 'reports the correct written count' do
119
119
  expect(response.written_count).to eq(1)
120
120
  end
121
121
 
122
- it 'reports the correct written count', unless: write_command_enabled? do
123
- expect(response.written_count).to eq(0)
124
- end
125
-
126
122
  it 'inserts the document into the collection' do
127
123
  expect(authorized_collection.find(_id: 1).to_a). to eq(documents)
128
124
  end
@@ -170,14 +166,10 @@ describe Mongo::Operation::Write::Insert do
170
166
  insert.execute(authorized_primary)
171
167
  end
172
168
 
173
- it 'reports the correct written count', if: write_command_enabled? do
169
+ it 'reports the correct written count' do
174
170
  expect(response.written_count).to eq(2)
175
171
  end
176
172
 
177
- it 'reports the correct written count', unless: write_command_enabled? do
178
- expect(response.written_count).to eq(0)
179
- end
180
-
181
173
  it 'inserts the documents into the collection' do
182
174
  expect(authorized_collection.find.to_a). to eq(documents)
183
175
  end
@@ -106,14 +106,10 @@ describe Mongo::Operation::Write::Update do
106
106
  expect(result.written_count).to eq(1)
107
107
  end
108
108
 
109
- it 'reports the modified count', if: write_command_enabled? do
109
+ it 'reports the modified count' do
110
110
  expect(result.modified_count).to eq(1)
111
111
  end
112
112
 
113
- it 'returns nil for the modified count', unless: write_command_enabled? do
114
- expect(result.modified_count).to be_nil
115
- end
116
-
117
113
  it 'reports the matched count' do
118
114
  expect(result.matched_count).to eq(1)
119
115
  end
@@ -162,14 +158,10 @@ describe Mongo::Operation::Write::Update do
162
158
  expect(result.written_count).to eq(2)
163
159
  end
164
160
 
165
- it 'reports the modified count', if: write_command_enabled? do
161
+ it 'reports the modified count' do
166
162
  expect(result.modified_count).to eq(2)
167
163
  end
168
164
 
169
- it 'returns nil for the modified count', unless: write_command_enabled? do
170
- expect(result.modified_count).to be_nil
171
- end
172
-
173
165
  it 'reports the matched count' do
174
166
  expect(result.matched_count).to eq(2)
175
167
  end
@@ -219,14 +211,10 @@ describe Mongo::Operation::Write::Update do
219
211
  expect(result.written_count).to eq(1)
220
212
  end
221
213
 
222
- it 'reports the modified count', if: write_command_enabled? do
214
+ it 'reports the modified count' do
223
215
  expect(result.modified_count).to eq(0)
224
216
  end
225
217
 
226
- it 'returns nil for the modified count', unless: write_command_enabled? do
227
- expect(result.modified_count).to be_nil
228
- end
229
-
230
218
  it 'reports the matched count' do
231
219
  expect(result.matched_count).to eq(0)
232
220
  end