mongo 2.15.1 → 2.16.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (326) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/README.md +1 -1
  4. data/lib/mongo/bulk_write.rb +2 -2
  5. data/lib/mongo/client.rb +45 -5
  6. data/lib/mongo/cluster/periodic_executor.rb +4 -3
  7. data/lib/mongo/cluster/reapers/cursor_reaper.rb +76 -43
  8. data/lib/mongo/cluster/sdam_flow.rb +9 -3
  9. data/lib/mongo/cluster/topology/base.rb +13 -9
  10. data/lib/mongo/cluster/topology/load_balanced.rb +102 -0
  11. data/lib/mongo/cluster/topology.rb +28 -8
  12. data/lib/mongo/cluster.rb +136 -51
  13. data/lib/mongo/collection/view/aggregation.rb +5 -10
  14. data/lib/mongo/collection/view/builder/aggregation.rb +6 -5
  15. data/lib/mongo/collection/view/builder/map_reduce.rb +12 -49
  16. data/lib/mongo/collection/view/builder.rb +0 -4
  17. data/lib/mongo/collection/view/iterable.rb +42 -18
  18. data/lib/mongo/collection/view/map_reduce.rb +39 -15
  19. data/lib/mongo/collection/view/readable.rb +60 -51
  20. data/lib/mongo/collection/view/writable.rb +178 -175
  21. data/lib/mongo/collection/view.rb +15 -21
  22. data/lib/mongo/collection.rb +13 -13
  23. data/lib/mongo/cursor/kill_spec.rb +38 -0
  24. data/lib/mongo/cursor.rb +62 -31
  25. data/lib/mongo/database/view.rb +1 -1
  26. data/lib/mongo/error/bad_load_balancer_target.rb +26 -0
  27. data/lib/mongo/error/missing_service_id.rb +26 -0
  28. data/lib/mongo/error/no_service_connection_available.rb +49 -0
  29. data/lib/mongo/error/notable.rb +7 -0
  30. data/lib/mongo/error.rb +3 -0
  31. data/lib/mongo/grid/fs_bucket.rb +21 -2
  32. data/lib/mongo/id.rb +7 -5
  33. data/lib/mongo/index/view.rb +22 -41
  34. data/lib/mongo/monitoring/event/cmap/pool_cleared.rb +7 -4
  35. data/lib/mongo/monitoring/event/command_failed.rb +1 -1
  36. data/lib/mongo/monitoring/event/command_started.rb +2 -0
  37. data/lib/mongo/monitoring/publishable.rb +2 -2
  38. data/lib/mongo/operation/aggregate/command.rb +8 -0
  39. data/lib/mongo/operation/context.rb +19 -1
  40. data/lib/mongo/operation/count/command.rb +6 -0
  41. data/lib/mongo/operation/count/op_msg.rb +6 -0
  42. data/lib/mongo/operation/create/command.rb +7 -1
  43. data/lib/mongo/operation/create/op_msg.rb +7 -0
  44. data/lib/mongo/operation/create_index/command.rb +17 -1
  45. data/lib/mongo/operation/create_index/op_msg.rb +17 -4
  46. data/lib/mongo/operation/delete/command.rb +6 -3
  47. data/lib/mongo/operation/delete/legacy.rb +9 -2
  48. data/lib/mongo/operation/delete/op_msg.rb +8 -1
  49. data/lib/mongo/operation/distinct/command.rb +6 -0
  50. data/lib/mongo/operation/distinct/op_msg.rb +7 -0
  51. data/lib/mongo/operation/explain/command.rb +13 -1
  52. data/lib/mongo/operation/explain/legacy.rb +12 -5
  53. data/lib/mongo/operation/explain/op_msg.rb +9 -1
  54. data/lib/mongo/operation/find/builder/command.rb +110 -0
  55. data/lib/mongo/{collection/view → operation/find}/builder/flags.rb +10 -14
  56. data/lib/mongo/operation/find/builder/legacy.rb +123 -0
  57. data/lib/mongo/{collection/view → operation/find}/builder/modifiers.rb +31 -25
  58. data/lib/mongo/{cursor → operation/find}/builder.rb +4 -4
  59. data/lib/mongo/operation/find/command.rb +9 -0
  60. data/lib/mongo/operation/find/legacy.rb +10 -1
  61. data/lib/mongo/operation/find/op_msg.rb +12 -0
  62. data/lib/mongo/operation/find.rb +1 -0
  63. data/lib/mongo/operation/get_more/command.rb +1 -0
  64. data/lib/mongo/operation/get_more/command_builder.rb +38 -0
  65. data/lib/mongo/operation/get_more/op_msg.rb +1 -0
  66. data/lib/mongo/operation/get_more.rb +1 -0
  67. data/lib/mongo/operation/kill_cursors/command.rb +8 -0
  68. data/lib/mongo/operation/kill_cursors/command_builder.rb +35 -0
  69. data/lib/mongo/operation/kill_cursors/legacy.rb +2 -1
  70. data/lib/mongo/operation/kill_cursors/op_msg.rb +10 -0
  71. data/lib/mongo/operation/kill_cursors.rb +1 -0
  72. data/lib/mongo/operation/map_reduce/command.rb +8 -0
  73. data/lib/mongo/operation/map_reduce/op_msg.rb +1 -1
  74. data/lib/mongo/operation/shared/executable.rb +15 -1
  75. data/lib/mongo/operation/shared/polymorphic_operation.rb +1 -1
  76. data/lib/mongo/operation/shared/read_preference_supported.rb +3 -1
  77. data/lib/mongo/operation/shared/response_handling.rb +1 -0
  78. data/lib/mongo/operation/shared/sessions_supported.rb +12 -12
  79. data/lib/mongo/operation/shared/specifiable.rb +11 -29
  80. data/lib/mongo/operation/shared/validatable.rb +87 -0
  81. data/lib/mongo/operation/shared/write.rb +1 -1
  82. data/lib/mongo/operation/update/command.rb +6 -3
  83. data/lib/mongo/operation/update/legacy.rb +19 -11
  84. data/lib/mongo/operation/update/op_msg.rb +7 -4
  85. data/lib/mongo/operation/write_command/command.rb +51 -0
  86. data/lib/mongo/operation/write_command/op_msg.rb +43 -0
  87. data/lib/mongo/operation/write_command.rb +32 -0
  88. data/lib/mongo/operation.rb +10 -0
  89. data/lib/mongo/protocol/query.rb +35 -18
  90. data/lib/mongo/server/connection.rb +25 -3
  91. data/lib/mongo/server/connection_base.rb +12 -1
  92. data/lib/mongo/server/connection_common.rb +38 -1
  93. data/lib/mongo/server/connection_pool/generation_manager.rb +71 -0
  94. data/lib/mongo/server/connection_pool.rb +100 -27
  95. data/lib/mongo/server/description/features.rb +17 -16
  96. data/lib/mongo/server/description/load_balancer.rb +33 -0
  97. data/lib/mongo/server/description.rb +85 -6
  98. data/lib/mongo/server/monitor/connection.rb +5 -6
  99. data/lib/mongo/server/monitor.rb +2 -1
  100. data/lib/mongo/server/pending_connection.rb +47 -31
  101. data/lib/mongo/server.rb +73 -26
  102. data/lib/mongo/server_selector/base.rb +5 -1
  103. data/lib/mongo/session/session_pool.rb +11 -0
  104. data/lib/mongo/session.rb +21 -1
  105. data/lib/mongo/socket/ocsp_verifier.rb +6 -37
  106. data/lib/mongo/uri/options_mapper.rb +1 -0
  107. data/lib/mongo/uri/srv_protocol.rb +6 -8
  108. data/lib/mongo/uri.rb +18 -0
  109. data/lib/mongo/utils.rb +0 -7
  110. data/lib/mongo/version.rb +1 -1
  111. data/mongo.gemspec +1 -1
  112. data/spec/integration/auth_spec.rb +31 -1
  113. data/spec/integration/awaited_ismaster_spec.rb +1 -1
  114. data/spec/integration/bulk_write_spec.rb +1 -1
  115. data/spec/integration/change_stream_spec.rb +3 -3
  116. data/spec/integration/client_construction_spec.rb +54 -0
  117. data/spec/integration/client_side_encryption/auto_encryption_bulk_writes_spec.rb +1 -1
  118. data/spec/integration/client_side_encryption/auto_encryption_command_monitoring_spec.rb +1 -1
  119. data/spec/integration/client_side_encryption/bson_size_limit_spec.rb +1 -1
  120. data/spec/integration/client_side_encryption/data_key_spec.rb +1 -1
  121. data/spec/integration/client_spec.rb +2 -0
  122. data/spec/integration/command_monitoring_spec.rb +1 -1
  123. data/spec/integration/command_spec.rb +1 -1
  124. data/spec/integration/connection_spec.rb +52 -35
  125. data/spec/integration/crud_spec.rb +174 -1
  126. data/spec/integration/cursor_pinning_spec.rb +121 -0
  127. data/spec/integration/cursor_reaping_spec.rb +8 -4
  128. data/spec/integration/fork_reconnect_spec.rb +1 -5
  129. data/spec/integration/get_more_spec.rb +1 -1
  130. data/spec/integration/heartbeat_events_spec.rb +1 -1
  131. data/spec/integration/map_reduce_spec.rb +77 -0
  132. data/spec/integration/query_cache_spec.rb +2 -2
  133. data/spec/integration/query_cache_transactions_spec.rb +1 -1
  134. data/spec/integration/read_concern_spec.rb +1 -1
  135. data/spec/integration/read_preference_spec.rb +1 -1
  136. data/spec/integration/reconnect_spec.rb +30 -12
  137. data/spec/integration/retryable_errors_spec.rb +1 -1
  138. data/spec/integration/retryable_writes/retryable_writes_36_and_older_spec.rb +1 -1
  139. data/spec/integration/retryable_writes/retryable_writes_40_and_newer_spec.rb +1 -1
  140. data/spec/integration/sdam_error_handling_spec.rb +5 -3
  141. data/spec/integration/sdam_events_spec.rb +35 -19
  142. data/spec/integration/sdam_prose_spec.rb +1 -1
  143. data/spec/integration/server_monitor_spec.rb +1 -0
  144. data/spec/integration/server_selector_spec.rb +22 -5
  145. data/spec/integration/server_spec.rb +2 -0
  146. data/spec/integration/srv_monitoring_spec.rb +1 -1
  147. data/spec/integration/step_down_spec.rb +1 -1
  148. data/spec/integration/transaction_pinning_spec.rb +120 -0
  149. data/spec/integration/versioned_api_examples_spec.rb +45 -0
  150. data/spec/integration/x509_auth_spec.rb +1 -1
  151. data/spec/lite_spec_helper.rb +1 -2
  152. data/spec/mongo/address/unix_spec.rb +1 -0
  153. data/spec/mongo/auth/cr_spec.rb +2 -3
  154. data/spec/mongo/auth/ldap_spec.rb +2 -3
  155. data/spec/mongo/auth/scram_spec.rb +2 -3
  156. data/spec/mongo/auth/user/view_spec.rb +1 -1
  157. data/spec/mongo/auth/x509_spec.rb +2 -3
  158. data/spec/mongo/bulk_write_spec.rb +3 -3
  159. data/spec/mongo/client_construction_spec.rb +259 -28
  160. data/spec/mongo/client_spec.rb +6 -4
  161. data/spec/mongo/cluster/cursor_reaper_spec.rb +36 -21
  162. data/spec/mongo/cluster/periodic_executor_spec.rb +3 -1
  163. data/spec/mongo/cluster_spec.rb +44 -3
  164. data/spec/mongo/collection/view/aggregation_spec.rb +1 -1
  165. data/spec/mongo/collection/view/builder/find_command_spec.rb +4 -0
  166. data/spec/mongo/collection/view/builder/op_query_spec.rb +4 -0
  167. data/spec/mongo/collection/view/map_reduce_spec.rb +1 -1
  168. data/spec/mongo/collection_crud_spec.rb +7 -2
  169. data/spec/mongo/collection_ddl_spec.rb +1 -1
  170. data/spec/mongo/collection_spec.rb +1 -1
  171. data/spec/mongo/cursor/builder/get_more_command_spec.rb +4 -0
  172. data/spec/mongo/cursor/builder/op_get_more_spec.rb +4 -0
  173. data/spec/mongo/cursor_spec.rb +15 -5
  174. data/spec/mongo/database_spec.rb +15 -15
  175. data/spec/mongo/error/operation_failure_heavy_spec.rb +1 -1
  176. data/spec/mongo/grid/fs_bucket_spec.rb +18 -12
  177. data/spec/mongo/grid/stream/write_spec.rb +3 -9
  178. data/spec/mongo/grid/stream_spec.rb +1 -1
  179. data/spec/mongo/index/view_spec.rb +2 -2
  180. data/spec/mongo/operation/delete/op_msg_spec.rb +1 -1
  181. data/spec/mongo/{collection/view → operation/find}/builder/flags_spec.rb +2 -2
  182. data/spec/mongo/{collection/view → operation/find}/builder/modifiers_spec.rb +2 -2
  183. data/spec/mongo/operation/find/legacy_spec.rb +1 -0
  184. data/spec/mongo/operation/insert/bulk_spec.rb +1 -1
  185. data/spec/mongo/operation/insert/op_msg_spec.rb +1 -1
  186. data/spec/mongo/operation/kill_cursors_spec.rb +4 -1
  187. data/spec/mongo/operation/read_preference_legacy_spec.rb +4 -0
  188. data/spec/mongo/operation/read_preference_op_msg_spec.rb +2 -0
  189. data/spec/mongo/operation/update/bulk_spec.rb +1 -1
  190. data/spec/mongo/operation/update/op_msg_spec.rb +1 -1
  191. data/spec/mongo/query_cache_spec.rb +6 -2
  192. data/spec/mongo/server/connection_common_spec.rb +62 -11
  193. data/spec/mongo/server/connection_pool_spec.rb +73 -7
  194. data/spec/mongo/server/connection_spec.rb +138 -43
  195. data/spec/mongo/server/description_spec.rb +1 -1
  196. data/spec/mongo/server/monitor_spec.rb +4 -3
  197. data/spec/mongo/session/session_pool_spec.rb +42 -10
  198. data/spec/mongo/session_transaction_spec.rb +15 -30
  199. data/spec/mongo/socket/unix_spec.rb +1 -0
  200. data/spec/mongo/uri_option_parsing_spec.rb +38 -5
  201. data/spec/runners/change_streams/test.rb +1 -1
  202. data/spec/runners/cmap.rb +1 -1
  203. data/spec/runners/connection_string.rb +7 -3
  204. data/spec/runners/crud/operation.rb +5 -3
  205. data/spec/runners/crud/requirement.rb +1 -0
  206. data/spec/runners/crud.rb +1 -1
  207. data/spec/runners/sdam.rb +2 -1
  208. data/spec/runners/transactions/test.rb +2 -2
  209. data/spec/runners/unified/assertions.rb +2 -3
  210. data/spec/runners/unified/event_subscriber.rb +2 -2
  211. data/spec/runners/unified/test.rb +3 -0
  212. data/spec/runners/unified.rb +1 -1
  213. data/spec/shared/lib/mrss/constraints.rb +11 -5
  214. data/spec/shared/lib/mrss/event_subscriber.rb +200 -0
  215. data/spec/shared/lib/mrss/server_version_registry.rb +17 -12
  216. data/spec/shared/share/Dockerfile.erb +2 -1
  217. data/spec/shared/shlib/server.sh +70 -20
  218. data/spec/spec_tests/change_streams_spec.rb +1 -1
  219. data/spec/spec_tests/cmap_spec.rb +4 -1
  220. data/spec/spec_tests/command_monitoring_spec.rb +2 -2
  221. data/spec/spec_tests/data/command_monitoring/find.yml +9 -9
  222. data/spec/spec_tests/data/crud/read/aggregate-collation.yml +2 -1
  223. data/spec/spec_tests/data/crud/read/aggregate-out.yml +1 -0
  224. data/spec/spec_tests/data/crud/read/count-collation.yml +2 -1
  225. data/spec/spec_tests/data/crud/read/distinct-collation.yml +2 -1
  226. data/spec/spec_tests/data/crud/read/find-collation.yml +2 -1
  227. data/spec/spec_tests/data/crud/write/bulkWrite-collation.yml +2 -1
  228. data/spec/spec_tests/data/crud/write/deleteMany-collation.yml +2 -1
  229. data/spec/spec_tests/data/crud/write/deleteOne-collation.yml +2 -1
  230. data/spec/spec_tests/data/crud/write/findOneAndDelete-collation.yml +3 -2
  231. data/spec/spec_tests/data/crud/write/findOneAndReplace-collation.yml +2 -1
  232. data/spec/spec_tests/data/crud/write/findOneAndUpdate-collation.yml +3 -2
  233. data/spec/spec_tests/data/crud/write/replaceOne-collation.yml +3 -2
  234. data/spec/spec_tests/data/crud/write/updateMany-collation.yml +2 -1
  235. data/spec/spec_tests/data/crud/write/updateOne-collation.yml +2 -1
  236. data/spec/spec_tests/data/load_balancers/event-monitoring.yml +99 -0
  237. data/spec/spec_tests/data/load_balancers/lb-connection-establishment.yml +36 -0
  238. data/spec/spec_tests/data/load_balancers/non-lb-connection-establishment.yml +56 -0
  239. data/spec/spec_tests/data/load_balancers/server-selection.yml +50 -0
  240. data/spec/spec_tests/data/retryable_reads/changeStreams-client.watch-serverErrors.yml +1 -1
  241. data/spec/spec_tests/data/retryable_reads/changeStreams-client.watch.yml +1 -1
  242. data/spec/spec_tests/data/retryable_reads/changeStreams-db.coll.watch-serverErrors.yml +1 -1
  243. data/spec/spec_tests/data/retryable_reads/changeStreams-db.coll.watch.yml +1 -1
  244. data/spec/spec_tests/data/retryable_reads/changeStreams-db.watch-serverErrors.yml +1 -1
  245. data/spec/spec_tests/data/retryable_reads/changeStreams-db.watch.yml +1 -1
  246. data/spec/spec_tests/data/retryable_reads/mapReduce.yml +3 -1
  247. data/spec/spec_tests/data/sdam/load-balanced/discover_load_balancer.yml +25 -0
  248. data/spec/spec_tests/data/sdam_integration/find-network-error.yml +2 -0
  249. data/spec/spec_tests/data/sdam_integration/find-shutdown-error.yml +2 -0
  250. data/spec/spec_tests/data/sdam_integration/hello-command-error.yml +3 -1
  251. data/spec/spec_tests/data/sdam_integration/hello-network-error.yml +3 -1
  252. data/spec/spec_tests/data/sdam_integration/hello-timeout.yml +2 -0
  253. data/spec/spec_tests/data/sdam_integration/insert-network-error.yml +2 -0
  254. data/spec/spec_tests/data/sdam_integration/insert-shutdown-error.yml +2 -0
  255. data/spec/spec_tests/data/sdam_monitoring/load_balancer.yml +65 -0
  256. data/spec/spec_tests/data/seed_list_discovery/load-balanced/loadBalanced-directConnection.yml +13 -0
  257. data/spec/spec_tests/data/seed_list_discovery/load-balanced/loadBalanced-replicaSet-errors.yml +6 -0
  258. data/spec/spec_tests/data/seed_list_discovery/load-balanced/loadBalanced-true-multiple-hosts.yml +5 -0
  259. data/spec/spec_tests/data/seed_list_discovery/load-balanced/loadBalanced-true-txt.yml +10 -0
  260. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/direct-connection-false.yml +0 -0
  261. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/direct-connection-true.yml +0 -0
  262. data/spec/spec_tests/data/seed_list_discovery/replica-set/encoded-userinfo-and-db.yml +15 -0
  263. data/spec/spec_tests/data/seed_list_discovery/replica-set/loadBalanced-false-txt.yml +10 -0
  264. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/longer-parent-in-return.yml +0 -0
  265. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/misformatted-option.yml +0 -0
  266. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/no-results.yml +0 -0
  267. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/not-enough-parts.yml +0 -0
  268. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/one-result-default-port.yml +0 -0
  269. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/one-txt-record-multiple-strings.yml +0 -0
  270. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/one-txt-record.yml +0 -0
  271. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/parent-part-mismatch1.yml +0 -0
  272. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/parent-part-mismatch2.yml +0 -0
  273. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/parent-part-mismatch3.yml +0 -0
  274. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/parent-part-mismatch4.yml +0 -0
  275. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/parent-part-mismatch5.yml +0 -0
  276. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/returned-parent-too-short.yml +0 -0
  277. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/returned-parent-wrong.yml +0 -0
  278. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/two-results-default-port.yml +0 -0
  279. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/two-results-nonstandard-port.yml +0 -0
  280. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/two-txt-records.yml +0 -0
  281. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/txt-record-not-allowed-option.yml +0 -0
  282. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/txt-record-with-overridden-ssl-option.yml +0 -0
  283. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/txt-record-with-overridden-uri-option.yml +0 -0
  284. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/txt-record-with-unallowed-option.yml +0 -0
  285. data/spec/spec_tests/data/seed_list_discovery/replica-set/uri-with-admin-database.yml +13 -0
  286. data/spec/spec_tests/data/seed_list_discovery/replica-set/uri-with-auth.yml +12 -0
  287. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/uri-with-port.yml +0 -0
  288. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/uri-with-two-hosts.yml +0 -0
  289. data/spec/spec_tests/data/transactions/retryable-abort-errorLabels.yml +2 -0
  290. data/spec/spec_tests/data/transactions/retryable-abort.yml +2 -0
  291. data/spec/spec_tests/data/transactions/retryable-commit-errorLabels.yml +2 -0
  292. data/spec/spec_tests/data/transactions/retryable-commit.yml +2 -0
  293. data/spec/spec_tests/data/transactions/retryable-writes.yml +2 -0
  294. data/spec/spec_tests/data/uri_options/connection-options.yml +60 -0
  295. data/spec/spec_tests/load_balancers_spec.rb +15 -0
  296. data/spec/spec_tests/retryable_reads_spec.rb +2 -2
  297. data/spec/spec_tests/retryable_writes_spec.rb +1 -1
  298. data/spec/spec_tests/sdam_integration_spec.rb +1 -1
  299. data/spec/spec_tests/sdam_monitoring_spec.rb +10 -5
  300. data/spec/spec_tests/sdam_spec.rb +1 -1
  301. data/spec/spec_tests/seed_list_discovery_spec.rb +118 -0
  302. data/spec/spec_tests/uri_options_spec.rb +4 -4
  303. data/spec/stress/fork_reconnect_stress_spec.rb +1 -5
  304. data/spec/support/certificates/atlas-ocsp-ca.crt +82 -90
  305. data/spec/support/certificates/atlas-ocsp.crt +127 -122
  306. data/spec/support/common_shortcuts.rb +2 -3
  307. data/spec/support/matchers.rb +13 -0
  308. data/spec/support/shared/auth_context.rb +16 -0
  309. data/spec/support/shared/session.rb +2 -2
  310. data/spec/support/spec_config.rb +9 -10
  311. data/spec/support/using_hash.rb +31 -0
  312. data/spec/support/utils.rb +1 -1
  313. data.tar.gz.sig +0 -0
  314. metadata +120 -76
  315. metadata.gz.sig +0 -0
  316. data/lib/mongo/collection/view/builder/find_command.rb +0 -173
  317. data/lib/mongo/collection/view/builder/op_query.rb +0 -94
  318. data/lib/mongo/cursor/builder/get_more_command.rb +0 -80
  319. data/lib/mongo/cursor/builder/kill_cursors_command.rb +0 -111
  320. data/lib/mongo/cursor/builder/op_get_more.rb +0 -64
  321. data/lib/mongo/cursor/builder/op_kill_cursors.rb +0 -106
  322. data/lib/mongo/server/context.rb +0 -72
  323. data/spec/mongo/cursor/builder/op_kill_cursors_spec.rb +0 -66
  324. data/spec/runners/unified/using_hash.rb +0 -34
  325. data/spec/spec_tests/dns_seedlist_discovery_spec.rb +0 -79
  326. data/spec/support/event_subscriber.rb +0 -221
@@ -5,7 +5,7 @@ require 'spec_helper'
5
5
 
6
6
  describe 'Command' do
7
7
 
8
- let(:subscriber) { EventSubscriber.new }
8
+ let(:subscriber) { Mrss::EventSubscriber.new }
9
9
 
10
10
  describe 'payload' do
11
11
  let(:server) { authorized_client.cluster.next_primary }
@@ -50,7 +50,7 @@ describe 'Connections' do
50
50
 
51
51
  context 'with sdam event subscription' do
52
52
 
53
- let(:subscriber) { EventSubscriber.new }
53
+ let(:subscriber) { Mrss::EventSubscriber.new }
54
54
  let(:client) do
55
55
  ClientRegistry.instance.global_client('authorized').with(app_name: 'connection_integration').tap do |client|
56
56
  client.subscribe(Mongo::Monitoring::SERVER_OPENING, subscriber)
@@ -246,43 +246,60 @@ describe 'Connections' do
246
246
 
247
247
  let(:client) { ClientRegistry.instance.global_client('authorized').with(app_name: 'wire_protocol_update') }
248
248
 
249
- it 'updates on hello response from non-monitoring connections' do
250
- # connect server
251
- client['test'].insert_one(test: 1)
249
+ context 'non-lb' do
250
+ require_topology :single, :replica_set, :sharded
252
251
 
253
- # kill background threads so that they are not interfering with
254
- # our mocked hello response
255
- client.cluster.servers.each do |server|
256
- server.monitor.stop!
252
+ it 'updates on handshake response from non-monitoring connections' do
253
+ # connect server
254
+ client['test'].insert_one(test: 1)
255
+
256
+ # kill background threads so that they are not interfering with
257
+ # our mocked hello response
258
+ client.cluster.servers.each do |server|
259
+ server.monitor.stop!
260
+ end
261
+
262
+ server = client.cluster.servers.first
263
+ expect(server.features.server_wire_versions.max >= 4).to be true
264
+ max_version = server.features.server_wire_versions.max
265
+
266
+ # Depending on server version, handshake here may return a
267
+ # description that compares equal to the one we got from a
268
+ # monitoring connection (pre-4.2) or not (4.2+).
269
+ # Since we do run SDAM flow on handshake responses on
270
+ # non-monitoring connections, force descriptions to be different
271
+ # by setting the existing description here to unknown.
272
+ server.monitor.instance_variable_set('@description',
273
+ Mongo::Server::Description.new(server.address))
274
+
275
+ RSpec::Mocks.with_temporary_scope do
276
+ # now pretend a handshake returned a different range
277
+ features = Mongo::Server::Description::Features.new(0..3)
278
+ # One Features instantiation is for SDAM event publication, this
279
+ # one always happens. The second one happens on servers
280
+ # where we do not negotiate auth mechanism.
281
+ expect(Mongo::Server::Description::Features).to receive(:new).at_least(:once).and_return(features)
282
+
283
+ connection = Mongo::Server::Connection.new(server, server.options)
284
+ expect(connection.connect!).to be true
285
+
286
+ # hello response should update server description via sdam flow,
287
+ # which includes wire version range
288
+ expect(server.features.server_wire_versions.max).to eq(3)
289
+ end
257
290
  end
291
+ end
292
+
293
+ context 'lb' do
294
+ require_topology :load_balanced
295
+
296
+ it 'does not update on handshake response from non-monitoring connections since there are not any' do
297
+ # connect server
298
+ client['test'].insert_one(test: 1)
258
299
 
259
- server = client.cluster.servers.first
260
- expect(server.features.server_wire_versions.max >= 4).to be true
261
- max_version = server.features.server_wire_versions.max
262
-
263
- # Depending on server version, hello here may return a
264
- # description that compares equal to the one we got from a
265
- # monitoring connection (pre-4.2) or not (4.2+).
266
- # Since we do run SDAM flow on hello responses on
267
- # non-monitoring connections, force descriptions to be different
268
- # by setting the existing description here to unknown.
269
- server.monitor.instance_variable_set('@description',
270
- Mongo::Server::Description.new(server.address))
271
-
272
- RSpec::Mocks.with_temporary_scope do
273
- # now pretend a hello returned a different range
274
- features = Mongo::Server::Description::Features.new(0..3)
275
- # One Features instantiation is for SDAM event publication, this
276
- # one always happens. The second one happens on servers
277
- # where we do not negotiate auth mechanism.
278
- expect(Mongo::Server::Description::Features).to receive(:new).at_least(:once).and_return(features)
279
-
280
- connection = Mongo::Server::Connection.new(server, server.options)
281
- expect(connection.connect!).to be true
282
-
283
- # hello response should update server description via sdam flow,
284
- # which includes wire version range
285
- expect(server.features.server_wire_versions.max).to eq(3)
300
+ server = client.cluster.servers.first
301
+ server.load_balancer?.should be true
302
+ server.features.server_wire_versions.max.should be 0
286
303
  end
287
304
  end
288
305
  end
@@ -4,7 +4,8 @@
4
4
  require 'spec_helper'
5
5
 
6
6
  describe 'CRUD operations' do
7
- let(:collection) { authorized_client['crud_integration'] }
7
+ let(:client) { authorized_client }
8
+ let(:collection) { client['crud_integration'] }
8
9
 
9
10
  before do
10
11
  collection.delete_many
@@ -64,6 +65,178 @@ describe 'CRUD operations' do
64
65
  end
65
66
  end
66
67
  end
68
+
69
+ context 'with read concern' do
70
+ # Read concern requires 3.2+ server.
71
+ min_server_fcv '3.2'
72
+
73
+ context 'with read concern specified on operation level' do
74
+
75
+ it 'passes the read concern' do
76
+ event = Utils.get_command_event(client, 'find') do |client|
77
+ client['foo'].find({}, read_concern: {level: :local}).to_a
78
+ end
79
+ event.command.fetch('readConcern').should == {'level' => 'local'}
80
+ end
81
+ end
82
+
83
+ context 'with read concern specified on collection level' do
84
+
85
+ it 'passes the read concern' do
86
+ event = Utils.get_command_event(client, 'find') do |client|
87
+ client['foo', read_concern: {level: :local}].find.to_a
88
+ end
89
+ event.command.fetch('readConcern').should == {'level' => 'local'}
90
+ end
91
+ end
92
+
93
+ context 'with read concern specified on client level' do
94
+
95
+ let(:client) { authorized_client.with(read_concern: {level: :local}) }
96
+
97
+ it 'passes the read concern' do
98
+ event = Utils.get_command_event(client, 'find') do |client|
99
+ client['foo'].find.to_a
100
+ end
101
+ event.command.fetch('readConcern').should == {'level' => 'local'}
102
+ end
103
+ end
104
+ end
105
+
106
+ context 'with oplog_replay option' do
107
+ let(:collection_name) { 'crud_integration_oplog_replay' }
108
+
109
+ let(:oplog_query) do
110
+ {ts: {'$gt' => 1}}
111
+ end
112
+
113
+ context 'passed to operation' do
114
+ it 'passes the option' do
115
+ event = Utils.get_command_event(client, 'find') do |client|
116
+ client[collection_name].find(oplog_query, oplog_replay: true).to_a
117
+ end
118
+ event.command.fetch('oplogReplay').should be true
119
+ end
120
+
121
+ it 'warns' do
122
+ client.should receive(:log_warn).with('The :oplog_replay option is deprecated and ignored by MongoDB 4.4 and later')
123
+ client[collection_name].find(oplog_query, oplog_replay: true).to_a
124
+ end
125
+ end
126
+
127
+ context 'set on collection' do
128
+ it 'passes the option' do
129
+ event = Utils.get_command_event(client, 'find') do |client|
130
+ client[collection_name, oplog_replay: true].find(oplog_query).to_a
131
+ end
132
+ event.command.fetch('oplogReplay').should be true
133
+ end
134
+
135
+ it 'warns' do
136
+ client.should receive(:log_warn).with('The :oplog_replay option is deprecated and ignored by MongoDB 4.4 and later')
137
+ client[collection_name, oplog_replay: true].find(oplog_query).to_a
138
+ end
139
+ end
140
+ end
141
+ end
142
+
143
+ describe 'explain' do
144
+ context 'with explicit session' do
145
+ min_server_fcv '3.6'
146
+
147
+ it 'passes the session' do
148
+ client.start_session do |session|
149
+ event = Utils.get_command_event(client, 'explain') do |client|
150
+ client['foo'].find({}, session: session).explain.should be_explain_output
151
+ end
152
+ event.command.fetch('lsid').should == session.session_id
153
+ end
154
+ end
155
+ end
156
+
157
+ context 'with read preference specified on operation level' do
158
+ require_topology :sharded
159
+
160
+ # RUBY-2706
161
+ min_server_fcv '3.6'
162
+
163
+ it 'passes the read preference' do
164
+ event = Utils.get_command_event(client, 'explain') do |client|
165
+ client['foo'].find({}, read: {mode: :secondary_preferred}).explain.should be_explain_output
166
+ end
167
+ event.command.fetch('$readPreference').should == {'mode' => 'secondaryPreferred'}
168
+ end
169
+ end
170
+
171
+ context 'with read preference specified on collection level' do
172
+ require_topology :sharded
173
+
174
+ # RUBY-2706
175
+ min_server_fcv '3.6'
176
+
177
+ it 'passes the read preference' do
178
+ event = Utils.get_command_event(client, 'explain') do |client|
179
+ client['foo', read: {mode: :secondary_preferred}].find.explain.should be_explain_output
180
+ end
181
+ event.command.fetch('$readPreference').should == {'mode' => 'secondaryPreferred'}
182
+ end
183
+ end
184
+
185
+ context 'with read preference specified on client level' do
186
+ require_topology :sharded
187
+
188
+ # RUBY-2706
189
+ min_server_fcv '3.6'
190
+
191
+ let(:client) { authorized_client.with(read: {mode: :secondary_preferred}) }
192
+
193
+ it 'passes the read preference' do
194
+ event = Utils.get_command_event(client, 'explain') do |client|
195
+ client['foo'].find.explain.should be_explain_output
196
+ end
197
+ event.command.fetch('$readPreference').should == {'mode' => 'secondaryPreferred'}
198
+ end
199
+ end
200
+
201
+ context 'with read concern' do
202
+ # Read concern requires 3.2+ server.
203
+ min_server_fcv '3.2'
204
+
205
+ context 'with read concern specifed on operation level' do
206
+
207
+ # Read concern is not allowed in explain command, driver drops it.
208
+ it 'drops the read concern' do
209
+ event = Utils.get_command_event(client, 'explain') do |client|
210
+ client['foo'].find({}, read_concern: {level: :local}).explain.should have_key('queryPlanner')
211
+ end
212
+ event.command.should_not have_key('readConcern')
213
+ end
214
+ end
215
+
216
+ context 'with read concern specifed on collection level' do
217
+
218
+ # Read concern is not allowed in explain command, driver drops it.
219
+ it 'drops the read concern' do
220
+ event = Utils.get_command_event(client, 'explain') do |client|
221
+ client['foo', read_concern: {level: :local}].find.explain.should have_key('queryPlanner')
222
+ end
223
+ event.command.should_not have_key('readConcern')
224
+ end
225
+ end
226
+
227
+ context 'with read concern specifed on client level' do
228
+
229
+ let(:client) { authorized_client.with(read_concern: {level: :local}) }
230
+
231
+ # Read concern is not allowed in explain command, driver drops it.
232
+ it 'drops the read concern' do
233
+ event = Utils.get_command_event(client, 'explain') do |client|
234
+ client['foo'].find.explain.should have_key('queryPlanner')
235
+ end
236
+ event.command.should_not have_key('readConcern')
237
+ end
238
+ end
239
+ end
67
240
  end
68
241
 
69
242
  describe 'insert' do
@@ -0,0 +1,121 @@
1
+ # frozen_string_literal: true
2
+ # encoding: utf-8
3
+
4
+ require 'spec_helper'
5
+
6
+ describe 'Cursor pinning' do
7
+ let(:client) { authorized_client }
8
+ let(:collection_name) { 'cursor_pinning' }
9
+ let(:collection) { client[collection_name] }
10
+
11
+ before do
12
+ authorized_client[collection_name].insert_many([{test: 1}] * 200)
13
+ end
14
+
15
+ let(:server) { client.cluster.next_primary }
16
+
17
+ clean_slate
18
+
19
+ context 'non-lb' do
20
+ require_topology :single, :replica_set, :sharded
21
+ require_no_multi_mongos
22
+
23
+ # When not in load-balanced topology, iterating a cursor creates
24
+ # new connections as needed.
25
+
26
+ it 'creates new connections for iteration' do
27
+ server.pool.size.should == 0
28
+
29
+ # Use batch_size of 2 until RUBY-2727 is fixed.
30
+ enum = collection.find({}, batch_size: 2).to_enum
31
+ # Still zero because we haven't iterated
32
+ server.pool.size.should == 0
33
+
34
+ enum.next
35
+ enum.next
36
+ server.pool.size.should == 1
37
+
38
+ # Grab the connection that was used
39
+ server.with_connection do
40
+ # This requires a new connection
41
+ enum.next
42
+
43
+ server.pool.size.should == 2
44
+ end
45
+ end
46
+ end
47
+
48
+ context 'lb' do
49
+ require_topology :load_balanced
50
+
51
+ # In load-balanced topology, we cannot create new connections to a
52
+ # particular service.
53
+
54
+ context 'when no connection is available' do
55
+
56
+ it 'raises ConnectionCheckOutTimeout' do
57
+ server.pool.size.should == 0
58
+
59
+ enum = collection.find({}, batch_size: 1).to_enum
60
+ # Still zero because we haven't iterated
61
+ server.pool.size.should == 0
62
+
63
+ enum.next
64
+ server.pool.size.should == 1
65
+
66
+ # Grab the connection that was used
67
+ server.with_connection do
68
+ # This requires a new connection, but we cannot make one.
69
+ lambda do
70
+ enum.next
71
+ end.should raise_error(Mongo::Error::ConnectionCheckOutTimeout)
72
+
73
+ server.pool.size.should == 1
74
+ end
75
+ end
76
+ end
77
+
78
+ context 'when connection is available' do
79
+ require_multi_mongos
80
+
81
+ let(:client) { authorized_client.with(max_pool_size: 4) }
82
+
83
+ it 'uses the available connection' do
84
+ server.pool.size.should == 0
85
+
86
+ # Create 4 connections.
87
+
88
+ enums = []
89
+ connections = []
90
+ service_ids = []
91
+
92
+ 4.times do
93
+ view = collection.find({}, batch_size: 1)
94
+ enum = view.to_enum
95
+
96
+ enum.next
97
+
98
+ enums << enum
99
+ service_ids << view.cursor.initial_result.connection_description.service_id
100
+ connections << server.pool.check_out
101
+ end
102
+
103
+ service_ids.uniq.length.should be > 1
104
+
105
+ server.pool.size.should == 4
106
+
107
+ connections.each do |c|
108
+ server.pool.check_in(c)
109
+ end
110
+
111
+ # At this point, in theory, all connections are equally likely to
112
+ # be chosen, but we have cursors referencing more than one
113
+ # distinct service.
114
+ # Iterate each cursor to ensure they all continue to work.
115
+ enums.each do |enum|
116
+ enum.next
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
@@ -8,6 +8,8 @@ describe 'Cursor reaping' do
8
8
  # in MRI, I don't currently know how to force GC to run in JRuby
9
9
  require_mri
10
10
 
11
+ # Uncomment for debugging this test.
12
+ =begin
11
13
  around(:all) do |example|
12
14
  saved_level = Mongo::Logger.logger.level
13
15
  Mongo::Logger.logger.level = Logger::DEBUG
@@ -17,8 +19,9 @@ describe 'Cursor reaping' do
17
19
  Mongo::Logger.logger.level = saved_level
18
20
  end
19
21
  end
22
+ =end
20
23
 
21
- let(:subscriber) { EventSubscriber.new }
24
+ let(:subscriber) { Mrss::EventSubscriber.new }
22
25
 
23
26
  let(:client) do
24
27
  authorized_client.tap do |client|
@@ -57,10 +60,11 @@ describe 'Cursor reaping' do
57
60
  10.times do
58
61
  scope = collection.find.batch_size(2).no_cursor_timeout
59
62
 
60
- # there is no API for retrieving the cursor
63
+ # Begin iteration, creating the cursor
61
64
  scope.each.first
62
- # and keep the first cursor
63
- cursor_ids << scope.instance_variable_get('@cursor').id
65
+
66
+ scope.cursor.should_not be nil
67
+ cursor_ids << scope.cursor.id
64
68
  end
65
69
  end
66
70
  end
@@ -10,11 +10,7 @@ describe 'fork reconnect' do
10
10
  # On multi-shard sharded clusters a succeeding write request does not
11
11
  # guarantee that the next operation will succeed (since it could be sent to
12
12
  # another shard with a dead connection).
13
- require_no_multi_shard
14
-
15
- # On Ruby 2.3 $?.exitstatus is sometimes nil after Process.wait returns which
16
- # is not supposed to happen.
17
- ruby_version_gte '2.4'
13
+ require_no_multi_mongos
18
14
 
19
15
  let(:client) { authorized_client }
20
16
  let(:server) { client.cluster.next_primary }
@@ -7,7 +7,7 @@ describe 'getMore operation' do
7
7
  # https://jira.mongodb.org/browse/RUBY-1987
8
8
  min_server_fcv '3.2'
9
9
 
10
- let(:subscriber) { EventSubscriber.new }
10
+ let(:subscriber) { Mrss::EventSubscriber.new }
11
11
 
12
12
  let(:client) do
13
13
  authorized_client.tap do |client|
@@ -11,7 +11,7 @@ describe 'Heartbeat events' do
11
11
 
12
12
  clean_slate_for_all
13
13
 
14
- let(:subscriber) { EventSubscriber.new }
14
+ let(:subscriber) { Mrss::EventSubscriber.new }
15
15
 
16
16
  before do
17
17
  Mongo::Monitoring::Global.subscribe(Mongo::Monitoring::SERVER_HEARTBEAT, subscriber)
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+ # encoding: utf-8
3
+
4
+ require 'spec_helper'
5
+
6
+ describe 'Map-reduce operations' do
7
+ let(:client) { authorized_client }
8
+ let(:collection) { client['mr_integration'] }
9
+
10
+ let(:subscriber) { Mrss::EventSubscriber.new }
11
+
12
+ let(:find_options) { {} }
13
+
14
+ let(:operation) do
15
+ collection.find({}, find_options).map_reduce('function(){}', 'function(){}')
16
+ end
17
+
18
+ before do
19
+ collection.insert_one(test: 1)
20
+ client.subscribe(Mongo::Monitoring::COMMAND, subscriber)
21
+ end
22
+
23
+ let(:event) { subscriber.single_command_started_event('mapReduce') }
24
+
25
+ context 'read preference' do
26
+ require_topology :sharded
27
+
28
+ context 'specified on client' do
29
+ let(:client) { authorized_client.with(read: {mode: :secondary_preferred }) }
30
+
31
+ # RUBY-2706: read preference is not sent on pre-3.6 servers
32
+ min_server_fcv '3.6'
33
+
34
+ it 'is sent' do
35
+ operation.to_a
36
+
37
+ event.command['$readPreference'].should == {'mode' => 'secondaryPreferred'}
38
+ end
39
+ end
40
+
41
+ context 'specified on collection' do
42
+ let(:collection) { client['mr_integration', read: {mode: :secondary_preferred }] }
43
+
44
+ # RUBY-2706: read preference is not sent on pre-3.6 servers
45
+ min_server_fcv '3.6'
46
+
47
+ it 'is sent' do
48
+ operation.to_a
49
+
50
+ event.command['$readPreference'].should == {'mode' => 'secondaryPreferred'}
51
+ end
52
+ end
53
+
54
+ context 'specified on operation' do
55
+ let(:find_options) { {read: {mode: :secondary_preferred }} }
56
+
57
+ # RUBY-2706: read preference is not sent on pre-3.6 servers
58
+ min_server_fcv '3.6'
59
+
60
+ it 'is sent' do
61
+ operation.to_a
62
+
63
+ event.command['$readPreference'].should == {'mode' => 'secondaryPreferred'}
64
+ end
65
+ end
66
+ end
67
+
68
+ context 'session' do
69
+ min_server_fcv '3.6'
70
+
71
+ it 'is sent' do
72
+ operation.to_a
73
+
74
+ event.command['lsid'].should_not be nil
75
+ end
76
+ end
77
+ end
@@ -28,7 +28,7 @@ describe 'QueryCache' do
28
28
  SessionRegistry.instance.verify_sessions_ended!
29
29
  end
30
30
 
31
- let(:subscriber) { EventSubscriber.new }
31
+ let(:subscriber) { Mrss::EventSubscriber.new }
32
32
 
33
33
  let(:client) do
34
34
  authorized_client.tap do |client|
@@ -969,7 +969,7 @@ describe 'QueryCache' do
969
969
 
970
970
  context 'when find command fails and retries' do
971
971
  require_fail_command
972
- require_no_multi_shard
972
+ require_no_multi_mongos
973
973
  require_warning_clean
974
974
 
975
975
  before do
@@ -23,7 +23,7 @@ describe 'QueryCache with transactions' do
23
23
  # leak sessions independently of the query cache. This will be resolved by
24
24
  # RUBY-2391.
25
25
 
26
- let(:subscriber) { EventSubscriber.new }
26
+ let(:subscriber) { Mrss::EventSubscriber.new }
27
27
 
28
28
  let(:client) do
29
29
  authorized_client.tap do |client|
@@ -7,7 +7,7 @@ describe 'read concern' do
7
7
  min_server_version '3.2'
8
8
 
9
9
  let(:subscriber) do
10
- EventSubscriber.new
10
+ Mrss::EventSubscriber.new
11
11
  end
12
12
 
13
13
  let(:specified_read_concern) do
@@ -16,7 +16,7 @@ describe 'Read preference' do
16
16
  authorized_client.with(client_options)
17
17
  end
18
18
 
19
- let(:subscriber) { EventSubscriber.new }
19
+ let(:subscriber) { Mrss::EventSubscriber.new }
20
20
 
21
21
  before do
22
22
  client.subscribe(Mongo::Monitoring::COMMAND, subscriber)
@@ -16,20 +16,38 @@ describe 'Client after reconnect' do
16
16
  expect(doc['testk']).to eq('testv')
17
17
  end
18
18
 
19
- it 'recreates monitor thread' do
20
- thread = client.cluster.servers.first.monitor.instance_variable_get('@thread')
21
- expect(thread).to be_alive
19
+ context 'non-lb' do
20
+ require_topology :single, :replica_set, :sharded
22
21
 
23
- thread.kill
24
- # context switch to let the thread get killed
25
- sleep 0.1
26
- expect(thread).not_to be_alive
22
+ it 'recreates monitor thread' do
23
+ thread = client.cluster.servers.first.monitor.instance_variable_get('@thread')
24
+ expect(thread).to be_alive
27
25
 
28
- client.reconnect
26
+ thread.kill
27
+ # context switch to let the thread get killed
28
+ sleep 0.1
29
+ expect(thread).not_to be_alive
30
+
31
+ client.reconnect
32
+
33
+ new_thread = client.cluster.servers.first.monitor.instance_variable_get('@thread')
34
+ expect(new_thread).not_to eq(thread)
35
+ expect(new_thread).to be_alive
36
+ end
37
+ end
38
+
39
+ context 'lb' do
40
+ require_topology :load_balanced
29
41
 
30
- new_thread = client.cluster.servers.first.monitor.instance_variable_get('@thread')
31
- expect(new_thread).not_to eq(thread)
32
- expect(new_thread).to be_alive
42
+ it 'does not recreate monitor thread' do
43
+ thread = client.cluster.servers.first.monitor.instance_variable_get('@thread')
44
+ expect(thread).to be nil
45
+
46
+ client.reconnect
47
+
48
+ new_thread = client.cluster.servers.first.monitor.instance_variable_get('@thread')
49
+ expect(new_thread).to be nil
50
+ end
33
51
  end
34
52
 
35
53
  context 'with min_pool_size > 0' do
@@ -114,7 +132,7 @@ describe 'Client after reconnect' do
114
132
  context 'in sharded topology' do
115
133
  require_topology :sharded
116
134
  require_default_port_deployment
117
- require_multi_shard
135
+ require_multi_mongos
118
136
 
119
137
  let(:expected_topology_cls) { Mongo::Cluster::Topology::Sharded }
120
138
 
@@ -7,7 +7,7 @@ describe 'Failing retryable operations' do
7
7
  # Requirement for fail point
8
8
  min_server_fcv '4.0'
9
9
 
10
- let(:subscriber) { EventSubscriber.new }
10
+ let(:subscriber) { Mrss::EventSubscriber.new }
11
11
 
12
12
  let(:client_options) do
13
13
  {}