mongo 2.6.4 → 2.7.0.rc0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (832) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/LICENSE +1 -1
  5. data/README.md +1 -1
  6. data/Rakefile +10 -11
  7. data/lib/mongo.rb +3 -1
  8. data/lib/mongo/active_support.rb +17 -0
  9. data/lib/mongo/address.rb +47 -39
  10. data/lib/mongo/address/ipv4.rb +1 -1
  11. data/lib/mongo/address/ipv6.rb +1 -1
  12. data/lib/mongo/address/unix.rb +1 -1
  13. data/lib/mongo/auth.rb +3 -8
  14. data/lib/mongo/auth/cr.rb +2 -2
  15. data/lib/mongo/auth/cr/conversation.rb +4 -4
  16. data/lib/mongo/auth/ldap.rb +2 -2
  17. data/lib/mongo/auth/ldap/conversation.rb +3 -3
  18. data/lib/mongo/auth/roles.rb +1 -1
  19. data/lib/mongo/auth/scram.rb +2 -2
  20. data/lib/mongo/auth/scram/conversation.rb +5 -5
  21. data/lib/mongo/auth/stringprep.rb +1 -1
  22. data/lib/mongo/auth/stringprep/profiles/sasl.rb +1 -1
  23. data/lib/mongo/auth/stringprep/tables.rb +1 -1
  24. data/lib/mongo/auth/user.rb +1 -1
  25. data/lib/mongo/auth/user/view.rb +2 -2
  26. data/lib/mongo/auth/x509.rb +2 -2
  27. data/lib/mongo/auth/x509/conversation.rb +3 -3
  28. data/lib/mongo/bson.rb +1 -1
  29. data/lib/mongo/bulk_write.rb +1 -1
  30. data/lib/mongo/bulk_write/combineable.rb +2 -2
  31. data/lib/mongo/bulk_write/ordered_combiner.rb +1 -1
  32. data/lib/mongo/bulk_write/result.rb +1 -1
  33. data/lib/mongo/bulk_write/result_combiner.rb +1 -1
  34. data/lib/mongo/bulk_write/transformable.rb +2 -2
  35. data/lib/mongo/bulk_write/unordered_combiner.rb +1 -1
  36. data/lib/mongo/bulk_write/validatable.rb +2 -2
  37. data/lib/mongo/client.rb +194 -82
  38. data/lib/mongo/cluster.rb +418 -298
  39. data/lib/mongo/cluster/periodic_executor.rb +10 -3
  40. data/lib/mongo/cluster/reapers/socket_reaper.rb +1 -1
  41. data/lib/mongo/cluster/sdam_flow.rb +481 -0
  42. data/lib/mongo/cluster/topology.rb +37 -16
  43. data/lib/mongo/cluster/topology/base.rb +218 -0
  44. data/lib/mongo/cluster/topology/no_replica_set_options.rb +34 -0
  45. data/lib/mongo/cluster/topology/replica_set_no_primary.rb +168 -0
  46. data/lib/mongo/cluster/topology/replica_set_with_primary.rb +27 -0
  47. data/lib/mongo/cluster/topology/sharded.rb +12 -115
  48. data/lib/mongo/cluster/topology/single.rb +18 -112
  49. data/lib/mongo/cluster/topology/unknown.rb +11 -152
  50. data/lib/mongo/collection.rb +2 -2
  51. data/lib/mongo/collection/view.rb +1 -1
  52. data/lib/mongo/collection/view/aggregation.rb +2 -2
  53. data/lib/mongo/collection/view/builder.rb +1 -1
  54. data/lib/mongo/collection/view/builder/aggregation.rb +1 -1
  55. data/lib/mongo/collection/view/builder/find_command.rb +1 -1
  56. data/lib/mongo/collection/view/builder/flags.rb +2 -2
  57. data/lib/mongo/collection/view/builder/map_reduce.rb +1 -1
  58. data/lib/mongo/collection/view/builder/modifiers.rb +2 -2
  59. data/lib/mongo/collection/view/builder/op_query.rb +1 -1
  60. data/lib/mongo/collection/view/change_stream.rb +4 -3
  61. data/lib/mongo/collection/view/change_stream/retryable.rb +1 -1
  62. data/lib/mongo/collection/view/explainable.rb +2 -2
  63. data/lib/mongo/collection/view/immutable.rb +2 -2
  64. data/lib/mongo/collection/view/iterable.rb +2 -2
  65. data/lib/mongo/collection/view/map_reduce.rb +2 -2
  66. data/lib/mongo/collection/view/readable.rb +3 -3
  67. data/lib/mongo/collection/view/writable.rb +2 -2
  68. data/lib/mongo/cursor.rb +8 -6
  69. data/lib/mongo/cursor/builder.rb +1 -1
  70. data/lib/mongo/cursor/builder/get_more_command.rb +1 -1
  71. data/lib/mongo/cursor/builder/kill_cursors_command.rb +1 -1
  72. data/lib/mongo/cursor/builder/op_get_more.rb +2 -2
  73. data/lib/mongo/cursor/builder/op_kill_cursors.rb +2 -2
  74. data/lib/mongo/database.rb +9 -4
  75. data/lib/mongo/database/view.rb +1 -1
  76. data/lib/mongo/dbref.rb +1 -1
  77. data/lib/mongo/error.rb +15 -2
  78. data/lib/mongo/error/bulk_write_error.rb +17 -1
  79. data/lib/mongo/error/change_stream_resumable.rb +1 -1
  80. data/lib/mongo/error/closed_stream.rb +1 -1
  81. data/lib/mongo/error/extra_file_chunk.rb +1 -1
  82. data/lib/mongo/error/file_not_found.rb +1 -1
  83. data/lib/mongo/error/handshake_error.rb +24 -0
  84. data/lib/mongo/error/insufficient_iteration_count.rb +1 -1
  85. data/lib/mongo/error/invalid_application_name.rb +1 -1
  86. data/lib/mongo/error/invalid_bulk_operation.rb +1 -1
  87. data/lib/mongo/error/invalid_bulk_operation_type.rb +1 -1
  88. data/lib/mongo/error/invalid_collection_name.rb +1 -1
  89. data/lib/mongo/error/invalid_database_name.rb +1 -1
  90. data/lib/mongo/error/invalid_document.rb +1 -1
  91. data/lib/mongo/error/invalid_file.rb +1 -1
  92. data/lib/mongo/error/invalid_file_revision.rb +1 -1
  93. data/lib/mongo/error/invalid_min_pool_size.rb +1 -1
  94. data/lib/mongo/error/invalid_nonce.rb +1 -1
  95. data/lib/mongo/error/invalid_read_option.rb +1 -1
  96. data/lib/mongo/error/invalid_replacement_document.rb +1 -1
  97. data/lib/mongo/error/invalid_server_preference.rb +1 -1
  98. data/lib/mongo/error/invalid_session.rb +1 -1
  99. data/lib/mongo/error/invalid_signature.rb +1 -1
  100. data/lib/mongo/error/invalid_transaction_operation.rb +2 -2
  101. data/lib/mongo/error/invalid_txt_record.rb +1 -1
  102. data/lib/mongo/error/invalid_update_document.rb +1 -1
  103. data/lib/mongo/error/invalid_uri.rb +1 -1
  104. data/lib/mongo/error/invalid_write_concern.rb +1 -1
  105. data/lib/mongo/error/lint_error.rb +1 -1
  106. data/lib/mongo/error/max_bson_size.rb +1 -1
  107. data/lib/mongo/error/max_message_size.rb +1 -1
  108. data/lib/mongo/error/mismatched_domain.rb +1 -1
  109. data/lib/mongo/error/missing_file_chunk.rb +1 -1
  110. data/lib/mongo/error/missing_resume_token.rb +1 -1
  111. data/lib/mongo/error/multi_index_drop.rb +1 -1
  112. data/lib/mongo/error/need_primary_server.rb +1 -1
  113. data/lib/mongo/error/no_server_available.rb +9 -5
  114. data/lib/mongo/error/no_srv_records.rb +1 -1
  115. data/lib/mongo/error/operation_failure.rb +2 -1
  116. data/lib/mongo/error/parser.rb +10 -1
  117. data/lib/mongo/error/session_ended.rb +27 -0
  118. data/lib/mongo/error/socket_error.rb +1 -1
  119. data/lib/mongo/error/socket_timeout_error.rb +1 -1
  120. data/lib/mongo/error/unchangeable_collection_option.rb +1 -1
  121. data/lib/mongo/error/unexpected_chunk_length.rb +1 -1
  122. data/lib/mongo/error/unexpected_response.rb +1 -1
  123. data/lib/mongo/error/unknown_payload_type.rb +1 -1
  124. data/lib/mongo/error/unsupported_array_filters.rb +1 -1
  125. data/lib/mongo/error/unsupported_collation.rb +1 -1
  126. data/lib/mongo/error/unsupported_features.rb +1 -1
  127. data/lib/mongo/error/unsupported_message_type.rb +1 -1
  128. data/lib/mongo/error/write_retryable.rb +1 -1
  129. data/lib/mongo/event.rb +3 -4
  130. data/lib/mongo/event/base.rb +6 -3
  131. data/lib/mongo/event/description_changed.rb +7 -27
  132. data/lib/mongo/event/listeners.rb +1 -1
  133. data/lib/mongo/event/publisher.rb +1 -1
  134. data/lib/mongo/event/subscriber.rb +1 -1
  135. data/lib/mongo/grid.rb +1 -1
  136. data/lib/mongo/grid/file.rb +1 -1
  137. data/lib/mongo/grid/file/chunk.rb +2 -2
  138. data/lib/mongo/grid/file/info.rb +8 -2
  139. data/lib/mongo/grid/fs_bucket.rb +1 -1
  140. data/lib/mongo/grid/stream.rb +1 -1
  141. data/lib/mongo/grid/stream/read.rb +1 -1
  142. data/lib/mongo/grid/stream/write.rb +1 -1
  143. data/lib/mongo/id.rb +64 -0
  144. data/lib/mongo/index.rb +1 -1
  145. data/lib/mongo/index/view.rb +1 -1
  146. data/lib/mongo/lint.rb +44 -5
  147. data/lib/mongo/loggable.rb +1 -1
  148. data/lib/mongo/logger.rb +1 -1
  149. data/lib/mongo/monitoring.rb +34 -10
  150. data/lib/mongo/monitoring/command_log_subscriber.rb +1 -1
  151. data/lib/mongo/monitoring/event.rb +4 -1
  152. data/lib/mongo/monitoring/event/command_failed.rb +1 -1
  153. data/lib/mongo/monitoring/event/command_started.rb +2 -2
  154. data/lib/mongo/monitoring/event/command_succeeded.rb +1 -1
  155. data/lib/mongo/monitoring/event/secure.rb +2 -2
  156. data/lib/mongo/monitoring/event/server_closed.rb +14 -1
  157. data/lib/mongo/monitoring/event/server_description_changed.rb +16 -1
  158. data/lib/mongo/monitoring/event/server_heartbeat_failed.rb +71 -0
  159. data/lib/mongo/monitoring/event/server_heartbeat_started.rb +55 -0
  160. data/lib/mongo/monitoring/event/server_heartbeat_succeeded.rb +63 -0
  161. data/lib/mongo/monitoring/event/server_opening.rb +8 -4
  162. data/lib/mongo/monitoring/event/topology_changed.rb +9 -6
  163. data/lib/mongo/monitoring/event/topology_closed.rb +14 -1
  164. data/lib/mongo/monitoring/event/topology_opening.rb +8 -4
  165. data/lib/mongo/monitoring/publishable.rb +3 -35
  166. data/lib/mongo/monitoring/sdam_log_subscriber.rb +1 -1
  167. data/lib/mongo/monitoring/server_closed_log_subscriber.rb +1 -1
  168. data/lib/mongo/monitoring/server_description_changed_log_subscriber.rb +1 -1
  169. data/lib/mongo/monitoring/server_opening_log_subscriber.rb +1 -1
  170. data/lib/mongo/monitoring/topology_changed_log_subscriber.rb +4 -4
  171. data/lib/mongo/monitoring/topology_closed_log_subscriber.rb +30 -0
  172. data/lib/mongo/monitoring/topology_opening_log_subscriber.rb +2 -2
  173. data/lib/mongo/operation.rb +8 -0
  174. data/lib/mongo/operation/aggregate.rb +3 -20
  175. data/lib/mongo/operation/aggregate/command.rb +1 -1
  176. data/lib/mongo/operation/aggregate/op_msg.rb +4 -30
  177. data/lib/mongo/operation/aggregate/result.rb +2 -2
  178. data/lib/mongo/operation/collections_info.rb +1 -1
  179. data/lib/mongo/operation/collections_info/result.rb +2 -2
  180. data/lib/mongo/operation/command.rb +2 -19
  181. data/lib/mongo/operation/command/command.rb +1 -1
  182. data/lib/mongo/operation/command/op_msg.rb +2 -27
  183. data/lib/mongo/operation/count.rb +2 -19
  184. data/lib/mongo/operation/count/command.rb +1 -1
  185. data/lib/mongo/operation/count/op_msg.rb +2 -11
  186. data/lib/mongo/operation/create.rb +2 -19
  187. data/lib/mongo/operation/create/command.rb +1 -1
  188. data/lib/mongo/operation/create/op_msg.rb +3 -20
  189. data/lib/mongo/operation/create_index.rb +2 -19
  190. data/lib/mongo/operation/create_index/command.rb +1 -1
  191. data/lib/mongo/operation/create_index/op_msg.rb +3 -18
  192. data/lib/mongo/operation/create_user.rb +2 -19
  193. data/lib/mongo/operation/create_user/command.rb +1 -1
  194. data/lib/mongo/operation/create_user/op_msg.rb +3 -18
  195. data/lib/mongo/operation/delete.rb +1 -1
  196. data/lib/mongo/operation/delete/bulk_result.rb +2 -2
  197. data/lib/mongo/operation/delete/command.rb +1 -1
  198. data/lib/mongo/operation/delete/legacy.rb +1 -1
  199. data/lib/mongo/operation/delete/op_msg.rb +5 -23
  200. data/lib/mongo/operation/delete/result.rb +2 -2
  201. data/lib/mongo/operation/distinct.rb +2 -19
  202. data/lib/mongo/operation/distinct/command.rb +1 -1
  203. data/lib/mongo/operation/distinct/op_msg.rb +3 -20
  204. data/lib/mongo/operation/drop.rb +2 -19
  205. data/lib/mongo/operation/drop/command.rb +1 -1
  206. data/lib/mongo/operation/drop/op_msg.rb +3 -20
  207. data/lib/mongo/operation/drop_database.rb +2 -19
  208. data/lib/mongo/operation/drop_database/command.rb +1 -1
  209. data/lib/mongo/operation/drop_database/op_msg.rb +3 -20
  210. data/lib/mongo/operation/drop_index.rb +2 -19
  211. data/lib/mongo/operation/drop_index/command.rb +1 -1
  212. data/lib/mongo/operation/drop_index/op_msg.rb +3 -18
  213. data/lib/mongo/operation/explain.rb +2 -21
  214. data/lib/mongo/operation/explain/command.rb +1 -1
  215. data/lib/mongo/operation/explain/legacy.rb +1 -1
  216. data/lib/mongo/operation/explain/op_msg.rb +4 -30
  217. data/lib/mongo/operation/explain/result.rb +2 -2
  218. data/lib/mongo/operation/find.rb +2 -21
  219. data/lib/mongo/operation/find/command.rb +1 -1
  220. data/lib/mongo/operation/find/legacy.rb +1 -1
  221. data/lib/mongo/operation/find/legacy/result.rb +2 -2
  222. data/lib/mongo/operation/find/op_msg.rb +6 -30
  223. data/lib/mongo/operation/find/result.rb +2 -2
  224. data/lib/mongo/operation/get_more.rb +2 -11
  225. data/lib/mongo/operation/get_more/command.rb +1 -1
  226. data/lib/mongo/operation/get_more/legacy.rb +1 -1
  227. data/lib/mongo/operation/get_more/op_msg.rb +6 -30
  228. data/lib/mongo/operation/get_more/result.rb +2 -2
  229. data/lib/mongo/operation/indexes.rb +2 -21
  230. data/lib/mongo/operation/indexes/command.rb +1 -1
  231. data/lib/mongo/operation/indexes/legacy.rb +1 -1
  232. data/lib/mongo/operation/indexes/op_msg.rb +4 -30
  233. data/lib/mongo/operation/indexes/result.rb +2 -2
  234. data/lib/mongo/operation/insert.rb +1 -1
  235. data/lib/mongo/operation/insert/bulk_result.rb +2 -2
  236. data/lib/mongo/operation/insert/command.rb +1 -1
  237. data/lib/mongo/operation/insert/legacy.rb +1 -1
  238. data/lib/mongo/operation/insert/op_msg.rb +10 -23
  239. data/lib/mongo/operation/insert/result.rb +2 -2
  240. data/lib/mongo/operation/kill_cursors.rb +2 -21
  241. data/lib/mongo/operation/kill_cursors/command.rb +1 -1
  242. data/lib/mongo/operation/kill_cursors/legacy.rb +1 -1
  243. data/lib/mongo/operation/kill_cursors/op_msg.rb +3 -20
  244. data/lib/mongo/operation/list_collections.rb +2 -19
  245. data/lib/mongo/operation/list_collections/command.rb +1 -1
  246. data/lib/mongo/operation/list_collections/op_msg.rb +4 -28
  247. data/lib/mongo/operation/list_collections/result.rb +2 -2
  248. data/lib/mongo/operation/map_reduce.rb +2 -19
  249. data/lib/mongo/operation/map_reduce/command.rb +1 -1
  250. data/lib/mongo/operation/map_reduce/op_msg.rb +4 -30
  251. data/lib/mongo/operation/map_reduce/result.rb +2 -2
  252. data/lib/mongo/operation/op_msg_base.rb +30 -0
  253. data/lib/mongo/operation/parallel_scan.rb +2 -19
  254. data/lib/mongo/operation/parallel_scan/command.rb +1 -1
  255. data/lib/mongo/operation/parallel_scan/op_msg.rb +4 -28
  256. data/lib/mongo/operation/parallel_scan/result.rb +2 -2
  257. data/lib/mongo/operation/remove_user.rb +2 -19
  258. data/lib/mongo/operation/remove_user/command.rb +1 -1
  259. data/lib/mongo/operation/remove_user/op_msg.rb +3 -18
  260. data/lib/mongo/operation/result.rb +14 -2
  261. data/lib/mongo/operation/shared/bypass_document_validation.rb +1 -1
  262. data/lib/mongo/operation/shared/causal_consistency_supported.rb +14 -6
  263. data/lib/mongo/operation/shared/executable.rb +10 -3
  264. data/lib/mongo/operation/shared/executable_no_validate.rb +30 -0
  265. data/lib/mongo/operation/shared/executable_transaction_label.rb +34 -0
  266. data/lib/mongo/operation/shared/idable.rb +1 -1
  267. data/lib/mongo/operation/shared/limited.rb +1 -1
  268. data/lib/mongo/operation/shared/object_id_generator.rb +1 -1
  269. data/lib/mongo/operation/shared/op_msg_or_command.rb +42 -0
  270. data/lib/mongo/operation/shared/op_msg_or_find_command.rb +45 -0
  271. data/lib/mongo/operation/shared/op_msg_or_list_indexes_command.rb +45 -0
  272. data/lib/mongo/operation/shared/polymorphic_lookup.rb +33 -0
  273. data/lib/mongo/operation/shared/polymorphic_result.rb +32 -0
  274. data/lib/mongo/operation/shared/read_preference_supported.rb +1 -1
  275. data/lib/mongo/operation/shared/result/aggregatable.rb +2 -2
  276. data/lib/mongo/operation/shared/sessions_supported.rb +24 -4
  277. data/lib/mongo/operation/shared/specifiable.rb +5 -3
  278. data/lib/mongo/operation/shared/write.rb +1 -1
  279. data/lib/mongo/operation/shared/write_concern_supported.rb +1 -1
  280. data/lib/mongo/operation/update.rb +1 -1
  281. data/lib/mongo/operation/update/bulk_result.rb +2 -2
  282. data/lib/mongo/operation/update/command.rb +1 -1
  283. data/lib/mongo/operation/update/legacy.rb +1 -1
  284. data/lib/mongo/operation/update/legacy/result.rb +2 -2
  285. data/lib/mongo/operation/update/op_msg.rb +5 -23
  286. data/lib/mongo/operation/update/result.rb +2 -2
  287. data/lib/mongo/operation/update_user.rb +2 -19
  288. data/lib/mongo/operation/update_user/command.rb +1 -1
  289. data/lib/mongo/operation/update_user/op_msg.rb +3 -18
  290. data/lib/mongo/operation/users_info.rb +2 -19
  291. data/lib/mongo/operation/users_info/command.rb +1 -1
  292. data/lib/mongo/operation/users_info/op_msg.rb +4 -28
  293. data/lib/mongo/operation/users_info/result.rb +2 -2
  294. data/lib/mongo/options.rb +1 -1
  295. data/lib/mongo/options/mapper.rb +10 -3
  296. data/lib/mongo/options/redacted.rb +1 -1
  297. data/lib/mongo/protocol/bit_vector.rb +1 -1
  298. data/lib/mongo/protocol/compressed.rb +2 -2
  299. data/lib/mongo/protocol/delete.rb +1 -1
  300. data/lib/mongo/protocol/get_more.rb +1 -1
  301. data/lib/mongo/protocol/insert.rb +1 -1
  302. data/lib/mongo/protocol/kill_cursors.rb +1 -1
  303. data/lib/mongo/protocol/message.rb +4 -9
  304. data/lib/mongo/protocol/msg.rb +2 -2
  305. data/lib/mongo/protocol/query.rb +1 -1
  306. data/lib/mongo/protocol/registry.rb +1 -1
  307. data/lib/mongo/protocol/reply.rb +1 -1
  308. data/lib/mongo/protocol/serializers.rb +1 -1
  309. data/lib/mongo/protocol/update.rb +1 -1
  310. data/lib/mongo/retryable.rb +40 -14
  311. data/lib/mongo/semaphore.rb +46 -0
  312. data/lib/mongo/server.rb +159 -44
  313. data/lib/mongo/{cluster → server}/app_metadata.rb +26 -13
  314. data/lib/mongo/server/connectable.rb +9 -13
  315. data/lib/mongo/server/connection.rb +143 -71
  316. data/lib/mongo/server/connection_pool.rb +25 -20
  317. data/lib/mongo/server/connection_pool/queue.rb +163 -46
  318. data/lib/mongo/server/context.rb +13 -13
  319. data/lib/mongo/server/description.rb +93 -48
  320. data/lib/mongo/server/description/features.rb +22 -3
  321. data/lib/mongo/server/monitor.rb +143 -74
  322. data/lib/mongo/server/monitor/app_metadata.rb +34 -0
  323. data/lib/mongo/server/monitor/connection.rb +42 -26
  324. data/lib/mongo/server/round_trip_time_averager.rb +64 -0
  325. data/lib/mongo/server_selector.rb +1 -1
  326. data/lib/mongo/server_selector/nearest.rb +1 -1
  327. data/lib/mongo/server_selector/primary.rb +1 -1
  328. data/lib/mongo/server_selector/primary_preferred.rb +1 -1
  329. data/lib/mongo/server_selector/secondary.rb +1 -1
  330. data/lib/mongo/server_selector/secondary_preferred.rb +1 -1
  331. data/lib/mongo/server_selector/selectable.rb +38 -13
  332. data/lib/mongo/session.rb +189 -40
  333. data/lib/mongo/session/server_session.rb +18 -7
  334. data/lib/mongo/session/session_pool.rb +1 -1
  335. data/lib/mongo/socket.rb +1 -1
  336. data/lib/mongo/socket/ssl.rb +46 -7
  337. data/lib/mongo/socket/tcp.rb +1 -1
  338. data/lib/mongo/socket/unix.rb +1 -1
  339. data/lib/mongo/uri.rb +304 -18
  340. data/lib/mongo/uri/srv_protocol.rb +1 -1
  341. data/lib/mongo/version.rb +2 -2
  342. data/lib/mongo/write_concern.rb +6 -6
  343. data/lib/mongo/write_concern/acknowledged.rb +2 -4
  344. data/lib/mongo/write_concern/{normalizable.rb → base.rb} +5 -6
  345. data/lib/mongo/write_concern/unacknowledged.rb +2 -4
  346. data/mongo.gemspec +1 -1
  347. data/spec/enterprise_auth/kerberos_spec.rb +57 -0
  348. data/spec/integration/bulk_insert_spec.rb +4 -2
  349. data/spec/integration/change_stream_examples_spec.rb +5 -6
  350. data/spec/integration/change_stream_spec.rb +17 -14
  351. data/spec/integration/client_connectivity_spec.rb +38 -0
  352. data/spec/integration/client_construction_spec.rb +94 -0
  353. data/spec/integration/command_monitoring_spec.rb +18 -30
  354. data/spec/integration/connect_single_rs_name_spec.rb +67 -0
  355. data/spec/integration/connection_spec.rb +209 -0
  356. data/spec/integration/cursor_reaping_spec.rb +95 -0
  357. data/spec/integration/docs_examples_spec.rb +6 -5
  358. data/spec/integration/heartbeat_events_spec.rb +116 -0
  359. data/spec/integration/retryable_writes_spec.rb +18 -8
  360. data/spec/integration/sdam_events_spec.rb +47 -0
  361. data/spec/integration/server_description_spec.rb +48 -0
  362. data/spec/integration/time_zone_querying_spec.rb +52 -0
  363. data/spec/lite_spec_helper.rb +74 -19
  364. data/spec/mongo/address_spec.rb +17 -7
  365. data/spec/mongo/auth/cr_spec.rb +8 -5
  366. data/spec/mongo/auth/ldap_spec.rb +9 -6
  367. data/spec/mongo/auth/scram/conversation_spec.rb +4 -1
  368. data/spec/mongo/auth/scram/negotiation_spec.rb +68 -110
  369. data/spec/mongo/auth/scram_spec.rb +8 -5
  370. data/spec/mongo/auth/user/view_spec.rb +5 -5
  371. data/spec/mongo/auth/x509_spec.rb +9 -6
  372. data/spec/mongo/bulk_write_spec.rb +32 -22
  373. data/spec/mongo/client_construction_spec.rb +1164 -0
  374. data/spec/mongo/client_spec.rb +62 -1000
  375. data/spec/mongo/cluster/cursor_reaper_spec.rb +2 -2
  376. data/spec/mongo/cluster/topology/replica_set_spec.rb +186 -251
  377. data/spec/mongo/cluster/topology/sharded_spec.rb +48 -50
  378. data/spec/mongo/cluster/topology/single_spec.rb +62 -22
  379. data/spec/mongo/cluster/topology/unknown_spec.rb +30 -115
  380. data/spec/mongo/cluster/topology_spec.rb +111 -13
  381. data/spec/mongo/cluster_spec.rb +195 -246
  382. data/spec/mongo/collection/view/aggregation_spec.rb +7 -8
  383. data/spec/mongo/collection/view/change_stream_spec.rb +18 -7
  384. data/spec/mongo/collection/view/explainable_spec.rb +1 -1
  385. data/spec/mongo/collection/view/immutable_spec.rb +1 -1
  386. data/spec/mongo/collection/view/map_reduce_spec.rb +7 -8
  387. data/spec/mongo/collection/view/readable_spec.rb +7 -8
  388. data/spec/mongo/collection/view/writable_spec.rb +1 -1
  389. data/spec/mongo/collection/view_spec.rb +2 -5
  390. data/spec/mongo/collection_spec.rb +41 -48
  391. data/spec/mongo/cursor/builder/get_more_command_spec.rb +1 -1
  392. data/spec/mongo/cursor/builder/op_get_more_spec.rb +1 -1
  393. data/spec/mongo/cursor_spec.rb +51 -25
  394. data/spec/mongo/database_spec.rb +25 -37
  395. data/spec/mongo/error/no_server_available_spec.rb +22 -0
  396. data/spec/mongo/error/operation_failure_spec.rb +70 -0
  397. data/spec/mongo/error/parser_spec.rb +44 -10
  398. data/spec/mongo/grid/file/info_spec.rb +3 -3
  399. data/spec/mongo/grid/fs_bucket_spec.rb +18 -53
  400. data/spec/mongo/grid/stream/read_spec.rb +9 -15
  401. data/spec/mongo/grid/stream/write_spec.rb +11 -23
  402. data/spec/mongo/id_spec.rb +35 -0
  403. data/spec/mongo/index/view_spec.rb +11 -72
  404. data/spec/mongo/lint_spec.rb +76 -0
  405. data/spec/mongo/monitoring/event/command_failed_spec.rb +1 -1
  406. data/spec/mongo/monitoring/event/command_started_spec.rb +1 -1
  407. data/spec/mongo/monitoring/event/command_succeeded_spec.rb +1 -1
  408. data/spec/mongo/monitoring/event/secure_spec.rb +1 -1
  409. data/spec/mongo/monitoring/event/server_closed_spec.rb +35 -0
  410. data/spec/mongo/monitoring/event/server_description_changed_spec.rb +38 -0
  411. data/spec/mongo/monitoring/event/server_heartbeat_failed_spec.rb +31 -0
  412. data/spec/mongo/monitoring/event/server_heartbeat_started_spec.rb +31 -0
  413. data/spec/mongo/monitoring/event/server_heartbeat_succeeded_spec.rb +31 -0
  414. data/spec/mongo/monitoring/event/server_opening_spec.rb +35 -0
  415. data/spec/mongo/monitoring/event/topology_changed_spec.rb +41 -0
  416. data/spec/mongo/monitoring/event/topology_closed_spec.rb +35 -0
  417. data/spec/mongo/monitoring/event/topology_opening_spec.rb +35 -0
  418. data/spec/mongo/monitoring_spec.rb +2 -2
  419. data/spec/mongo/operation/aggregate_spec.rb +2 -2
  420. data/spec/mongo/operation/collections_info_spec.rb +2 -2
  421. data/spec/mongo/operation/command_spec.rb +1 -1
  422. data/spec/mongo/operation/create_index_spec.rb +8 -11
  423. data/spec/mongo/operation/create_user_spec.rb +6 -3
  424. data/spec/mongo/operation/delete/bulk_spec.rb +21 -12
  425. data/spec/mongo/operation/delete/command_spec.rb +3 -2
  426. data/spec/mongo/operation/delete/op_msg_spec.rb +32 -17
  427. data/spec/mongo/operation/delete_spec.rb +21 -10
  428. data/spec/mongo/operation/drop_index_spec.rb +5 -2
  429. data/spec/mongo/operation/find/legacy_spec.rb +3 -2
  430. data/spec/mongo/operation/get_more_spec.rb +2 -2
  431. data/spec/mongo/operation/indexes_spec.rb +3 -2
  432. data/spec/mongo/operation/insert/bulk_spec.rb +13 -3
  433. data/spec/mongo/operation/insert/command_spec.rb +3 -2
  434. data/spec/mongo/operation/insert/op_msg_spec.rb +34 -18
  435. data/spec/mongo/operation/insert_spec.rb +7 -6
  436. data/spec/mongo/operation/kill_cursors_spec.rb +2 -2
  437. data/spec/mongo/operation/map_reduce_spec.rb +2 -2
  438. data/spec/mongo/operation/remove_user_spec.rb +6 -2
  439. data/spec/mongo/operation/result_spec.rb +6 -3
  440. data/spec/mongo/operation/update/bulk_spec.rb +3 -3
  441. data/spec/mongo/operation/update/command_spec.rb +8 -7
  442. data/spec/mongo/operation/update/op_msg_spec.rb +36 -21
  443. data/spec/mongo/operation/update_spec.rb +8 -6
  444. data/spec/mongo/operation/update_user_spec.rb +6 -6
  445. data/spec/mongo/protocol/compressed_spec.rb +3 -2
  446. data/spec/mongo/protocol/delete_spec.rb +1 -1
  447. data/spec/mongo/protocol/get_more_spec.rb +1 -1
  448. data/spec/mongo/protocol/insert_spec.rb +1 -1
  449. data/spec/mongo/protocol/kill_cursors_spec.rb +1 -1
  450. data/spec/mongo/protocol/msg_spec.rb +14 -13
  451. data/spec/mongo/protocol/query_spec.rb +1 -1
  452. data/spec/mongo/protocol/update_spec.rb +1 -1
  453. data/spec/mongo/retryable_spec.rb +84 -0
  454. data/spec/mongo/{cluster → server}/app_metadata_spec.rb +15 -3
  455. data/spec/mongo/server/connection_auth_spec.rb +114 -0
  456. data/spec/mongo/server/connection_pool/queue_spec.rb +146 -30
  457. data/spec/mongo/server/connection_pool_spec.rb +11 -12
  458. data/spec/mongo/server/connection_spec.rb +339 -152
  459. data/spec/mongo/server/description_query_methods_spec.rb +288 -0
  460. data/spec/mongo/server/description_spec.rb +63 -240
  461. data/spec/mongo/server/monitor/app_metadata_spec.rb +16 -0
  462. data/spec/mongo/server/monitor/connection_spec.rb +31 -28
  463. data/spec/mongo/server/monitor_spec.rb +61 -32
  464. data/spec/mongo/server/round_trip_time_averager_spec.rb +43 -0
  465. data/spec/mongo/server_selector_spec.rb +106 -1
  466. data/spec/mongo/server_spec.rb +31 -12
  467. data/spec/mongo/session/session_pool_spec.rb +3 -1
  468. data/spec/mongo/session_spec.rb +64 -2
  469. data/spec/mongo/session_transaction_spec.rb +64 -0
  470. data/spec/mongo/socket/ssl_spec.rb +86 -10
  471. data/spec/mongo/uri/srv_protocol_spec.rb +40 -40
  472. data/spec/mongo/uri_spec.rb +74 -38
  473. data/spec/spec_helper.rb +39 -64
  474. data/spec/spec_tests/connection_string_spec.rb +4 -32
  475. data/spec/spec_tests/crud_spec.rb +12 -2
  476. data/spec/{support/change_streams_tests → spec_tests/data/change_streams}/change-streams-errors.yml +0 -0
  477. data/spec/{support/change_streams_tests → spec_tests/data/change_streams}/change-streams.yml +0 -0
  478. data/spec/{support → spec_tests/data}/command_monitoring/bulkWrite.yml +0 -0
  479. data/spec/{support → spec_tests/data}/command_monitoring/command.yml +0 -0
  480. data/spec/{support → spec_tests/data}/command_monitoring/deleteMany.yml +0 -0
  481. data/spec/{support → spec_tests/data}/command_monitoring/deleteOne.yml +0 -0
  482. data/spec/{support → spec_tests/data}/command_monitoring/find.yml +0 -0
  483. data/spec/{support → spec_tests/data}/command_monitoring/insertMany.yml +0 -0
  484. data/spec/{support → spec_tests/data}/command_monitoring/insertOne.yml +0 -0
  485. data/spec/{support → spec_tests/data}/command_monitoring/unacknowledgedBulkWrite.yml +0 -0
  486. data/spec/{support → spec_tests/data}/command_monitoring/updateMany.yml +0 -0
  487. data/spec/{support → spec_tests/data}/command_monitoring/updateOne.yml +0 -0
  488. data/spec/{support/connection_string_tests → spec_tests/data/connection_string}/invalid-uris.yml +0 -0
  489. data/spec/{support/connection_string_tests → spec_tests/data/connection_string}/valid-auth.yml +0 -0
  490. data/spec/{support/connection_string_tests → spec_tests/data/connection_string}/valid-db-with-dotted-name.yml +0 -0
  491. data/spec/{support/connection_string_tests → spec_tests/data/connection_string}/valid-host_identifiers.yml +0 -0
  492. data/spec/{support/connection_string_tests → spec_tests/data/connection_string}/valid-options.yml +0 -0
  493. data/spec/{support/connection_string_tests → spec_tests/data/connection_string}/valid-unix_socket-absolute.yml +0 -0
  494. data/spec/{support/connection_string_tests → spec_tests/data/connection_string}/valid-unix_socket-relative.yml +0 -0
  495. data/spec/{support/connection_string_tests → spec_tests/data/connection_string}/valid-warnings.yml +0 -0
  496. data/spec/{support/crud_tests → spec_tests/data/crud}/read/aggregate-collation.yml +0 -0
  497. data/spec/{support/crud_tests → spec_tests/data/crud}/read/aggregate-out.yml +6 -6
  498. data/spec/{support/crud_tests → spec_tests/data/crud}/read/aggregate.yml +0 -0
  499. data/spec/{support/crud_tests → spec_tests/data/crud}/read/count-collation.yml +0 -0
  500. data/spec/{support/crud_tests → spec_tests/data/crud}/read/count.yml +0 -0
  501. data/spec/{support/crud_tests → spec_tests/data/crud}/read/distinct-collation.yml +0 -0
  502. data/spec/{support/crud_tests → spec_tests/data/crud}/read/distinct.yml +0 -0
  503. data/spec/{support/crud_tests → spec_tests/data/crud}/read/find-collation.yml +0 -0
  504. data/spec/{support/crud_tests → spec_tests/data/crud}/read/find.yml +0 -0
  505. data/spec/{support/crud_tests → spec_tests/data/crud}/write/bulkWrite-arrayFilters.yml +0 -0
  506. data/spec/{support/crud_tests → spec_tests/data/crud}/write/deleteMany-collation.yml +0 -0
  507. data/spec/{support/crud_tests → spec_tests/data/crud}/write/deleteMany.yml +0 -0
  508. data/spec/{support/crud_tests → spec_tests/data/crud}/write/deleteOne-collation.yml +0 -0
  509. data/spec/{support/crud_tests → spec_tests/data/crud}/write/deleteOne.yml +0 -0
  510. data/spec/{support/crud_tests → spec_tests/data/crud}/write/findOneAndDelete-collation.yml +0 -0
  511. data/spec/{support/crud_tests → spec_tests/data/crud}/write/findOneAndDelete.yml +0 -0
  512. data/spec/{support/crud_tests → spec_tests/data/crud}/write/findOneAndReplace-collation.yml +0 -0
  513. data/spec/{support/crud_tests → spec_tests/data/crud}/write/findOneAndReplace-upsert.yml +0 -0
  514. data/spec/{support/crud_tests → spec_tests/data/crud}/write/findOneAndReplace-upsert_pre_2.6.yml +0 -0
  515. data/spec/{support/crud_tests → spec_tests/data/crud}/write/findOneAndReplace.yml +0 -0
  516. data/spec/{support/crud_tests → spec_tests/data/crud}/write/findOneAndUpdate-arrayFilters.yml +0 -0
  517. data/spec/{support/crud_tests → spec_tests/data/crud}/write/findOneAndUpdate-collation.yml +0 -0
  518. data/spec/{support/crud_tests → spec_tests/data/crud}/write/findOneAndUpdate.yml +0 -0
  519. data/spec/{support/crud_tests → spec_tests/data/crud}/write/insertMany.yml +0 -0
  520. data/spec/{support/crud_tests → spec_tests/data/crud}/write/insertOne.yml +0 -0
  521. data/spec/{support/crud_tests → spec_tests/data/crud}/write/replaceOne-collation.yml +0 -0
  522. data/spec/{support/crud_tests → spec_tests/data/crud}/write/replaceOne-pre_2.6.yml +0 -0
  523. data/spec/{support/crud_tests → spec_tests/data/crud}/write/replaceOne-upsert.yml +0 -0
  524. data/spec/{support/crud_tests → spec_tests/data/crud}/write/replaceOne.yml +0 -0
  525. data/spec/{support/crud_tests → spec_tests/data/crud}/write/updateMany-arrayFilters.yml +0 -0
  526. data/spec/{support/crud_tests → spec_tests/data/crud}/write/updateMany-collation.yml +0 -0
  527. data/spec/{support/crud_tests → spec_tests/data/crud}/write/updateMany-pre_2.6.yml +0 -0
  528. data/spec/{support/crud_tests → spec_tests/data/crud}/write/updateMany.yml +0 -0
  529. data/spec/{support/crud_tests → spec_tests/data/crud}/write/updateOne-arrayFilters.yml +0 -0
  530. data/spec/{support/crud_tests → spec_tests/data/crud}/write/updateOne-collation.yml +0 -0
  531. data/spec/{support/crud_tests → spec_tests/data/crud}/write/updateOne-pre_2.6.yml +0 -0
  532. data/spec/{support/crud_tests → spec_tests/data/crud}/write/updateOne.yml +0 -0
  533. data/spec/{support/dns_seedlist_discovery_tests → spec_tests/data/dns_seedlist_discovery}/longer-parent-in-return.yml +0 -0
  534. data/spec/{support/dns_seedlist_discovery_tests → spec_tests/data/dns_seedlist_discovery}/misformatted-option.yml +0 -0
  535. data/spec/{support/dns_seedlist_discovery_tests → spec_tests/data/dns_seedlist_discovery}/no-results.yml +0 -0
  536. data/spec/{support/dns_seedlist_discovery_tests → spec_tests/data/dns_seedlist_discovery}/not-enough-parts.yml +0 -0
  537. data/spec/{support/dns_seedlist_discovery_tests → spec_tests/data/dns_seedlist_discovery}/one-result-default-port.yml +0 -0
  538. data/spec/{support/dns_seedlist_discovery_tests → spec_tests/data/dns_seedlist_discovery}/one-txt-record-multiple-strings.yml +0 -0
  539. data/spec/{support/dns_seedlist_discovery_tests → spec_tests/data/dns_seedlist_discovery}/one-txt-record.yml +0 -0
  540. data/spec/{support/dns_seedlist_discovery_tests → spec_tests/data/dns_seedlist_discovery}/parent-part-mismatch1.yml +0 -0
  541. data/spec/{support/dns_seedlist_discovery_tests → spec_tests/data/dns_seedlist_discovery}/parent-part-mismatch2.yml +0 -0
  542. data/spec/{support/dns_seedlist_discovery_tests → spec_tests/data/dns_seedlist_discovery}/parent-part-mismatch3.yml +0 -0
  543. data/spec/{support/dns_seedlist_discovery_tests → spec_tests/data/dns_seedlist_discovery}/parent-part-mismatch4.yml +0 -0
  544. data/spec/{support/dns_seedlist_discovery_tests → spec_tests/data/dns_seedlist_discovery}/parent-part-mismatch5.yml +0 -0
  545. data/spec/{support/dns_seedlist_discovery_tests → spec_tests/data/dns_seedlist_discovery}/returned-parent-too-short.yml +0 -0
  546. data/spec/{support/dns_seedlist_discovery_tests → spec_tests/data/dns_seedlist_discovery}/returned-parent-wrong.yml +0 -0
  547. data/spec/{support/dns_seedlist_discovery_tests → spec_tests/data/dns_seedlist_discovery}/two-results-default-port.yml +0 -0
  548. data/spec/{support/dns_seedlist_discovery_tests → spec_tests/data/dns_seedlist_discovery}/two-results-nonstandard-port.yml +0 -0
  549. data/spec/{support/dns_seedlist_discovery_tests → spec_tests/data/dns_seedlist_discovery}/two-txt-records.yml +0 -0
  550. data/spec/{support/dns_seedlist_discovery_tests → spec_tests/data/dns_seedlist_discovery}/txt-record-not-allowed-option.yml +0 -0
  551. data/spec/{support/dns_seedlist_discovery_tests → spec_tests/data/dns_seedlist_discovery}/txt-record-with-overridden-ssl-option.yml +0 -0
  552. data/spec/{support/dns_seedlist_discovery_tests → spec_tests/data/dns_seedlist_discovery}/txt-record-with-overridden-uri-option.yml +0 -0
  553. data/spec/{support/dns_seedlist_discovery_tests → spec_tests/data/dns_seedlist_discovery}/txt-record-with-unallowed-option.yml +0 -0
  554. data/spec/{support/dns_seedlist_discovery_tests → spec_tests/data/dns_seedlist_discovery}/uri-with-port.yml +0 -0
  555. data/spec/{support/dns_seedlist_discovery_tests → spec_tests/data/dns_seedlist_discovery}/uri-with-two-hosts.yml +0 -0
  556. data/spec/{support/gridfs_tests → spec_tests/data/gridfs}/delete.yml +0 -0
  557. data/spec/{support/gridfs_tests → spec_tests/data/gridfs}/download.yml +0 -0
  558. data/spec/{support/gridfs_tests → spec_tests/data/gridfs}/download_by_name.yml +0 -0
  559. data/spec/{support/gridfs_tests → spec_tests/data/gridfs}/upload.yml +0 -0
  560. data/spec/{support → spec_tests/data}/max_staleness/ReplicaSetNoPrimary/DefaultNoMaxStaleness.yml +0 -0
  561. data/spec/{support → spec_tests/data}/max_staleness/ReplicaSetNoPrimary/Incompatible.yml +0 -0
  562. data/spec/{support → spec_tests/data}/max_staleness/ReplicaSetNoPrimary/LastUpdateTime.yml +0 -0
  563. data/spec/{support → spec_tests/data}/max_staleness/ReplicaSetNoPrimary/Nearest.yml +0 -0
  564. data/spec/{support → spec_tests/data}/max_staleness/ReplicaSetNoPrimary/Nearest2.yml +0 -0
  565. data/spec/{support → spec_tests/data}/max_staleness/ReplicaSetNoPrimary/NoKnownServers.yml +0 -0
  566. data/spec/{support → spec_tests/data}/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred.yml +0 -0
  567. data/spec/{support → spec_tests/data}/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred_tags.yml +0 -0
  568. data/spec/{support → spec_tests/data}/max_staleness/ReplicaSetNoPrimary/Secondary.yml +0 -0
  569. data/spec/{support → spec_tests/data}/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred.yml +0 -0
  570. data/spec/{support → spec_tests/data}/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred_tags.yml +0 -0
  571. data/spec/{support → spec_tests/data}/max_staleness/ReplicaSetNoPrimary/ZeroMaxStaleness.yml +0 -0
  572. data/spec/{support → spec_tests/data}/max_staleness/ReplicaSetWithPrimary/DefaultNoMaxStaleness.yml +0 -0
  573. data/spec/{support → spec_tests/data}/max_staleness/ReplicaSetWithPrimary/Incompatible.yml +0 -0
  574. data/spec/{support → spec_tests/data}/max_staleness/ReplicaSetWithPrimary/LastUpdateTime.yml +0 -0
  575. data/spec/{support → spec_tests/data}/max_staleness/ReplicaSetWithPrimary/LongHeartbeat.yml +0 -0
  576. data/spec/{support → spec_tests/data}/max_staleness/ReplicaSetWithPrimary/LongHeartbeat2.yml +0 -0
  577. data/spec/{support → spec_tests/data}/max_staleness/ReplicaSetWithPrimary/MaxStalenessTooSmall.yml +0 -0
  578. data/spec/{support → spec_tests/data}/max_staleness/ReplicaSetWithPrimary/MaxStalenessWithModePrimary.yml +0 -0
  579. data/spec/{support → spec_tests/data}/max_staleness/ReplicaSetWithPrimary/Nearest.yml +0 -0
  580. data/spec/{support → spec_tests/data}/max_staleness/ReplicaSetWithPrimary/Nearest2.yml +0 -0
  581. data/spec/{support → spec_tests/data}/max_staleness/ReplicaSetWithPrimary/Nearest_tags.yml +0 -0
  582. data/spec/{support → spec_tests/data}/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred.yml +0 -0
  583. data/spec/{support → spec_tests/data}/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred_incompatible.yml +0 -0
  584. data/spec/{support → spec_tests/data}/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred.yml +0 -0
  585. data/spec/{support → spec_tests/data}/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags.yml +0 -0
  586. data/spec/{support → spec_tests/data}/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags2.yml +0 -0
  587. data/spec/{support → spec_tests/data}/max_staleness/ReplicaSetWithPrimary/Secondary_tags.yml +0 -0
  588. data/spec/{support → spec_tests/data}/max_staleness/ReplicaSetWithPrimary/Secondary_tags2.yml +0 -0
  589. data/spec/{support → spec_tests/data}/max_staleness/ReplicaSetWithPrimary/ZeroMaxStaleness.yml +0 -0
  590. data/spec/{support → spec_tests/data}/max_staleness/Sharded/Incompatible.yml +0 -0
  591. data/spec/{support → spec_tests/data}/max_staleness/Sharded/SmallMaxStaleness.yml +0 -0
  592. data/spec/{support → spec_tests/data}/max_staleness/Single/Incompatible.yml +0 -0
  593. data/spec/{support → spec_tests/data}/max_staleness/Single/SmallMaxStaleness.yml +0 -0
  594. data/spec/{support → spec_tests/data}/max_staleness/Unknown/SmallMaxStaleness.yml +0 -0
  595. data/spec/{support/retryable_writes_tests → spec_tests/data/retryable_writes}/bulkWrite-serverErrors.yml +0 -0
  596. data/spec/{support/retryable_writes_tests → spec_tests/data/retryable_writes}/bulkWrite.yml +0 -0
  597. data/spec/{support/retryable_writes_tests → spec_tests/data/retryable_writes}/deleteOne-serverErrors.yml +0 -0
  598. data/spec/{support/retryable_writes_tests → spec_tests/data/retryable_writes}/deleteOne.yml +0 -0
  599. data/spec/{support/retryable_writes_tests → spec_tests/data/retryable_writes}/findOneAndDelete-serverErrors.yml +0 -0
  600. data/spec/{support/retryable_writes_tests → spec_tests/data/retryable_writes}/findOneAndDelete.yml +0 -0
  601. data/spec/{support/retryable_writes_tests → spec_tests/data/retryable_writes}/findOneAndReplace-serverErrors.yml +0 -0
  602. data/spec/{support/retryable_writes_tests → spec_tests/data/retryable_writes}/findOneAndReplace.yml +0 -0
  603. data/spec/{support/retryable_writes_tests → spec_tests/data/retryable_writes}/findOneAndUpdate-serverErrors.yml +0 -0
  604. data/spec/{support/retryable_writes_tests → spec_tests/data/retryable_writes}/findOneAndUpdate.yml +0 -0
  605. data/spec/{support/retryable_writes_tests → spec_tests/data/retryable_writes}/insertMany-serverErrors.yml +0 -0
  606. data/spec/{support/retryable_writes_tests → spec_tests/data/retryable_writes}/insertMany.yml +0 -0
  607. data/spec/{support/retryable_writes_tests → spec_tests/data/retryable_writes}/insertOne-serverErrors.yml +0 -0
  608. data/spec/{support/retryable_writes_tests → spec_tests/data/retryable_writes}/insertOne.yml +0 -0
  609. data/spec/{support/retryable_writes_tests → spec_tests/data/retryable_writes}/replaceOne-serverErrors.yml +0 -0
  610. data/spec/{support/retryable_writes_tests → spec_tests/data/retryable_writes}/replaceOne.yml +0 -0
  611. data/spec/{support/retryable_writes_tests → spec_tests/data/retryable_writes}/updateOne-serverErrors.yml +0 -0
  612. data/spec/{support/retryable_writes_tests → spec_tests/data/retryable_writes}/updateOne.yml +0 -0
  613. data/spec/{support → spec_tests/data}/sdam/rs/compatible.yml +0 -0
  614. data/spec/spec_tests/data/sdam/rs/compatible_unknown.yml +31 -0
  615. data/spec/{support → spec_tests/data}/sdam/rs/discover_arbiters.yml +0 -0
  616. data/spec/{support → spec_tests/data}/sdam/rs/discover_passives.yml +0 -0
  617. data/spec/{support → spec_tests/data}/sdam/rs/discover_primary.yml +0 -0
  618. data/spec/{support → spec_tests/data}/sdam/rs/discover_secondary.yml +0 -0
  619. data/spec/{support → spec_tests/data}/sdam/rs/discovery.yml +0 -0
  620. data/spec/{support → spec_tests/data}/sdam/rs/equal_electionids.yml +2 -0
  621. data/spec/{support → spec_tests/data}/sdam/rs/ghost_discovered.yml +0 -0
  622. data/spec/{support → spec_tests/data}/sdam/rs/hosts_differ_from_seeds.yml +0 -0
  623. data/spec/spec_tests/data/sdam/rs/incompatible_arbiter.yml +32 -0
  624. data/spec/spec_tests/data/sdam/rs/incompatible_ghost.yml +32 -0
  625. data/spec/spec_tests/data/sdam/rs/incompatible_other.yml +32 -0
  626. data/spec/{support → spec_tests/data}/sdam/rs/ls_timeout.yml +0 -0
  627. data/spec/{support → spec_tests/data}/sdam/rs/member_reconfig.yml +0 -0
  628. data/spec/{support → spec_tests/data}/sdam/rs/member_standalone.yml +0 -0
  629. data/spec/{support → spec_tests/data}/sdam/rs/new_primary.yml +0 -0
  630. data/spec/{support → spec_tests/data}/sdam/rs/new_primary_new_electionid.yml +6 -0
  631. data/spec/{support → spec_tests/data}/sdam/rs/new_primary_new_setversion.yml +6 -0
  632. data/spec/{support → spec_tests/data}/sdam/rs/new_primary_wrong_set_name.yml +0 -0
  633. data/spec/{support → spec_tests/data}/sdam/rs/non_rs_member.yml +0 -0
  634. data/spec/{support → spec_tests/data}/sdam/rs/normalize_case.yml +0 -0
  635. data/spec/{support → spec_tests/data}/sdam/rs/normalize_case_me.yml +0 -0
  636. data/spec/{support → spec_tests/data}/sdam/rs/null_election_id.yml +7 -0
  637. data/spec/spec_tests/data/sdam/rs/primary_becomes_ghost.yml +63 -0
  638. data/spec/spec_tests/data/sdam/rs/primary_becomes_mongos.yml +56 -0
  639. data/spec/{support → spec_tests/data}/sdam/rs/primary_becomes_standalone.yml +0 -0
  640. data/spec/{support → spec_tests/data}/sdam/rs/primary_changes_set_name.yml +0 -0
  641. data/spec/{support → spec_tests/data}/sdam/rs/primary_disconnect.yml +0 -0
  642. data/spec/{support → spec_tests/data}/sdam/rs/primary_disconnect_electionid.yml +10 -0
  643. data/spec/{support → spec_tests/data}/sdam/rs/primary_disconnect_setversion.yml +10 -0
  644. data/spec/{support → spec_tests/data}/sdam/rs/primary_hint_from_secondary_with_mismatched_me.yml +0 -0
  645. data/spec/{support → spec_tests/data}/sdam/rs/primary_mismatched_me.yml +0 -0
  646. data/spec/{support → spec_tests/data}/sdam/rs/primary_reports_new_member.yml +0 -0
  647. data/spec/{support → spec_tests/data}/sdam/rs/primary_to_no_primary_mismatched_me.yml +0 -0
  648. data/spec/{support → spec_tests/data}/sdam/rs/primary_wrong_set_name.yml +0 -0
  649. data/spec/{support → spec_tests/data}/sdam/rs/response_from_removed.yml +0 -0
  650. data/spec/{support → spec_tests/data}/sdam/rs/rsother_discovered.yml +0 -0
  651. data/spec/{support → spec_tests/data}/sdam/rs/sec_not_auth.yml +0 -0
  652. data/spec/{support → spec_tests/data}/sdam/rs/secondary_ignore_ok_0.yml +0 -0
  653. data/spec/{support → spec_tests/data}/sdam/rs/secondary_mismatched_me.yml +0 -0
  654. data/spec/{support → spec_tests/data}/sdam/rs/secondary_wrong_set_name.yml +0 -0
  655. data/spec/{support → spec_tests/data}/sdam/rs/secondary_wrong_set_name_with_primary.yml +0 -0
  656. data/spec/spec_tests/data/sdam/rs/secondary_wrong_set_name_with_primary_second.yml +73 -0
  657. data/spec/{support → spec_tests/data}/sdam/rs/setversion_without_electionid.yml +2 -0
  658. data/spec/{support → spec_tests/data}/sdam/rs/stepdown_change_set_name.yml +0 -0
  659. data/spec/{support → spec_tests/data}/sdam/rs/too_new.yml +0 -0
  660. data/spec/{support → spec_tests/data}/sdam/rs/too_old.yml +0 -0
  661. data/spec/{support → spec_tests/data}/sdam/rs/unexpected_mongos.yml +0 -0
  662. data/spec/{support → spec_tests/data}/sdam/rs/use_setversion_without_electionid.yml +6 -0
  663. data/spec/{support → spec_tests/data}/sdam/rs/wrong_set_name.yml +0 -0
  664. data/spec/{support → spec_tests/data}/sdam/sharded/compatible.yml +0 -0
  665. data/spec/{support → spec_tests/data}/sdam/sharded/ls_timeout_mongos.yml +0 -0
  666. data/spec/{support → spec_tests/data}/sdam/sharded/mongos_disconnect.yml +0 -0
  667. data/spec/{support → spec_tests/data}/sdam/sharded/multiple_mongoses.yml +0 -0
  668. data/spec/{support → spec_tests/data}/sdam/sharded/non_mongos_removed.yml +0 -0
  669. data/spec/{support → spec_tests/data}/sdam/sharded/normalize_uri_case.yml +0 -0
  670. data/spec/{support → spec_tests/data}/sdam/sharded/single_mongos.yml +0 -0
  671. data/spec/{support → spec_tests/data}/sdam/sharded/too_new.yml +0 -0
  672. data/spec/{support → spec_tests/data}/sdam/sharded/too_old.yml +0 -0
  673. data/spec/{support → spec_tests/data}/sdam/single/compatible.yml +0 -0
  674. data/spec/{support → spec_tests/data}/sdam/single/direct_connection_external_ip.yml +0 -0
  675. data/spec/{support → spec_tests/data}/sdam/single/direct_connection_mongos.yml +0 -0
  676. data/spec/{support → spec_tests/data}/sdam/single/direct_connection_rsarbiter.yml +0 -0
  677. data/spec/{support → spec_tests/data}/sdam/single/direct_connection_rsprimary.yml +0 -0
  678. data/spec/{support → spec_tests/data}/sdam/single/direct_connection_rssecondary.yml +0 -0
  679. data/spec/{support → spec_tests/data}/sdam/single/direct_connection_slave.yml +0 -0
  680. data/spec/{support → spec_tests/data}/sdam/single/direct_connection_standalone.yml +0 -0
  681. data/spec/{support → spec_tests/data}/sdam/single/ls_timeout_standalone.yml +0 -0
  682. data/spec/{support → spec_tests/data}/sdam/single/not_ok_response.yml +0 -0
  683. data/spec/{support → spec_tests/data}/sdam/single/standalone_removed.yml +0 -0
  684. data/spec/{support → spec_tests/data}/sdam/single/too_new.yml +0 -0
  685. data/spec/{support → spec_tests/data}/sdam/single/too_old.yml +0 -0
  686. data/spec/{support → spec_tests/data}/sdam/single/unavailable_seed.yml +0 -0
  687. data/spec/spec_tests/data/sdam_monitoring/discovered_standalone.yml +72 -0
  688. data/spec/spec_tests/data/sdam_monitoring/replica_set_other_chain.yml +222 -0
  689. data/spec/spec_tests/data/sdam_monitoring/replica_set_other_change.yml +225 -0
  690. data/spec/spec_tests/data/sdam_monitoring/replica_set_other_seed.yml +233 -0
  691. data/spec/{support → spec_tests/data}/sdam_monitoring/replica_set_with_no_primary.yml +0 -0
  692. data/spec/{support → spec_tests/data}/sdam_monitoring/replica_set_with_primary.yml +0 -0
  693. data/spec/spec_tests/data/sdam_monitoring/replica_set_with_primary_and_secondary.yml +198 -0
  694. data/spec/spec_tests/data/sdam_monitoring/replica_set_with_primary_removal.yml +171 -0
  695. data/spec/{support → spec_tests/data}/sdam_monitoring/replica_set_with_removal.yml +0 -0
  696. data/spec/spec_tests/data/sdam_monitoring/replica_set_with_second_seed_removal.yml +106 -0
  697. data/spec/{support → spec_tests/data}/sdam_monitoring/required_replica_set.yml +23 -0
  698. data/spec/{support → spec_tests/data}/sdam_monitoring/standalone.yml +2 -2
  699. data/spec/spec_tests/data/sdam_monitoring/standalone_repeated.yml +86 -0
  700. data/spec/{support/server_selection/selection → spec_tests/data/server_selection}/ReplicaSetNoPrimary/read/Nearest.yml +0 -0
  701. data/spec/{support/server_selection/selection → spec_tests/data/server_selection}/ReplicaSetNoPrimary/read/Nearest_multiple.yml +0 -0
  702. data/spec/{support/server_selection/selection → spec_tests/data/server_selection}/ReplicaSetNoPrimary/read/Nearest_non_matching.yml +0 -0
  703. data/spec/{support/server_selection/selection → spec_tests/data/server_selection}/ReplicaSetNoPrimary/read/PossiblePrimary.yml +0 -0
  704. data/spec/{support/server_selection/selection → spec_tests/data/server_selection}/ReplicaSetNoPrimary/read/PossiblePrimaryNearest.yml +0 -0
  705. data/spec/{support/server_selection/selection → spec_tests/data/server_selection}/ReplicaSetNoPrimary/read/Primary.yml +0 -0
  706. data/spec/{support/server_selection/selection → spec_tests/data/server_selection}/ReplicaSetNoPrimary/read/PrimaryPreferred.yml +0 -0
  707. data/spec/{support/server_selection/selection → spec_tests/data/server_selection}/ReplicaSetNoPrimary/read/PrimaryPreferred_non_matching.yml +0 -0
  708. data/spec/{support/server_selection/selection → spec_tests/data/server_selection}/ReplicaSetNoPrimary/read/Secondary.yml +0 -0
  709. data/spec/{support/server_selection/selection → spec_tests/data/server_selection}/ReplicaSetNoPrimary/read/SecondaryPreferred.yml +0 -0
  710. data/spec/{support/server_selection/selection → spec_tests/data/server_selection}/ReplicaSetNoPrimary/read/SecondaryPreferred_non_matching.yml +0 -0
  711. data/spec/{support/server_selection/selection → spec_tests/data/server_selection}/ReplicaSetNoPrimary/read/Secondary_multi_tags.yml +0 -0
  712. data/spec/{support/server_selection/selection → spec_tests/data/server_selection}/ReplicaSetNoPrimary/read/Secondary_multi_tags2.yml +0 -0
  713. data/spec/{support/server_selection/selection → spec_tests/data/server_selection}/ReplicaSetNoPrimary/read/Secondary_non_matching.yml +0 -0
  714. data/spec/{support/server_selection/selection → spec_tests/data/server_selection}/ReplicaSetWithPrimary/read/Nearest.yml +0 -0
  715. data/spec/{support/server_selection/selection → spec_tests/data/server_selection}/ReplicaSetWithPrimary/read/Nearest_multiple.yml +0 -0
  716. data/spec/{support/server_selection/selection → spec_tests/data/server_selection}/ReplicaSetWithPrimary/read/Nearest_non_matching.yml +0 -0
  717. data/spec/{support/server_selection/selection → spec_tests/data/server_selection}/ReplicaSetWithPrimary/read/Primary.yml +0 -0
  718. data/spec/{support/server_selection/selection → spec_tests/data/server_selection}/ReplicaSetWithPrimary/read/PrimaryPreferred.yml +0 -0
  719. data/spec/{support/server_selection/selection → spec_tests/data/server_selection}/ReplicaSetWithPrimary/read/PrimaryPreferred_non_matching.yml +0 -0
  720. data/spec/{support/server_selection/selection → spec_tests/data/server_selection}/ReplicaSetWithPrimary/read/Secondary.yml +0 -0
  721. data/spec/{support/server_selection/selection → spec_tests/data/server_selection}/ReplicaSetWithPrimary/read/SecondaryPreferred.yml +0 -0
  722. data/spec/{support/server_selection/selection → spec_tests/data/server_selection}/ReplicaSetWithPrimary/read/SecondaryPreferred_non_matching.yml +0 -0
  723. data/spec/{support/server_selection/selection → spec_tests/data/server_selection}/ReplicaSetWithPrimary/read/SecondaryPreferred_tags.yml +0 -0
  724. data/spec/{support/server_selection/selection → spec_tests/data/server_selection}/ReplicaSetWithPrimary/read/Secondary_non_matching.yml +0 -0
  725. data/spec/{support/server_selection/selection → spec_tests/data/server_selection}/Sharded/read/Nearest.yml +0 -0
  726. data/spec/{support/server_selection/selection → spec_tests/data/server_selection}/Sharded/read/Primary.yml +0 -0
  727. data/spec/{support/server_selection/selection → spec_tests/data/server_selection}/Sharded/read/PrimaryPreferred.yml +0 -0
  728. data/spec/{support/server_selection/selection → spec_tests/data/server_selection}/Sharded/read/Secondary.yml +0 -0
  729. data/spec/{support/server_selection/selection → spec_tests/data/server_selection}/Sharded/read/SecondaryPreferred.yml +0 -0
  730. data/spec/{support/server_selection/selection → spec_tests/data/server_selection}/Single/read/SecondaryPreferred.yml +0 -0
  731. data/spec/{support/server_selection/selection → spec_tests/data/server_selection}/Unknown/read/SecondaryPreferred.yml +0 -0
  732. data/spec/{support/server_selection/rtt → spec_tests/data/server_selection_rtt}/first_value.yml +0 -0
  733. data/spec/{support/server_selection/rtt → spec_tests/data/server_selection_rtt}/first_value_zero.yml +0 -0
  734. data/spec/{support/server_selection/rtt → spec_tests/data/server_selection_rtt}/value_test_1.yml +0 -0
  735. data/spec/{support/server_selection/rtt → spec_tests/data/server_selection_rtt}/value_test_2.yml +0 -0
  736. data/spec/{support/server_selection/rtt → spec_tests/data/server_selection_rtt}/value_test_3.yml +0 -0
  737. data/spec/{support/server_selection/rtt → spec_tests/data/server_selection_rtt}/value_test_4.yml +0 -0
  738. data/spec/{support/server_selection/rtt → spec_tests/data/server_selection_rtt}/value_test_5.yml +0 -0
  739. data/spec/{support/transactions_tests → spec_tests/data/transactions}/abort.yml +0 -0
  740. data/spec/{support/transactions_tests → spec_tests/data/transactions}/bulk.yml +0 -0
  741. data/spec/{support/transactions_tests → spec_tests/data/transactions}/causal-consistency.yml +0 -0
  742. data/spec/{support/transactions_tests → spec_tests/data/transactions}/commit.yml +0 -0
  743. data/spec/{support/transactions_tests → spec_tests/data/transactions}/delete.yml +0 -0
  744. data/spec/{support/transactions_tests → spec_tests/data/transactions}/error-labels.yml +0 -0
  745. data/spec/{support/transactions_tests → spec_tests/data/transactions}/errors.yml +0 -0
  746. data/spec/{support/transactions_tests → spec_tests/data/transactions}/findOneAndDelete.yml +0 -0
  747. data/spec/{support/transactions_tests → spec_tests/data/transactions}/findOneAndReplace.yml +0 -0
  748. data/spec/{support/transactions_tests → spec_tests/data/transactions}/findOneAndUpdate.yml +0 -0
  749. data/spec/{support/transactions_tests → spec_tests/data/transactions}/insert.yml +0 -0
  750. data/spec/{support/transactions_tests → spec_tests/data/transactions}/isolation.yml +0 -0
  751. data/spec/{support/transactions_tests → spec_tests/data/transactions}/read-pref.yml +0 -0
  752. data/spec/{support/transactions_tests → spec_tests/data/transactions}/reads.yml +0 -0
  753. data/spec/{support/transactions_tests → spec_tests/data/transactions}/retryable-abort.yml +0 -0
  754. data/spec/{support/transactions_tests → spec_tests/data/transactions}/retryable-commit.yml +0 -0
  755. data/spec/{support/transactions_tests → spec_tests/data/transactions}/retryable-writes.yml +0 -0
  756. data/spec/{support/transactions_tests → spec_tests/data/transactions}/run-command.yml +0 -0
  757. data/spec/{support/transactions_tests → spec_tests/data/transactions}/transaction-options.yml +0 -0
  758. data/spec/{support/transactions_tests → spec_tests/data/transactions}/update.yml +0 -0
  759. data/spec/{support/transactions_tests → spec_tests/data/transactions}/write-concern.yml +0 -0
  760. data/spec/spec_tests/data/transactions_api/callback-aborts.yml +156 -0
  761. data/spec/spec_tests/data/transactions_api/callback-commits.yml +192 -0
  762. data/spec/spec_tests/data/transactions_api/callback-retry.yml +203 -0
  763. data/spec/spec_tests/data/transactions_api/commit-retry.yml +261 -0
  764. data/spec/spec_tests/data/transactions_api/commit-transienttransactionerror-4.2.yml +132 -0
  765. data/spec/spec_tests/data/transactions_api/commit-transienttransactionerror.yml +178 -0
  766. data/spec/spec_tests/data/transactions_api/commit-writeconcernerror.yml +269 -0
  767. data/spec/spec_tests/data/transactions_api/commit.yml +181 -0
  768. data/spec/spec_tests/data/transactions_api/transaction-options.yml +258 -0
  769. data/spec/spec_tests/data/uri_options/auth-options.yml +14 -0
  770. data/spec/spec_tests/data/uri_options/compression-options.yml +48 -0
  771. data/spec/spec_tests/data/uri_options/concern-options.yml +55 -0
  772. data/spec/spec_tests/data/uri_options/connection-options.yml +106 -0
  773. data/spec/spec_tests/data/uri_options/connection-pool-options.yml +26 -0
  774. data/spec/spec_tests/data/uri_options/read-preference-options.yml +42 -0
  775. data/spec/spec_tests/data/uri_options/tls-options.yml +89 -0
  776. data/spec/spec_tests/dns_seedlist_discovery_spec.rb +0 -40
  777. data/spec/spec_tests/gridfs_spec.rb +1 -1
  778. data/spec/spec_tests/max_staleness_spec.rb +21 -8
  779. data/spec/spec_tests/retryable_writes_spec.rb +6 -6
  780. data/spec/spec_tests/sdam_monitoring_spec.rb +38 -20
  781. data/spec/spec_tests/sdam_spec.rb +80 -15
  782. data/spec/spec_tests/server_selection_rtt_spec.rb +6 -63
  783. data/spec/spec_tests/server_selection_spec.rb +18 -3
  784. data/spec/spec_tests/transactions_api_spec.rb +60 -0
  785. data/spec/spec_tests/transactions_spec.rb +20 -13
  786. data/spec/spec_tests/uri_options_spec.rb +94 -0
  787. data/spec/support/authorization.rb +28 -167
  788. data/spec/support/change_streams.rb +7 -7
  789. data/spec/support/change_streams/operation.rb +1 -1
  790. data/spec/support/client_registry.rb +170 -0
  791. data/spec/support/client_registry_macros.rb +14 -0
  792. data/spec/support/cluster_config.rb +49 -0
  793. data/spec/support/command_monitoring.rb +3 -3
  794. data/spec/support/common_shortcuts.rb +12 -0
  795. data/spec/support/connection_string.rb +99 -7
  796. data/spec/support/constraints.rb +24 -13
  797. data/spec/support/crud.rb +9 -97
  798. data/spec/support/crud/read.rb +2 -2
  799. data/spec/support/crud/verifier.rb +98 -0
  800. data/spec/support/crud/write.rb +2 -2
  801. data/spec/support/event_subscriber.rb +25 -13
  802. data/spec/support/gridfs.rb +8 -5
  803. data/spec/support/json_ext_formatter.rb +9 -0
  804. data/spec/support/lite_constraints.rb +27 -1
  805. data/spec/support/monitoring_ext.rb +16 -0
  806. data/spec/support/sdam_formatter_integration.rb +110 -0
  807. data/spec/support/sdam_monitoring.rb +77 -17
  808. data/spec/support/server_discovery_and_monitoring.rb +43 -20
  809. data/spec/support/server_selection.rb +3 -13
  810. data/spec/support/server_selection_rtt.rb +10 -10
  811. data/spec/support/shared/server_selector.rb +13 -41
  812. data/spec/support/shared/session.rb +44 -22
  813. data/spec/support/spec_config.rb +186 -11
  814. data/spec/support/spec_setup.rb +61 -0
  815. data/spec/support/transactions.rb +79 -145
  816. data/spec/support/transactions/operation.rb +53 -14
  817. data/spec/support/transactions/verifier.rb +94 -0
  818. metadata +712 -565
  819. metadata.gz.sig +0 -0
  820. data/lib/mongo/cluster/topology/replica_set.rb +0 -339
  821. data/lib/mongo/event/member_discovered.rb +0 -67
  822. data/lib/mongo/event/primary_elected.rb +0 -55
  823. data/lib/mongo/event/standalone_discovered.rb +0 -53
  824. data/lib/mongo/server/description/inspector.rb +0 -81
  825. data/lib/mongo/server/description/inspector/description_changed.rb +0 -57
  826. data/lib/mongo/server/description/inspector/member_discovered.rb +0 -59
  827. data/lib/mongo/server/description/inspector/primary_elected.rb +0 -60
  828. data/lib/mongo/server/description/inspector/standalone_discovered.rb +0 -56
  829. data/spec/mongo/server/description/inspector/description_changed_spec.rb +0 -78
  830. data/spec/mongo/server/description/inspector/primary_elected_spec.rb +0 -94
  831. data/spec/support/sdam/rs/set_version_without_electionid.yml +0 -69
  832. data/spec/support/travis.rb +0 -14
@@ -3,20 +3,7 @@ require 'spec_helper'
3
3
  describe Mongo::BulkWrite do
4
4
 
5
5
  before do
6
- authorized_collection.delete_many
7
- end
8
-
9
- after do
10
- authorized_collection.delete_many
11
- collection_with_validator.drop
12
- end
13
-
14
- let(:collection_with_validator) do
15
- begin; authorized_client[:validating].drop; rescue; end
16
- authorized_client[:validating,
17
- :validator => { :a => { '$exists' => true } }].tap do |c|
18
- c.create
19
- end
6
+ authorized_collection.drop
20
7
  end
21
8
 
22
9
  let(:collection_invalid_write_concern) do
@@ -1921,10 +1908,18 @@ describe Mongo::BulkWrite do
1921
1908
  it_behaves_like 'an operation using a session'
1922
1909
  end
1923
1910
 
1924
- context 'when retryable writes are supported', if: test_sessions? do
1911
+ context 'when retryable writes are supported' do
1912
+ min_server_version '3.6'
1913
+ require_topology :replica_set, :sharded
1914
+
1915
+ let(:subscriber) { EventSubscriber.new }
1925
1916
 
1926
1917
  let(:client) do
1927
- authorized_client_with_retry_writes
1918
+ authorized_client_with_retry_writes.tap do |client|
1919
+ # We do not unsubscribe any of these subscribers.
1920
+ # This is harmless since they simply store the events in themselves.
1921
+ client.subscribe(Mongo::Monitoring::COMMAND, subscriber)
1922
+ end
1928
1923
  end
1929
1924
 
1930
1925
  let(:collection) do
@@ -1935,12 +1930,18 @@ describe Mongo::BulkWrite do
1935
1930
  bulk_write.execute
1936
1931
  end
1937
1932
 
1933
+ let(:started_events) do
1934
+ subscriber.started_events.select do |event|
1935
+ event.command['insert']
1936
+ end
1937
+ end
1938
+
1938
1939
  let(:first_txn_number) do
1939
- EventSubscriber.started_events[-2].command['txnNumber'].instance_variable_get(:@integer)
1940
+ started_events[-2].command['txnNumber'].instance_variable_get(:@integer)
1940
1941
  end
1941
1942
 
1942
1943
  let(:second_txn_number) do
1943
- EventSubscriber.started_events[-1].command['txnNumber'].instance_variable_get(:@integer)
1944
+ started_events[-1].command['txnNumber'].instance_variable_get(:@integer)
1944
1945
  end
1945
1946
 
1946
1947
  it 'inserts the documents' do
@@ -1951,8 +1952,12 @@ describe Mongo::BulkWrite do
1951
1952
  expect(result.inserted_ids.size).to eq(batch_size)
1952
1953
  end
1953
1954
 
1955
+ it 'publishes the expected number of events' do
1956
+ expect(started_events.length).to eq 2
1957
+ end
1958
+
1954
1959
  it 'increments the transaction number' do
1955
- expect(first_txn_number + 1). to eq(second_txn_number)
1960
+ expect(second_txn_number). to eq(first_txn_number + 1)
1956
1961
  end
1957
1962
  end
1958
1963
  end
@@ -2139,12 +2144,17 @@ describe Mongo::BulkWrite do
2139
2144
  describe 'when the collection has a validator' do
2140
2145
  min_server_version '3.2'
2141
2146
 
2142
- before do
2143
- collection_with_validator.insert_many([{ :a => 1 }, { :a => 2 }])
2147
+ let(:collection_with_validator) do
2148
+ authorized_client[:validating,
2149
+ :validator => { :a => { '$exists' => true } }].tap do |c|
2150
+ c.create
2151
+ end
2144
2152
  end
2145
2153
 
2146
- after do
2154
+ before do
2155
+ begin; authorized_client[:validating].drop; rescue; end
2147
2156
  collection_with_validator.delete_many
2157
+ collection_with_validator.insert_many([{ :a => 1 }, { :a => 2 }])
2148
2158
  end
2149
2159
 
2150
2160
  context 'when the documents are invalid' do
@@ -0,0 +1,1164 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mongo::Client do
4
+ before do
5
+ ClientRegistry.instance.close_all_clients
6
+ end
7
+
8
+ describe '.new' do
9
+ describe 'options' do
10
+ describe 'read' do
11
+ [
12
+ :primary, :primary_preferred, :secondary, :secondary_preferred, :nearest
13
+ ].each do |sym|
14
+ it "accepts #{sym} as symbol" do
15
+ client = new_local_client_nmio(['127.0.0.1:27017'],
16
+ :read => {:mode => sym})
17
+ # the key got converted to a string here
18
+ expect(client.read_preference).to eq({'mode' => sym})
19
+ end
20
+
21
+ # string keys are not documented as being allowed
22
+ # but the code accepts them
23
+ it "accepts #{sym} as string" do
24
+ client = new_local_client_nmio(['127.0.0.1:27017'],
25
+ :read => {:mode => sym.to_s})
26
+ # the key got converted to a string here
27
+ # the value remains a string
28
+ expect(client.read_preference).to eq({'mode' => sym.to_s})
29
+ end
30
+ end
31
+
32
+ context 'when not linting' do
33
+ skip_if_linting
34
+
35
+ it 'rejects bogus read preference as symbol' do
36
+ expect do
37
+ client = new_local_client_nmio(['127.0.0.1:27017'],
38
+ :read => {:mode => :bogus})
39
+ end.to raise_error(Mongo::Error::InvalidReadOption, 'Invalid read option: {"mode"=>:bogus}: mode bogus is not one of recognized modes')
40
+ end
41
+
42
+ it 'rejects bogus read preference as string' do
43
+ expect do
44
+ client = new_local_client_nmio(['127.0.0.1:27017'],
45
+ :read => {:mode => 'bogus'})
46
+ end.to raise_error(Mongo::Error::InvalidReadOption, 'Invalid read option: {"mode"=>"bogus"}: mode bogus is not one of recognized modes')
47
+ end
48
+
49
+ it 'rejects read option specified as a string' do
50
+ expect do
51
+ client = new_local_client_nmio(['127.0.0.1:27017'],
52
+ :read => 'primary')
53
+ end.to raise_error(Mongo::Error::InvalidReadOption, 'Invalid read option: primary: must be a hash')
54
+ end
55
+
56
+ it 'rejects read option specified as a symbol' do
57
+ expect do
58
+ client = new_local_client_nmio(['127.0.0.1:27017'],
59
+ :read => :primary)
60
+ end.to raise_error(Mongo::Error::InvalidReadOption, 'Invalid read option: primary: must be a hash')
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ context 'with scan: false' do
67
+ it 'does not perform i/o' do
68
+ allow_any_instance_of(Mongo::Server::Monitor).to receive(:run!)
69
+ expect_any_instance_of(Mongo::Server::Monitor).not_to receive(:scan!)
70
+ start_time = Time.now
71
+ # return should be instant
72
+ c = Timeout.timeout(1) do
73
+ ClientRegistry.instance.new_local_client(['1.1.1.1'], scan: false)
74
+ end
75
+ expect(c.cluster.servers).to be_empty
76
+ c.close
77
+ end
78
+ end
79
+
80
+ context 'with default scan: true' do
81
+ # TODO this test requires there being no outstanding background
82
+ # monitoring threads running, as otherwise the scan! expectation
83
+ # can be executed on a thread that belongs to one of the global
84
+ # clients for instance
85
+ it 'performs one round of sdam' do
86
+ # Does not work due to
87
+ # https://github.com/rspec/rspec-mocks/issues/1242.
88
+ #expect_any_instance_of(Mongo::Server::Monitor).to receive(:scan!).
89
+ # exactly(SpecConfig.instance.addresses.length).times.and_call_original
90
+ c = ClientRegistry.instance.new_local_client(
91
+ SpecConfig.instance.addresses, SpecConfig.instance.test_options)
92
+ expect(c.cluster.servers).not_to be_empty
93
+ c.close
94
+ end
95
+
96
+ # This checks the case of all initial seeds being removed from
97
+ # cluster during SDAM
98
+ context 'me mismatch on the only initial seed' do
99
+ let(:address) do
100
+ address = SpecConfig.instance.addresses.first
101
+ port = address.sub(/^.*:/, '').to_i
102
+ address = address.sub(/:.*/, '')
103
+ case address
104
+ when '127.0.0.1'
105
+ 'localhost'
106
+ when /^(\d+\.){3}\d+$/
107
+ skip 'This test requires a hostname or 127.0.0.1 as address'
108
+ else
109
+ # We don't know if mongod is listening on ipv4 or ipv6,
110
+ # in principle.
111
+ # Our tests use ipv4, so hardcode that for now.
112
+ # To support both we need to try both addresses
113
+ # which will make this test more complicated.
114
+ resolved_address = Addrinfo.getaddrinfo(address, port, Socket::PF_INET).first.ip_address
115
+ if resolved_address.include?(':')
116
+ "[#{resolved_address}]"
117
+ else
118
+ resolved_address
119
+ end + ":#{port}"
120
+ end
121
+ end
122
+
123
+ let(:client) do
124
+ ClientRegistry.instance.new_local_client(
125
+ [address],
126
+ # Specify server selection timeout here because test suite sets
127
+ # one by default and it's fairly low
128
+ SpecConfig.instance.test_options.merge(server_selection_timeout: 5))
129
+ end
130
+
131
+ it 'does not wait for server selection timeout' do
132
+ start_time = Time.now
133
+ client
134
+ time_taken = Time.now - start_time
135
+ expect(time_taken < 3).to be true
136
+
137
+ # run a command to ensure the client is a working one
138
+ client.database.command(ismaster: 1)
139
+ end
140
+ end
141
+ end
142
+
143
+ context 'with monitoring_io: false' do
144
+ let(:client) do
145
+ new_local_client(['127.0.0.1:27017'], monitoring_io: false)
146
+ end
147
+
148
+ it 'passes monitoring_io: false to cluster' do
149
+ expect(client.cluster.options[:monitoring_io]).to be false
150
+ end
151
+ end
152
+ end
153
+
154
+ describe '#initialize' do
155
+
156
+ context 'when providing options' do
157
+
158
+ context 'when retry_writes is defined' do
159
+
160
+ let(:options) do
161
+ { retry_writes: true }
162
+ end
163
+
164
+ let(:client) do
165
+ new_local_client_nmio(SpecConfig.instance.addresses, authorized_client.options.merge(options))
166
+ end
167
+
168
+ it 'sets the option' do
169
+ expect(client.options['retry_writes']).to eq(options[:retry_writes])
170
+ end
171
+ end
172
+
173
+ context 'when compressors are provided' do
174
+
175
+ let(:client) do
176
+ new_local_client(SpecConfig.instance.addresses, authorized_client.options.merge(options))
177
+ end
178
+
179
+ context 'when the compressor is supported' do
180
+
181
+ let(:options) do
182
+ { compressors: ['zlib'] }
183
+ end
184
+
185
+ it 'sets the compressor' do
186
+ expect(client.options['compressors']).to eq(options[:compressors])
187
+ end
188
+
189
+ it 'sends the compressor in the compression key of the handshake document' do
190
+ expect(client.cluster.app_metadata.send(:document)[:compression]).to eq(options[:compressors])
191
+ end
192
+
193
+ it 'uses compression for messages', if: testing_compression? do
194
+ expect(Mongo::Protocol::Compressed).to receive(:new).and_call_original
195
+ client[TEST_COLL].find({}, limit: 1).first
196
+ end
197
+
198
+ it 'does not use compression for authentication messages' do
199
+ expect(Mongo::Protocol::Compressed).not_to receive(:new)
200
+ client.cluster.next_primary.send(:with_connection) do |conn|
201
+ conn.send(:authenticate!)
202
+ end
203
+ end
204
+ end
205
+
206
+ context 'when the compressor is not supported by the driver' do
207
+
208
+ let(:options) do
209
+ { compressors: ['snoopy'] }
210
+ end
211
+
212
+ it 'does not set the compressor and warns' do
213
+ expect(Mongo::Logger.logger).to receive(:warn)
214
+ expect(client.options['compressors']).to be_nil
215
+ end
216
+
217
+ it 'sets the compression key of the handshake document to an empty array' do
218
+ expect(client.cluster.app_metadata.send(:document)[:compression]).to eq([])
219
+ end
220
+
221
+ context 'when one supported compressor and one unsupported compressor are provided', if: compression_enabled? do
222
+
223
+ let(:options) do
224
+ { compressors: ['zlib', 'snoopy'] }
225
+ end
226
+
227
+ it 'does not set the unsupported compressor and warns' do
228
+ expect(Mongo::Logger.logger).to receive(:warn).at_least(:once)
229
+ expect(client.options['compressors']).to eq(['zlib'])
230
+ end
231
+
232
+ it 'sets the compression key of the handshake document to the list of supported compressors' do
233
+ expect(client.cluster.app_metadata.send(:document)[:compression]).to eq(['zlib'])
234
+ end
235
+ end
236
+ end
237
+
238
+ context 'when the compressor is not supported by the server', unless: collation_enabled? do
239
+
240
+ let(:options) do
241
+ { compressors: ['zlib'] }
242
+ end
243
+
244
+ it 'does not set the compressor and warns' do
245
+ expect(Mongo::Logger.logger).to receive(:warn).at_least(:once)
246
+ expect(client.cluster.next_primary.monitor.compressor).to be_nil
247
+ end
248
+ end
249
+ end
250
+
251
+ context 'when compressors are not provided', unless: compression_enabled? do
252
+
253
+ let(:client) do
254
+ authorized_client
255
+ end
256
+
257
+ it 'does not set the compressor' do
258
+ expect(client.options['compressors']).to be_nil
259
+ end
260
+
261
+ it 'sets the compression key of the handshake document to an empty array' do
262
+ expect(client.cluster.app_metadata.send(:document)[:compression]).to eq([])
263
+ end
264
+
265
+ it 'does not use compression for messages' do
266
+ client[TEST_COLL].find({}, limit: 1).first
267
+ expect(Mongo::Protocol::Compressed).not_to receive(:new)
268
+ end
269
+ end
270
+
271
+ context 'when a zlib_compression_level option is provided', if: testing_compression? do
272
+
273
+ let(:client) do
274
+ new_local_client_nmio(SpecConfig.instance.addresses, SpecConfig.instance.test_options.merge(zlib_compression_level: 1))
275
+ end
276
+
277
+ it 'sets the option on the client' do
278
+ expect(client.options[:zlib_compression_level]).to eq(1)
279
+ end
280
+ end
281
+
282
+ context 'when ssl options are provided' do
283
+
284
+ let(:options) do
285
+ {
286
+ :ssl => true,
287
+ :ssl_ca_cert => CA_PEM,
288
+ :ssl_ca_cert_string => 'ca cert string',
289
+ :ssl_ca_cert_object => 'ca cert object',
290
+ :ssl_cert => CLIENT_CERT_PEM,
291
+ :ssl_cert_string => 'cert string',
292
+ :ssl_cert_object => 'cert object',
293
+ :ssl_key => CLIENT_KEY_PEM,
294
+ :ssl_key_string => 'key string',
295
+ :ssl_key_object => 'key object',
296
+ :ssl_key_pass_phrase => 'passphrase',
297
+ :ssl_verify => true
298
+ }
299
+ end
300
+
301
+ let(:client) do
302
+ new_local_client_nmio(['127.0.0.1:27017'], SpecConfig.instance.test_options.merge(options))
303
+ end
304
+
305
+ it 'sets the ssl option' do
306
+ expect(client.options[:ssl]).to eq(options[:ssl])
307
+ end
308
+
309
+ it 'sets the ssl_ca_cert option' do
310
+ expect(client.options[:ssl_ca_cert]).to eq(options[:ssl_ca_cert])
311
+ end
312
+
313
+ it 'sets the ssl_ca_cert_string option' do
314
+ expect(client.options[:ssl_ca_cert_string]).to eq(options[:ssl_ca_cert_string])
315
+ end
316
+
317
+ it 'sets the ssl_ca_cert_object option' do
318
+ expect(client.options[:ssl_ca_cert_object]).to eq(options[:ssl_ca_cert_object])
319
+ end
320
+
321
+ it 'sets the ssl_cert option' do
322
+ expect(client.options[:ssl_cert]).to eq(options[:ssl_cert])
323
+ end
324
+
325
+ it 'sets the ssl_cert_string option' do
326
+ expect(client.options[:ssl_cert_string]).to eq(options[:ssl_cert_string])
327
+ end
328
+
329
+ it 'sets the ssl_cert_object option' do
330
+ expect(client.options[:ssl_cert_object]).to eq(options[:ssl_cert_object])
331
+ end
332
+
333
+ it 'sets the ssl_key option' do
334
+ expect(client.options[:ssl_key]).to eq(options[:ssl_key])
335
+ end
336
+
337
+ it 'sets the ssl_key_string option' do
338
+ expect(client.options[:ssl_key_string]).to eq(options[:ssl_key_string])
339
+ end
340
+
341
+ it 'sets the ssl_key_object option' do
342
+ expect(client.options[:ssl_key_object]).to eq(options[:ssl_key_object])
343
+ end
344
+
345
+ it 'sets the ssl_key_pass_phrase option' do
346
+ expect(client.options[:ssl_key_pass_phrase]).to eq(options[:ssl_key_pass_phrase])
347
+ end
348
+
349
+ it 'sets the ssl_verify option' do
350
+ expect(client.options[:ssl_verify]).to eq(options[:ssl_verify])
351
+ end
352
+ end
353
+
354
+ context 'when no database is provided' do
355
+
356
+ let(:client) do
357
+ new_local_client_nmio(['127.0.0.1:27017'], :read => { :mode => :secondary })
358
+ end
359
+
360
+ it 'defaults the database to admin' do
361
+ expect(client.database.name).to eq('admin')
362
+ end
363
+ end
364
+
365
+ context 'when a database is provided' do
366
+
367
+ let(:client) do
368
+ new_local_client_nmio(['127.0.0.1:27017'], :database => :testdb)
369
+ end
370
+
371
+ it 'sets the current database' do
372
+ expect(client[:users].name).to eq('users')
373
+ end
374
+ end
375
+
376
+ context 'when providing a custom logger' do
377
+
378
+ let(:logger) do
379
+ Logger.new($stdout).tap do |l|
380
+ l.level = Logger::FATAL
381
+ end
382
+ end
383
+
384
+ let(:client) do
385
+ authorized_client.with(logger: logger)
386
+ end
387
+
388
+ it 'does not use the global logger' do
389
+ expect(client.cluster.logger).to_not eq(Mongo::Logger.logger)
390
+ end
391
+ end
392
+
393
+ context 'when providing a heartbeat_frequency' do
394
+
395
+ let(:client) do
396
+ new_local_client_nmio(['127.0.0.1:27017'], :heartbeat_frequency => 2)
397
+ end
398
+
399
+ it 'sets the heartbeat frequency' do
400
+ expect(client.cluster.options[:heartbeat_frequency]).to eq(client.options[:heartbeat_frequency])
401
+ end
402
+ end
403
+
404
+ context 'when min_pool_size is provided' do
405
+
406
+ let(:client) do
407
+ new_local_client_nmio(['127.0.0.1:27017'], options)
408
+ end
409
+
410
+ context 'when max_pool_size is provided' do
411
+
412
+ context 'when the min_pool_size is greater than the max_pool_size' do
413
+
414
+ let(:options) do
415
+ {
416
+ :min_pool_size => 20,
417
+ :max_pool_size => 10
418
+ }
419
+ end
420
+
421
+ it 'raises an Exception' do
422
+ expect {
423
+ client
424
+ }.to raise_exception(Mongo::Error::InvalidMinPoolSize)
425
+ end
426
+ end
427
+
428
+ context 'when the min_pool_size is less than the max_pool_size' do
429
+
430
+ let(:options) do
431
+ {
432
+ :min_pool_size => 10,
433
+ :max_pool_size => 20
434
+ }
435
+ end
436
+
437
+ it 'sets the option' do
438
+ expect(client.options[:min_pool_size]).to eq(options[:min_pool_size])
439
+ expect(client.options[:max_pool_size]).to eq(options[:max_pool_size])
440
+ end
441
+ end
442
+
443
+ context 'when the min_pool_size is equal to the max_pool_size' do
444
+
445
+ let(:options) do
446
+ {
447
+ :min_pool_size => 10,
448
+ :max_pool_size => 10
449
+ }
450
+ end
451
+
452
+ it 'sets the option' do
453
+ expect(client.options[:min_pool_size]).to eq(options[:min_pool_size])
454
+ expect(client.options[:max_pool_size]).to eq(options[:max_pool_size])
455
+ end
456
+ end
457
+ end
458
+
459
+ context 'when max_pool_size is not provided' do
460
+
461
+ context 'when the min_pool_size is greater than the default max_pool_size' do
462
+
463
+ let(:options) do
464
+ {
465
+ :min_pool_size => 10
466
+ }
467
+ end
468
+
469
+ it 'raises an Exception' do
470
+ expect {
471
+ client
472
+ }.to raise_exception(Mongo::Error::InvalidMinPoolSize)
473
+ end
474
+ end
475
+
476
+ context 'when the min_pool_size is less than the default max_pool_size' do
477
+
478
+ let(:options) do
479
+ {
480
+ :min_pool_size => 3
481
+ }
482
+ end
483
+
484
+ it 'sets the option' do
485
+ expect(client.options[:min_pool_size]).to eq(options[:min_pool_size])
486
+ end
487
+ end
488
+
489
+ context 'when the min_pool_size is equal to the max_pool_size' do
490
+
491
+ let(:options) do
492
+ {
493
+ :min_pool_size => Mongo::Server::ConnectionPool::Queue::MAX_SIZE
494
+ }
495
+ end
496
+
497
+ it 'sets the option' do
498
+ expect(client.options[:min_pool_size]).to eq(options[:min_pool_size])
499
+ end
500
+ end
501
+ end
502
+ end
503
+
504
+ context 'when max_pool_size and min_pool_size are both nil' do
505
+
506
+ let(:client) do
507
+ new_local_client_nmio(['127.0.0.1:27017'], options)
508
+ end
509
+
510
+ let(:options) do
511
+ {
512
+ :min_pool_size => nil,
513
+ :max_pool_size => nil
514
+ }
515
+ end
516
+
517
+ it 'does not set either option' do
518
+ expect(client.options[:max_pool_size]).to be_nil
519
+ expect(client.options[:min_pool_size]).to be_nil
520
+ end
521
+ end
522
+
523
+ context 'when platform details are specified' do
524
+
525
+ let(:app_metadata) do
526
+ client.cluster.app_metadata
527
+ end
528
+
529
+ let(:client) do
530
+ new_local_client_nmio(['127.0.0.1:27017'], :platform => 'mongoid-6.0.2')
531
+ end
532
+
533
+ it 'includes the platform info in the app metadata' do
534
+ expect(app_metadata.send(:full_client_document)[:platform]).to match(/mongoid-6\.0\.2/)
535
+ end
536
+ end
537
+
538
+ context 'when platform details are not specified' do
539
+
540
+ let(:app_metadata) do
541
+ client.cluster.app_metadata
542
+ end
543
+
544
+ let(:client) do
545
+ new_local_client_nmio(['127.0.0.1:27017'])
546
+ end
547
+
548
+ let(:platform_string) do
549
+ [
550
+ RUBY_VERSION,
551
+ RUBY_PLATFORM,
552
+ RbConfig::CONFIG['build']
553
+ ].join(', ')
554
+ end
555
+
556
+ it 'does not include the platform info in the app metadata' do
557
+ expect(app_metadata.send(:full_client_document)[:platform]).to eq(platform_string)
558
+ end
559
+ end
560
+ end
561
+
562
+ context 'when providing a connection string' do
563
+
564
+ context 'when the string uses the SRV Protocol' do
565
+ require_external_connectivity
566
+
567
+ let!(:uri) do
568
+ 'mongodb+srv://test5.test.build.10gen.cc/testdb'
569
+ end
570
+
571
+ let(:client) do
572
+ new_local_client_nmio(uri)
573
+ end
574
+
575
+ it 'sets the database' do
576
+ expect(client.options[:database]).to eq('testdb')
577
+ end
578
+ end
579
+
580
+ context 'when a database is provided' do
581
+
582
+ let!(:uri) do
583
+ 'mongodb://127.0.0.1:27017/testdb'
584
+ end
585
+
586
+ let(:client) do
587
+ new_local_client_nmio(uri)
588
+ end
589
+
590
+ it 'sets the database' do
591
+ expect { client[:users] }.to_not raise_error
592
+ end
593
+ end
594
+
595
+ context 'when a database is not provided' do
596
+
597
+ let!(:uri) do
598
+ 'mongodb://127.0.0.1:27017'
599
+ end
600
+
601
+ let(:client) do
602
+ new_local_client_nmio(uri)
603
+ end
604
+
605
+ it 'defaults the database to admin' do
606
+ expect(client.database.name).to eq('admin')
607
+ end
608
+ end
609
+
610
+ context 'when options are provided' do
611
+
612
+ let!(:uri) do
613
+ 'mongodb://127.0.0.1:27017/testdb?w=3'
614
+ end
615
+
616
+ let(:client) do
617
+ new_local_client_nmio(uri)
618
+ end
619
+
620
+ let(:expected_options) do
621
+ Mongo::Options::Redacted.new(:write => { :w => 3 },
622
+ monitoring_io: false, :database => 'testdb')
623
+ end
624
+
625
+ it 'sets the options' do
626
+ expect(client.options).to eq(expected_options)
627
+ end
628
+
629
+ context 'when min_pool_size is provided' do
630
+
631
+ context 'when max_pool_size is provided' do
632
+
633
+ context 'when the min_pool_size is greater than the max_pool_size' do
634
+
635
+ let(:uri) do
636
+ 'mongodb://127.0.0.1:27017/?minPoolSize=20&maxPoolSize=10'
637
+ end
638
+
639
+ it 'raises an Exception' do
640
+ expect {
641
+ client
642
+ }.to raise_exception(Mongo::Error::InvalidMinPoolSize)
643
+ end
644
+ end
645
+
646
+ context 'when the min_pool_size is less than the max_pool_size' do
647
+
648
+ let(:uri) do
649
+ 'mongodb://127.0.0.1:27017/?minPoolSize=10&maxPoolSize=20'
650
+ end
651
+
652
+ it 'sets the option' do
653
+ expect(client.options[:min_pool_size]).to eq(10)
654
+ expect(client.options[:max_pool_size]).to eq(20)
655
+ end
656
+ end
657
+
658
+ context 'when the min_pool_size is equal to the max_pool_size' do
659
+
660
+ let(:uri) do
661
+ 'mongodb://127.0.0.1:27017/?minPoolSize=10&maxPoolSize=10'
662
+ end
663
+
664
+ it 'sets the option' do
665
+ expect(client.options[:min_pool_size]).to eq(10)
666
+ expect(client.options[:max_pool_size]).to eq(10)
667
+ end
668
+ end
669
+ end
670
+
671
+ context 'when max_pool_size is not provided' do
672
+
673
+ context 'when the min_pool_size is greater than the default max_pool_size' do
674
+
675
+ let(:uri) do
676
+ 'mongodb://127.0.0.1:27017/?minPoolSize=10'
677
+ end
678
+
679
+ it 'raises an Exception' do
680
+ expect {
681
+ client
682
+ }.to raise_exception(Mongo::Error::InvalidMinPoolSize)
683
+ end
684
+ end
685
+
686
+ context 'when the min_pool_size is less than the default max_pool_size' do
687
+
688
+ let(:uri) do
689
+ 'mongodb://127.0.0.1:27017/?minPoolSize=3'
690
+ end
691
+
692
+ it 'sets the option' do
693
+ expect(client.options[:min_pool_size]).to eq(3)
694
+ end
695
+ end
696
+
697
+ context 'when the min_pool_size is equal to the max_pool_size' do
698
+
699
+ let(:uri) do
700
+ 'mongodb://127.0.0.1:27017/?minPoolSize=5'
701
+ end
702
+
703
+ it 'sets the option' do
704
+ expect(client.options[:min_pool_size]).to eq(5)
705
+ end
706
+ end
707
+ end
708
+ end
709
+ end
710
+
711
+ context 'when options are provided not in the string' do
712
+
713
+ let!(:uri) do
714
+ 'mongodb://127.0.0.1:27017/testdb'
715
+ end
716
+
717
+ let(:client) do
718
+ new_local_client_nmio(uri, :write => { :w => 3 })
719
+ end
720
+
721
+ let(:expected_options) do
722
+ Mongo::Options::Redacted.new(:write => { :w => 3 },
723
+ monitoring_io: false, :database => 'testdb')
724
+ end
725
+
726
+ it 'sets the options' do
727
+ expect(client.options).to eq(expected_options)
728
+ end
729
+ end
730
+
731
+ context 'when options are provided in the string and explicitly' do
732
+
733
+ let!(:uri) do
734
+ 'mongodb://127.0.0.1:27017/testdb?w=3'
735
+ end
736
+
737
+ let(:client) do
738
+ new_local_client_nmio(uri, :write => { :w => 4 })
739
+ end
740
+
741
+ let(:expected_options) do
742
+ Mongo::Options::Redacted.new(:write => { :w => 4 },
743
+ monitoring_io: false, :database => 'testdb')
744
+ end
745
+
746
+ it 'allows explicit options to take preference' do
747
+ expect(client.options).to eq(expected_options)
748
+ end
749
+ end
750
+
751
+ context 'when a replica set name is provided' do
752
+
753
+ let!(:uri) do
754
+ 'mongodb://127.0.0.1:27017/testdb?replicaSet=testing'
755
+ end
756
+
757
+ let(:client) do
758
+ new_local_client_nmio(uri)
759
+ end
760
+
761
+ it 'sets the correct cluster topology' do
762
+ expect(client.cluster.topology).to be_a(Mongo::Cluster::Topology::ReplicaSetNoPrimary)
763
+ end
764
+ end
765
+
766
+ context 'when an invalid option is provided' do
767
+
768
+ let(:client) do
769
+ new_local_client_nmio(['127.0.0.1:27017'], :ssl => false, :invalid => :test)
770
+ end
771
+
772
+ it 'does not set the option' do
773
+ expect(client.options.keys).not_to include('invalid')
774
+ end
775
+
776
+ it 'sets the valid options' do
777
+ expect(client.options.keys).to include('ssl')
778
+ end
779
+
780
+ it 'warns that an invalid option has been specified' do
781
+ expect(Mongo::Logger.logger).to receive(:warn)
782
+ expect(client.options.keys).not_to include('invalid')
783
+ end
784
+ end
785
+ end
786
+ end
787
+
788
+ shared_examples_for 'duplicated client with duplicated monitoring' do
789
+ let(:monitoring) { client.send(:monitoring) }
790
+ let(:new_monitoring) { new_client.send(:monitoring) }
791
+
792
+ it 'duplicates monitoring' do
793
+ expect(new_monitoring).not_to eql(monitoring)
794
+ end
795
+
796
+ it 'copies monitoring subscribers' do
797
+ monitoring.subscribers.clear
798
+ client.subscribe(Mongo::Monitoring::SERVER_HEARTBEAT, EventSubscriber.new)
799
+ expect(monitoring.present_subscribers.length).to eq(1)
800
+ expect(monitoring.subscribers[Mongo::Monitoring::SERVER_HEARTBEAT].length).to eq(1)
801
+
802
+ # this duplicates the client
803
+ expect(new_monitoring.present_subscribers.length).to eq(1)
804
+ expect(new_monitoring.subscribers[Mongo::Monitoring::SERVER_HEARTBEAT].length).to eq(1)
805
+ end
806
+
807
+ it 'does not change subscribers on original client' do
808
+ monitoring.subscribers.clear
809
+ client.subscribe(Mongo::Monitoring::SERVER_HEARTBEAT, EventSubscriber.new)
810
+ expect(monitoring.present_subscribers.length).to eq(1)
811
+ expect(monitoring.subscribers[Mongo::Monitoring::SERVER_HEARTBEAT].length).to eq(1)
812
+
813
+ new_client.subscribe(Mongo::Monitoring::SERVER_HEARTBEAT, EventSubscriber.new)
814
+ new_client.subscribe(Mongo::Monitoring::SERVER_HEARTBEAT, EventSubscriber.new)
815
+ expect(new_monitoring.present_subscribers.length).to eq(1)
816
+ expect(new_monitoring.subscribers[Mongo::Monitoring::SERVER_HEARTBEAT].length).to eq(3)
817
+ # original client should not have gotten any of the new subscribers
818
+ expect(monitoring.present_subscribers.length).to eq(1)
819
+ expect(monitoring.subscribers[Mongo::Monitoring::SERVER_HEARTBEAT].length).to eq(1)
820
+ end
821
+ end
822
+
823
+ shared_examples_for 'duplicated client with reused monitoring' do
824
+ let(:monitoring) { client.send(:monitoring) }
825
+ let(:new_monitoring) { new_client.send(:monitoring) }
826
+
827
+ it 'reuses monitoring' do
828
+ expect(new_monitoring).to eql(monitoring)
829
+ end
830
+ end
831
+
832
+ shared_examples_for 'duplicated client with clean slate monitoring' do
833
+ let(:monitoring) { client.send(:monitoring) }
834
+ let(:new_monitoring) { new_client.send(:monitoring) }
835
+
836
+ it 'does not reuse monitoring' do
837
+ expect(new_monitoring).not_to eql(monitoring)
838
+ end
839
+
840
+ it 'resets monitoring subscribers' do
841
+ monitoring.subscribers.clear
842
+ client.subscribe(Mongo::Monitoring::SERVER_HEARTBEAT, EventSubscriber.new)
843
+ expect(monitoring.present_subscribers.length).to eq(1)
844
+ expect(monitoring.subscribers[Mongo::Monitoring::SERVER_HEARTBEAT].length).to eq(1)
845
+
846
+ # this duplicates the client
847
+ # 7 is how many subscribers driver sets up by default
848
+ expect(new_monitoring.present_subscribers.length).to eq(7)
849
+ # ... none of which are for heartbeats
850
+ expect(new_monitoring.subscribers[Mongo::Monitoring::SERVER_HEARTBEAT].length).to eq(0)
851
+ end
852
+
853
+ it 'does not change subscribers on original client' do
854
+ monitoring.subscribers.clear
855
+ client.subscribe(Mongo::Monitoring::SERVER_HEARTBEAT, EventSubscriber.new)
856
+ expect(monitoring.present_subscribers.length).to eq(1)
857
+ expect(monitoring.subscribers[Mongo::Monitoring::SERVER_HEARTBEAT].length).to eq(1)
858
+
859
+ new_client.subscribe(Mongo::Monitoring::SERVER_HEARTBEAT, EventSubscriber.new)
860
+ new_client.subscribe(Mongo::Monitoring::SERVER_HEARTBEAT, EventSubscriber.new)
861
+ # 7 default subscribers + heartbeat
862
+ expect(new_monitoring.present_subscribers.length).to eq(8)
863
+ # the heartbeat subscriber on the original client is not inherited
864
+ expect(new_monitoring.subscribers[Mongo::Monitoring::SERVER_HEARTBEAT].length).to eq(2)
865
+ # original client should not have gotten any of the new subscribers
866
+ expect(monitoring.present_subscribers.length).to eq(1)
867
+ expect(monitoring.subscribers[Mongo::Monitoring::SERVER_HEARTBEAT].length).to eq(1)
868
+ end
869
+ end
870
+
871
+ describe '#use' do
872
+
873
+ let(:client) do
874
+ new_local_client_nmio(['127.0.0.1:27017'], :database => SpecConfig.instance.test_db)
875
+ end
876
+
877
+ shared_examples_for 'a database switching object' do
878
+
879
+ it 'returns the new client' do
880
+ expect(client.send(:database).name).to eq('ruby-driver')
881
+ end
882
+
883
+ it 'keeps the same cluster' do
884
+ expect(database.cluster).to equal(client.cluster)
885
+ end
886
+ end
887
+
888
+ context 'when provided a string' do
889
+
890
+ let(:database) do
891
+ client.use('testdb')
892
+ end
893
+
894
+ it_behaves_like 'a database switching object'
895
+ end
896
+
897
+ context 'when provided a symbol' do
898
+
899
+ let(:database) do
900
+ client.use(:testdb)
901
+ end
902
+
903
+ it_behaves_like 'a database switching object'
904
+ end
905
+
906
+ context 'when providing nil' do
907
+
908
+ it 'raises an exception' do
909
+ expect {
910
+ client.use(nil)
911
+ }.to raise_error(Mongo::Error::InvalidDatabaseName)
912
+ end
913
+ end
914
+ end
915
+
916
+ describe '#with' do
917
+
918
+ let(:client) do
919
+ new_local_client_nmio(['127.0.0.1:27017'], :database => SpecConfig.instance.test_db)
920
+ end
921
+
922
+ context 'when providing nil' do
923
+
924
+ it 'returns the cloned client' do
925
+ expect(client.with(nil)).to eq(client)
926
+ end
927
+ end
928
+
929
+ context 'when the app_name is changed' do
930
+
931
+ let(:client) do
932
+ authorized_client
933
+ end
934
+
935
+ let!(:original_options) do
936
+ client.options
937
+ end
938
+
939
+ let(:new_options) do
940
+ { app_name: 'client_test' }
941
+ end
942
+
943
+ let!(:new_client) do
944
+ authorized_client.with(new_options)
945
+ end
946
+
947
+ it 'returns a new client' do
948
+ expect(new_client).not_to equal(client)
949
+ end
950
+
951
+ it 'replaces the existing options' do
952
+ expect(new_client.options).to eq(client.options.merge(new_options))
953
+ end
954
+
955
+ it 'does not modify the original client' do
956
+ expect(client.options).to eq(original_options)
957
+ end
958
+
959
+ it 'does not keep the same cluster' do
960
+ expect(new_client.cluster).not_to be(client.cluster)
961
+ end
962
+ end
963
+
964
+ context 'when the write concern is not changed' do
965
+
966
+ let(:client) do
967
+ new_local_client_nmio(
968
+ ['127.0.0.1:27017'],
969
+ :read => { :mode => :secondary }, :write => { :w => 1 }, :database => SpecConfig.instance.test_db
970
+ )
971
+ end
972
+
973
+ let!(:new_client) do
974
+ client.with(:read => { :mode => :primary })
975
+ end
976
+
977
+ let(:new_options) do
978
+ Mongo::Options::Redacted.new(:read => { :mode => :primary },
979
+ :write => { :w => 1 },
980
+ monitoring_io: false,
981
+ :database => SpecConfig.instance.test_db)
982
+ end
983
+
984
+ let(:original_options) do
985
+ Mongo::Options::Redacted.new(:read => { :mode => :secondary },
986
+ :write => { :w => 1 },
987
+ monitoring_io: false,
988
+ :database => SpecConfig.instance.test_db)
989
+ end
990
+
991
+ it 'returns a new client' do
992
+ expect(new_client).not_to equal(client)
993
+ end
994
+
995
+ it 'replaces the existing options' do
996
+ expect(new_client.options).to eq(new_options)
997
+ end
998
+
999
+ it 'does not modify the original client' do
1000
+ expect(client.options).to eq(original_options)
1001
+ end
1002
+
1003
+ it 'keeps the same cluster' do
1004
+ expect(new_client.cluster).to be(client.cluster)
1005
+ end
1006
+ end
1007
+
1008
+ context 'when the write concern is changed' do
1009
+
1010
+ let(:client) do
1011
+ new_local_client(['127.0.0.1:27017'], :write => { :w => 1 }, :database => SpecConfig.instance.test_db)
1012
+ end
1013
+
1014
+ context 'when the write concern has not been accessed' do
1015
+
1016
+ let!(:new_client) do
1017
+ client.with(:write => { :w => 0 })
1018
+ end
1019
+
1020
+ let(:get_last_error) do
1021
+ new_client.write_concern.get_last_error
1022
+ end
1023
+
1024
+ it 'returns the correct write concern' do
1025
+ expect(get_last_error).to be_nil
1026
+ end
1027
+ end
1028
+
1029
+ context 'when the write concern has been accessed' do
1030
+
1031
+ let!(:new_client) do
1032
+ client.write_concern
1033
+ client.with(:write => { :w => 0 })
1034
+ end
1035
+
1036
+ let(:get_last_error) do
1037
+ new_client.write_concern.get_last_error
1038
+ end
1039
+
1040
+ it 'returns the correct write concern' do
1041
+ expect(get_last_error).to be_nil
1042
+ end
1043
+ end
1044
+ end
1045
+
1046
+ context 'when an invalid option is provided' do
1047
+
1048
+ let(:new_client) do
1049
+ client.with(invalid: :option, ssl: false)
1050
+ end
1051
+
1052
+ it 'does not set the invalid option' do
1053
+ expect(new_client.options.keys).not_to include('invalid')
1054
+ end
1055
+
1056
+ it 'sets the valid options' do
1057
+ expect(new_client.options.keys).to include('ssl')
1058
+ end
1059
+
1060
+ it 'warns that an invalid option has been specified' do
1061
+ expect(Mongo::Logger.logger).to receive(:warn)
1062
+ expect(new_client.options.keys).not_to include('invalid')
1063
+ end
1064
+ end
1065
+
1066
+ context 'when client is created with ipv6 address' do
1067
+ let(:client) do
1068
+ new_local_client_nmio(['[::1]:27017'], :database => SpecConfig.instance.test_db)
1069
+ end
1070
+
1071
+ context 'when providing nil' do
1072
+
1073
+ it 'returns the cloned client' do
1074
+ expect(client.with(nil)).to eq(client)
1075
+ end
1076
+ end
1077
+
1078
+ context 'when changing options' do
1079
+ let(:new_options) do
1080
+ { app_name: 'client_test' }
1081
+ end
1082
+
1083
+ let!(:new_client) do
1084
+ client.with(new_options)
1085
+ end
1086
+
1087
+ it 'returns a new client' do
1088
+ expect(new_client).not_to equal(client)
1089
+ end
1090
+ end
1091
+ end
1092
+
1093
+ context 'when new client has a new cluster' do
1094
+ let(:client) do
1095
+ new_local_client(['127.0.0.1:27017'], :database => SpecConfig.instance.test_db)
1096
+ end
1097
+ let(:new_client) do
1098
+ client.with(app_name: 'client_construction_spec').tap do |new_client|
1099
+ expect(new_client.cluster).not_to eql(client.cluster)
1100
+ end
1101
+ end
1102
+
1103
+ it_behaves_like 'duplicated client with clean slate monitoring'
1104
+ end
1105
+
1106
+ context 'when new client shares cluster with original client' do
1107
+ let(:new_client) do
1108
+ client.with(database: 'client_construction_spec').tap do |new_client|
1109
+ expect(new_client.cluster).to eql(client.cluster)
1110
+ end
1111
+ end
1112
+
1113
+ it_behaves_like 'duplicated client with reused monitoring'
1114
+ end
1115
+
1116
+ # Since we either reuse monitoring or reset it to a clean slate
1117
+ # in #with, the consistent behavior is to never transfer sdam_proc to
1118
+ # the new client.
1119
+ context 'when sdam_proc is given on original client' do
1120
+ let(:subscriber) { EventSubscriber.new }
1121
+
1122
+ let(:sdam_proc) do
1123
+ Proc.new do |client|
1124
+ client.subscribe(Mongo::Monitoring::SERVER_HEARTBEAT, subscriber)
1125
+ end
1126
+ end
1127
+
1128
+ let(:new_client) { client.with(database: 'foo') }
1129
+
1130
+ it 'does not copy sdam_proc option to new client' do
1131
+ client = new_local_client(['a'], sdam_proc: sdam_proc)
1132
+ expect(new_client.options[:sdam_proc]).to be nil
1133
+ end
1134
+
1135
+ it 'does not notify subscribers set up by sdam_proc' do
1136
+ client = new_local_client(['a'], sdam_proc: sdam_proc)
1137
+ expect(subscriber.started_events.length).to eq 1
1138
+ subscriber.started_events.clear
1139
+
1140
+ new_client
1141
+ expect(subscriber.started_events.length).to eq 0
1142
+ end
1143
+ end
1144
+ end
1145
+
1146
+ describe '#dup' do
1147
+
1148
+ let(:client) do
1149
+ new_local_client(
1150
+ ['127.0.0.1:27017'],
1151
+ :read => { :mode => :primary },
1152
+ :database => SpecConfig.instance.test_db
1153
+ )
1154
+ end
1155
+
1156
+ let(:new_client) { client.dup }
1157
+
1158
+ it 'creates a client with Redacted options' do
1159
+ expect(new_client.options).to be_a(Mongo::Options::Redacted)
1160
+ end
1161
+
1162
+ it_behaves_like 'duplicated client with reused monitoring'
1163
+ end
1164
+ end