mongo 2.15.0 → 2.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (332) 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 +58 -24
  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 +72 -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/push_monitor.rb +10 -1
  102. data/lib/mongo/server.rb +73 -26
  103. data/lib/mongo/server_selector/base.rb +5 -1
  104. data/lib/mongo/session/session_pool.rb +11 -0
  105. data/lib/mongo/session.rb +21 -1
  106. data/lib/mongo/socket/ocsp_verifier.rb +6 -37
  107. data/lib/mongo/uri/options_mapper.rb +1 -0
  108. data/lib/mongo/uri/srv_protocol.rb +6 -8
  109. data/lib/mongo/uri.rb +18 -0
  110. data/lib/mongo/utils.rb +0 -7
  111. data/lib/mongo/version.rb +1 -1
  112. data/mongo.gemspec +1 -1
  113. data/spec/integration/auth_spec.rb +31 -1
  114. data/spec/integration/awaited_ismaster_spec.rb +1 -1
  115. data/spec/integration/bulk_write_spec.rb +1 -1
  116. data/spec/integration/change_stream_spec.rb +3 -3
  117. data/spec/integration/client_construction_spec.rb +54 -0
  118. data/spec/integration/client_side_encryption/auto_encryption_bulk_writes_spec.rb +1 -1
  119. data/spec/integration/client_side_encryption/auto_encryption_command_monitoring_spec.rb +1 -1
  120. data/spec/integration/client_side_encryption/bson_size_limit_spec.rb +1 -1
  121. data/spec/integration/client_side_encryption/data_key_spec.rb +1 -1
  122. data/spec/integration/client_spec.rb +2 -0
  123. data/spec/integration/command_monitoring_spec.rb +1 -1
  124. data/spec/integration/command_spec.rb +1 -1
  125. data/spec/integration/connection_spec.rb +52 -35
  126. data/spec/integration/crud_spec.rb +174 -1
  127. data/spec/integration/cursor_pinning_spec.rb +121 -0
  128. data/spec/integration/cursor_reaping_spec.rb +8 -4
  129. data/spec/integration/fork_reconnect_spec.rb +1 -5
  130. data/spec/integration/get_more_spec.rb +1 -1
  131. data/spec/integration/heartbeat_events_spec.rb +1 -1
  132. data/spec/integration/map_reduce_spec.rb +77 -0
  133. data/spec/integration/query_cache_spec.rb +47 -2
  134. data/spec/integration/query_cache_transactions_spec.rb +1 -1
  135. data/spec/integration/read_concern_spec.rb +1 -1
  136. data/spec/integration/read_preference_spec.rb +1 -1
  137. data/spec/integration/reconnect_spec.rb +30 -12
  138. data/spec/integration/retryable_errors_spec.rb +1 -1
  139. data/spec/integration/retryable_writes/retryable_writes_36_and_older_spec.rb +1 -1
  140. data/spec/integration/retryable_writes/retryable_writes_40_and_newer_spec.rb +1 -1
  141. data/spec/integration/sdam_error_handling_spec.rb +5 -3
  142. data/spec/integration/sdam_events_spec.rb +35 -19
  143. data/spec/integration/sdam_prose_spec.rb +1 -1
  144. data/spec/integration/server_monitor_spec.rb +1 -0
  145. data/spec/integration/server_selector_spec.rb +22 -5
  146. data/spec/integration/server_spec.rb +2 -0
  147. data/spec/integration/srv_monitoring_spec.rb +1 -1
  148. data/spec/integration/step_down_spec.rb +1 -1
  149. data/spec/integration/transaction_pinning_spec.rb +120 -0
  150. data/spec/integration/versioned_api_examples_spec.rb +45 -0
  151. data/spec/integration/x509_auth_spec.rb +1 -1
  152. data/spec/lite_spec_helper.rb +1 -2
  153. data/spec/mongo/address/unix_spec.rb +1 -0
  154. data/spec/mongo/auth/cr_spec.rb +2 -3
  155. data/spec/mongo/auth/ldap_spec.rb +2 -3
  156. data/spec/mongo/auth/scram_spec.rb +2 -3
  157. data/spec/mongo/auth/user/view_spec.rb +1 -1
  158. data/spec/mongo/auth/x509_spec.rb +2 -3
  159. data/spec/mongo/bulk_write_spec.rb +3 -3
  160. data/spec/mongo/client_construction_spec.rb +259 -28
  161. data/spec/mongo/client_spec.rb +6 -4
  162. data/spec/mongo/cluster/cursor_reaper_spec.rb +36 -21
  163. data/spec/mongo/cluster/periodic_executor_spec.rb +3 -1
  164. data/spec/mongo/cluster_spec.rb +44 -3
  165. data/spec/mongo/collection/view/aggregation_spec.rb +1 -1
  166. data/spec/mongo/collection/view/builder/find_command_spec.rb +4 -0
  167. data/spec/mongo/collection/view/builder/op_query_spec.rb +4 -0
  168. data/spec/mongo/collection/view/map_reduce_spec.rb +1 -1
  169. data/spec/mongo/collection_crud_spec.rb +7 -2
  170. data/spec/mongo/collection_ddl_spec.rb +1 -1
  171. data/spec/mongo/collection_spec.rb +1 -1
  172. data/spec/mongo/cursor/builder/get_more_command_spec.rb +4 -0
  173. data/spec/mongo/cursor/builder/op_get_more_spec.rb +4 -0
  174. data/spec/mongo/cursor_spec.rb +15 -5
  175. data/spec/mongo/database_spec.rb +15 -15
  176. data/spec/mongo/error/operation_failure_heavy_spec.rb +1 -1
  177. data/spec/mongo/grid/fs_bucket_spec.rb +18 -12
  178. data/spec/mongo/grid/stream/write_spec.rb +3 -9
  179. data/spec/mongo/grid/stream_spec.rb +1 -1
  180. data/spec/mongo/index/view_spec.rb +2 -2
  181. data/spec/mongo/operation/delete/op_msg_spec.rb +1 -1
  182. data/spec/mongo/{collection/view → operation/find}/builder/flags_spec.rb +2 -2
  183. data/spec/mongo/{collection/view → operation/find}/builder/modifiers_spec.rb +2 -2
  184. data/spec/mongo/operation/find/legacy_spec.rb +1 -0
  185. data/spec/mongo/operation/insert/bulk_spec.rb +1 -1
  186. data/spec/mongo/operation/insert/op_msg_spec.rb +1 -1
  187. data/spec/mongo/operation/kill_cursors_spec.rb +4 -1
  188. data/spec/mongo/operation/read_preference_legacy_spec.rb +4 -0
  189. data/spec/mongo/operation/read_preference_op_msg_spec.rb +2 -0
  190. data/spec/mongo/operation/update/bulk_spec.rb +1 -1
  191. data/spec/mongo/operation/update/op_msg_spec.rb +1 -1
  192. data/spec/mongo/query_cache_spec.rb +6 -2
  193. data/spec/mongo/server/connection_common_spec.rb +62 -11
  194. data/spec/mongo/server/connection_pool_spec.rb +73 -7
  195. data/spec/mongo/server/connection_spec.rb +138 -43
  196. data/spec/mongo/server/description_spec.rb +1 -1
  197. data/spec/mongo/server/monitor/connection_spec.rb +22 -0
  198. data/spec/mongo/server/monitor_spec.rb +4 -3
  199. data/spec/mongo/server/push_monitor_spec.rb +101 -0
  200. data/spec/mongo/session/session_pool_spec.rb +42 -10
  201. data/spec/mongo/session_transaction_spec.rb +15 -30
  202. data/spec/mongo/socket/unix_spec.rb +1 -0
  203. data/spec/mongo/uri_option_parsing_spec.rb +38 -5
  204. data/spec/runners/change_streams/test.rb +1 -1
  205. data/spec/runners/cmap.rb +1 -1
  206. data/spec/runners/connection_string.rb +7 -3
  207. data/spec/runners/crud/operation.rb +5 -3
  208. data/spec/runners/crud/requirement.rb +1 -0
  209. data/spec/runners/crud.rb +1 -1
  210. data/spec/runners/sdam.rb +2 -1
  211. data/spec/runners/transactions/test.rb +2 -2
  212. data/spec/runners/unified/assertions.rb +2 -3
  213. data/spec/runners/unified/event_subscriber.rb +2 -2
  214. data/spec/runners/unified/support_operations.rb +10 -2
  215. data/spec/runners/unified/test.rb +3 -0
  216. data/spec/runners/unified.rb +1 -1
  217. data/spec/shared/lib/mrss/cluster_config.rb +6 -1
  218. data/spec/shared/lib/mrss/constraints.rb +11 -5
  219. data/spec/shared/lib/mrss/event_subscriber.rb +200 -0
  220. data/spec/shared/lib/mrss/server_version_registry.rb +17 -12
  221. data/spec/shared/share/Dockerfile.erb +5 -4
  222. data/spec/shared/shlib/server.sh +70 -20
  223. data/spec/spec_tests/change_streams_spec.rb +1 -1
  224. data/spec/spec_tests/cmap_spec.rb +4 -1
  225. data/spec/spec_tests/command_monitoring_spec.rb +2 -2
  226. data/spec/spec_tests/data/command_monitoring/find.yml +9 -9
  227. data/spec/spec_tests/data/crud/read/aggregate-collation.yml +2 -1
  228. data/spec/spec_tests/data/crud/read/aggregate-out.yml +1 -0
  229. data/spec/spec_tests/data/crud/read/count-collation.yml +2 -1
  230. data/spec/spec_tests/data/crud/read/distinct-collation.yml +2 -1
  231. data/spec/spec_tests/data/crud/read/find-collation.yml +2 -1
  232. data/spec/spec_tests/data/crud/write/bulkWrite-collation.yml +2 -1
  233. data/spec/spec_tests/data/crud/write/deleteMany-collation.yml +2 -1
  234. data/spec/spec_tests/data/crud/write/deleteOne-collation.yml +2 -1
  235. data/spec/spec_tests/data/crud/write/findOneAndDelete-collation.yml +3 -2
  236. data/spec/spec_tests/data/crud/write/findOneAndReplace-collation.yml +2 -1
  237. data/spec/spec_tests/data/crud/write/findOneAndUpdate-collation.yml +3 -2
  238. data/spec/spec_tests/data/crud/write/replaceOne-collation.yml +3 -2
  239. data/spec/spec_tests/data/crud/write/updateMany-collation.yml +2 -1
  240. data/spec/spec_tests/data/crud/write/updateOne-collation.yml +2 -1
  241. data/spec/spec_tests/data/load_balancers/event-monitoring.yml +99 -0
  242. data/spec/spec_tests/data/load_balancers/lb-connection-establishment.yml +36 -0
  243. data/spec/spec_tests/data/load_balancers/non-lb-connection-establishment.yml +56 -0
  244. data/spec/spec_tests/data/load_balancers/server-selection.yml +50 -0
  245. data/spec/spec_tests/data/retryable_reads/changeStreams-client.watch-serverErrors.yml +1 -1
  246. data/spec/spec_tests/data/retryable_reads/changeStreams-client.watch.yml +1 -1
  247. data/spec/spec_tests/data/retryable_reads/changeStreams-db.coll.watch-serverErrors.yml +1 -1
  248. data/spec/spec_tests/data/retryable_reads/changeStreams-db.coll.watch.yml +1 -1
  249. data/spec/spec_tests/data/retryable_reads/changeStreams-db.watch-serverErrors.yml +1 -1
  250. data/spec/spec_tests/data/retryable_reads/changeStreams-db.watch.yml +1 -1
  251. data/spec/spec_tests/data/retryable_reads/mapReduce.yml +3 -1
  252. data/spec/spec_tests/data/sdam/load-balanced/discover_load_balancer.yml +25 -0
  253. data/spec/spec_tests/data/sdam_integration/find-network-error.yml +2 -0
  254. data/spec/spec_tests/data/sdam_integration/find-shutdown-error.yml +2 -0
  255. data/spec/spec_tests/data/sdam_integration/hello-command-error.yml +3 -1
  256. data/spec/spec_tests/data/sdam_integration/hello-network-error.yml +3 -1
  257. data/spec/spec_tests/data/sdam_integration/hello-timeout.yml +2 -0
  258. data/spec/spec_tests/data/sdam_integration/insert-network-error.yml +2 -0
  259. data/spec/spec_tests/data/sdam_integration/insert-shutdown-error.yml +2 -0
  260. data/spec/spec_tests/data/sdam_monitoring/load_balancer.yml +65 -0
  261. data/spec/spec_tests/data/seed_list_discovery/load-balanced/loadBalanced-directConnection.yml +13 -0
  262. data/spec/spec_tests/data/seed_list_discovery/load-balanced/loadBalanced-replicaSet-errors.yml +6 -0
  263. data/spec/spec_tests/data/seed_list_discovery/load-balanced/loadBalanced-true-multiple-hosts.yml +5 -0
  264. data/spec/spec_tests/data/seed_list_discovery/load-balanced/loadBalanced-true-txt.yml +10 -0
  265. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/direct-connection-false.yml +0 -0
  266. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/direct-connection-true.yml +0 -0
  267. data/spec/spec_tests/data/seed_list_discovery/replica-set/encoded-userinfo-and-db.yml +15 -0
  268. data/spec/spec_tests/data/seed_list_discovery/replica-set/loadBalanced-false-txt.yml +10 -0
  269. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/longer-parent-in-return.yml +0 -0
  270. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/misformatted-option.yml +0 -0
  271. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/no-results.yml +0 -0
  272. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/not-enough-parts.yml +0 -0
  273. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/one-result-default-port.yml +0 -0
  274. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/one-txt-record-multiple-strings.yml +0 -0
  275. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/one-txt-record.yml +0 -0
  276. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/parent-part-mismatch1.yml +0 -0
  277. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/parent-part-mismatch2.yml +0 -0
  278. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/parent-part-mismatch3.yml +0 -0
  279. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/parent-part-mismatch4.yml +0 -0
  280. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/parent-part-mismatch5.yml +0 -0
  281. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/returned-parent-too-short.yml +0 -0
  282. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/returned-parent-wrong.yml +0 -0
  283. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/two-results-default-port.yml +0 -0
  284. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/two-results-nonstandard-port.yml +0 -0
  285. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/two-txt-records.yml +0 -0
  286. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/txt-record-not-allowed-option.yml +0 -0
  287. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/txt-record-with-overridden-ssl-option.yml +0 -0
  288. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/txt-record-with-overridden-uri-option.yml +0 -0
  289. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/txt-record-with-unallowed-option.yml +0 -0
  290. data/spec/spec_tests/data/seed_list_discovery/replica-set/uri-with-admin-database.yml +13 -0
  291. data/spec/spec_tests/data/seed_list_discovery/replica-set/uri-with-auth.yml +12 -0
  292. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/uri-with-port.yml +0 -0
  293. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/uri-with-two-hosts.yml +0 -0
  294. data/spec/spec_tests/data/transactions/retryable-abort-errorLabels.yml +2 -0
  295. data/spec/spec_tests/data/transactions/retryable-abort.yml +2 -0
  296. data/spec/spec_tests/data/transactions/retryable-commit-errorLabels.yml +2 -0
  297. data/spec/spec_tests/data/transactions/retryable-commit.yml +2 -0
  298. data/spec/spec_tests/data/transactions/retryable-writes.yml +2 -0
  299. data/spec/spec_tests/data/uri_options/connection-options.yml +60 -0
  300. data/spec/spec_tests/load_balancers_spec.rb +15 -0
  301. data/spec/spec_tests/retryable_reads_spec.rb +2 -2
  302. data/spec/spec_tests/retryable_writes_spec.rb +1 -1
  303. data/spec/spec_tests/sdam_integration_spec.rb +1 -1
  304. data/spec/spec_tests/sdam_monitoring_spec.rb +10 -5
  305. data/spec/spec_tests/sdam_spec.rb +1 -1
  306. data/spec/spec_tests/seed_list_discovery_spec.rb +118 -0
  307. data/spec/spec_tests/uri_options_spec.rb +4 -4
  308. data/spec/stress/fork_reconnect_stress_spec.rb +1 -5
  309. data/spec/stress/push_monitor_close_spec.rb +44 -0
  310. data/spec/support/certificates/atlas-ocsp-ca.crt +82 -90
  311. data/spec/support/certificates/atlas-ocsp.crt +127 -122
  312. data/spec/support/common_shortcuts.rb +2 -3
  313. data/spec/support/matchers.rb +13 -0
  314. data/spec/support/shared/auth_context.rb +16 -0
  315. data/spec/support/shared/session.rb +2 -2
  316. data/spec/support/spec_config.rb +10 -11
  317. data/spec/support/using_hash.rb +31 -0
  318. data/spec/support/utils.rb +1 -1
  319. data.tar.gz.sig +0 -0
  320. metadata +1077 -1029
  321. metadata.gz.sig +0 -0
  322. data/lib/mongo/collection/view/builder/find_command.rb +0 -173
  323. data/lib/mongo/collection/view/builder/op_query.rb +0 -94
  324. data/lib/mongo/cursor/builder/get_more_command.rb +0 -80
  325. data/lib/mongo/cursor/builder/kill_cursors_command.rb +0 -111
  326. data/lib/mongo/cursor/builder/op_get_more.rb +0 -64
  327. data/lib/mongo/cursor/builder/op_kill_cursors.rb +0 -106
  328. data/lib/mongo/server/context.rb +0 -72
  329. data/spec/mongo/cursor/builder/op_kill_cursors_spec.rb +0 -66
  330. data/spec/runners/unified/using_hash.rb +0 -34
  331. data/spec/spec_tests/dns_seedlist_discovery_spec.rb +0 -79
  332. data/spec/support/event_subscriber.rb +0 -221
@@ -16,7 +16,6 @@ RETRYABLE_READS_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/retryable_read
16
16
  COMMAND_MONITORING_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/command_monitoring/**/*.yml").sort
17
17
  CONNECTION_STRING_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/connection_string/*.yml").sort
18
18
  URI_OPTIONS_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/uri_options/*.yml").sort
19
- DNS_SEEDLIST_DISCOVERY_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/dns_seedlist_discovery/*.yml").sort
20
19
  GRIDFS_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/gridfs/*.yml").sort
21
20
  TRANSACTIONS_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/transactions/*.yml").sort
22
21
  TRANSACTIONS_API_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/transactions_api/*.yml").sort
@@ -78,7 +77,7 @@ end
78
77
 
79
78
  require 'mrss/lite_constraints'
80
79
  require 'support/matchers'
81
- require 'support/event_subscriber'
80
+ require 'mrss/event_subscriber'
82
81
  require 'support/common_shortcuts'
83
82
  require 'support/client_registry'
84
83
  require 'support/client_registry_macros'
@@ -28,6 +28,7 @@ describe Mongo::Address::Unix do
28
28
  end
29
29
 
30
30
  describe '#socket' do
31
+ require_unix_socket
31
32
 
32
33
  let(:address) do
33
34
  "/tmp/mongodb-#{SpecConfig.instance.any_port}.sock"
@@ -2,6 +2,7 @@
2
2
  # encoding: utf-8
3
3
 
4
4
  require 'spec_helper'
5
+ require 'support/shared/auth_context'
5
6
 
6
7
  describe Mongo::Auth::CR do
7
8
 
@@ -9,9 +10,7 @@ describe Mongo::Auth::CR do
9
10
  authorized_client.cluster.next_primary
10
11
  end
11
12
 
12
- let(:connection) do
13
- Mongo::Server::Connection.new(server, SpecConfig.instance.test_options)
14
- end
13
+ include_context 'auth unit tests'
15
14
 
16
15
  describe '#login' do
17
16
 
@@ -2,6 +2,7 @@
2
2
  # encoding: utf-8
3
3
 
4
4
  require 'spec_helper'
5
+ require 'support/shared/auth_context'
5
6
 
6
7
  describe Mongo::Auth::LDAP do
7
8
 
@@ -9,9 +10,7 @@ describe Mongo::Auth::LDAP do
9
10
  authorized_client.cluster.next_primary
10
11
  end
11
12
 
12
- let(:connection) do
13
- Mongo::Server::Connection.new(server, SpecConfig.instance.test_options)
14
- end
13
+ include_context 'auth unit tests'
15
14
 
16
15
  let(:user) do
17
16
  Mongo::Auth::User.new(
@@ -2,6 +2,7 @@
2
2
  # encoding: utf-8
3
3
 
4
4
  require 'spec_helper'
5
+ require 'support/shared/auth_context'
5
6
 
6
7
  describe Mongo::Auth::Scram do
7
8
  require_no_external_user
@@ -10,9 +11,7 @@ describe Mongo::Auth::Scram do
10
11
  authorized_client.cluster.next_primary
11
12
  end
12
13
 
13
- let(:connection) do
14
- Mongo::Server::Connection.new(server, SpecConfig.instance.monitoring_options)
15
- end
14
+ include_context 'auth unit tests'
16
15
 
17
16
  let(:cache_mod) { Mongo::Auth::CredentialCache }
18
17
 
@@ -23,7 +23,7 @@ describe Mongo::Auth::User::View do
23
23
  shared_context 'testing write concern' do
24
24
 
25
25
  let(:subscriber) do
26
- EventSubscriber.new
26
+ Mrss::EventSubscriber.new
27
27
  end
28
28
 
29
29
  let(:client) do
@@ -2,6 +2,7 @@
2
2
  # encoding: utf-8
3
3
 
4
4
  require 'spec_helper'
5
+ require 'support/shared/auth_context'
5
6
 
6
7
  describe Mongo::Auth::X509 do
7
8
 
@@ -9,9 +10,7 @@ describe Mongo::Auth::X509 do
9
10
  authorized_client.cluster.next_primary
10
11
  end
11
12
 
12
- let(:connection) do
13
- Mongo::Server::Connection.new(server, SpecConfig.instance.test_options)
14
- end
13
+ include_context 'auth unit tests'
15
14
 
16
15
  let(:user) do
17
16
  Mongo::Auth::User.new(database: '$external')
@@ -1424,7 +1424,7 @@ describe Mongo::BulkWrite do
1424
1424
 
1425
1425
  # In a multi-sharded cluster, the write seems to go to a
1426
1426
  # different shard from the read
1427
- require_no_multi_shard
1427
+ require_no_multi_mongos
1428
1428
 
1429
1429
  let(:extra_options) do
1430
1430
  { write_concern: { w: 0 } }
@@ -2103,10 +2103,10 @@ describe Mongo::BulkWrite do
2103
2103
 
2104
2104
  # In a multi-shard cluster, retries may go to a different server
2105
2105
  # than original command which these tests are not prepared to handle
2106
- require_no_multi_shard
2106
+ require_no_multi_mongos
2107
2107
 
2108
2108
 
2109
- let(:subscriber) { EventSubscriber.new }
2109
+ let(:subscriber) { Mrss::EventSubscriber.new }
2110
2110
 
2111
2111
  let(:client) do
2112
2112
  authorized_client_with_retry_writes.tap do |client|
@@ -6,7 +6,7 @@ require 'spec_helper'
6
6
  describe Mongo::Client do
7
7
  clean_slate
8
8
 
9
- let(:subscriber) { EventSubscriber.new }
9
+ let(:subscriber) { Mrss::EventSubscriber.new }
10
10
 
11
11
  describe '.new' do
12
12
  context 'with scan: false' do
@@ -24,26 +24,8 @@ describe Mongo::Client do
24
24
  end
25
25
 
26
26
  context 'with default scan: true' do
27
- # TODO this test requires there being no outstanding background
28
- # monitoring threads running, as otherwise the scan! expectation
29
- # can be executed on a thread that belongs to one of the global
30
- # clients for instance
31
- it 'performs one round of sdam' do
32
- # Does not work due to
33
- # https://github.com/rspec/rspec-mocks/issues/1242.
34
- #expect_any_instance_of(Mongo::Server::Monitor).to receive(:scan!).
35
- # exactly(SpecConfig.instance.addresses.length).times.and_call_original
36
- c = new_local_client(
37
- SpecConfig.instance.addresses, SpecConfig.instance.test_options)
38
- expect(c.cluster.servers).not_to be_empty
39
- end
40
-
41
- # This checks the case of all initial seeds being removed from
42
- # cluster during SDAM
43
- context 'me mismatch on the only initial seed' do
44
- let(:address) do
45
- ClusterConfig.instance.alternate_address.to_s
46
- end
27
+
28
+ shared_examples 'does not wait for server selection timeout' do
47
29
 
48
30
  let(:logger) do
49
31
  Logger.new(STDOUT, level: Logger::DEBUG)
@@ -94,6 +76,7 @@ describe Mongo::Client do
94
76
  Mongo::Cluster::Topology::ReplicaSetWithPrimary,
95
77
  Mongo::Cluster::Topology::Single,
96
78
  Mongo::Cluster::Topology::Sharded,
79
+ Mongo::Cluster::Topology::LoadBalanced,
97
80
  ]).to include(actual_class)
98
81
  expect(time_taken).to be < 5
99
82
 
@@ -101,6 +84,44 @@ describe Mongo::Client do
101
84
  client.database.command(ping: 1)
102
85
  end
103
86
  end
87
+
88
+ context 'when cluster is monitored' do
89
+ require_topology :single, :replica_set, :sharded
90
+
91
+ # TODO this test requires there being no outstanding background
92
+ # monitoring threads running, as otherwise the scan! expectation
93
+ # can be executed on a thread that belongs to one of the global
94
+ # clients for instance
95
+ it 'performs one round of sdam' do
96
+ # Does not work due to
97
+ # https://github.com/rspec/rspec-mocks/issues/1242.
98
+ #expect_any_instance_of(Mongo::Server::Monitor).to receive(:scan!).
99
+ # exactly(SpecConfig.instance.addresses.length).times.and_call_original
100
+ c = new_local_client(
101
+ SpecConfig.instance.addresses, SpecConfig.instance.test_options)
102
+ expect(c.cluster.servers).not_to be_empty
103
+ end
104
+
105
+ # This checks the case of all initial seeds being removed from
106
+ # cluster during SDAM
107
+ context 'me mismatch on the only initial seed' do
108
+ let(:address) do
109
+ ClusterConfig.instance.alternate_address.to_s
110
+ end
111
+
112
+ include_examples 'does not wait for server selection timeout'
113
+ end
114
+ end
115
+
116
+ context 'when cluster is not monitored' do
117
+ require_topology :load_balanced
118
+
119
+ let(:address) do
120
+ ClusterConfig.instance.alternate_address.to_s
121
+ end
122
+
123
+ include_examples 'does not wait for server selection timeout'
124
+ end
104
125
  end
105
126
 
106
127
  context 'with monitoring_io: false' do
@@ -388,10 +409,24 @@ describe Mongo::Client do
388
409
  end.should_not raise_error
389
410
  end
390
411
 
391
- it 'fails server selection due to very small timeout' do
392
- lambda do
393
- client.database.command(ping: 1)
394
- end.should raise_error(Mongo::Error::NoServerAvailable)
412
+ context 'non-lb' do
413
+ require_topology :single, :replica_set, :sharded
414
+
415
+ it 'fails server selection due to very small timeout' do
416
+ lambda do
417
+ client.database.command(ping: 1)
418
+ end.should raise_error(Mongo::Error::NoServerAvailable)
419
+ end
420
+ end
421
+
422
+ context 'lb' do
423
+ require_topology :load_balanced
424
+
425
+ it 'fails the operation after successful server selection' do
426
+ lambda do
427
+ client.database.command(ping: 1)
428
+ end.should raise_error(Mongo::Error::SocketTimeoutError, /socket took over.*to connect/)
429
+ end
395
430
  end
396
431
  end
397
432
 
@@ -412,7 +447,7 @@ describe Mongo::Client do
412
447
  end.should_not raise_error
413
448
  end
414
449
 
415
- it 'fails operations due to very small timeout' do
450
+ it 'fails operations due to very small timeout', retry: 3 do
416
451
  lambda do
417
452
  client.database.command(ping: 1)
418
453
  end.should raise_error(Mongo::Error::SocketTimeoutError)
@@ -1292,6 +1327,192 @@ describe Mongo::Client do
1292
1327
  client.options[:connect].should be :sharded
1293
1328
  end
1294
1329
  end
1330
+
1331
+ context 'load_balanced: true and multiple seeds' do
1332
+ let(:client) do
1333
+ new_local_client_nmio(['127.0.0.1:27017', '127.0.0.2:27017'],
1334
+ load_balanced: true)
1335
+ end
1336
+
1337
+ it 'is rejected' do
1338
+ lambda do
1339
+ client
1340
+ end.should raise_error(ArgumentError, /load_balanced=true cannot be used with multiple seeds/)
1341
+ end
1342
+ end
1343
+
1344
+ context 'load_balanced: false and multiple seeds' do
1345
+ let(:client) do
1346
+ new_local_client_nmio(['127.0.0.1:27017', '127.0.0.2:27017'],
1347
+ load_balanced: false)
1348
+ end
1349
+
1350
+ it 'is accepted' do
1351
+ lambda do
1352
+ client
1353
+ end.should_not raise_error
1354
+ client.options[:load_balanced].should be false
1355
+ end
1356
+ end
1357
+
1358
+ context 'load_balanced: true and direct_connection: true' do
1359
+ let(:client) do
1360
+ new_local_client_nmio(['127.0.0.1:27017'],
1361
+ load_balanced: true, direct_connection: true)
1362
+ end
1363
+
1364
+ it 'is rejected' do
1365
+ lambda do
1366
+ client
1367
+ end.should raise_error(ArgumentError, /direct_connection=true cannot be used with load_balanced=true/)
1368
+ end
1369
+ end
1370
+
1371
+ context 'load_balanced: true and direct_connection: false' do
1372
+ let(:client) do
1373
+ new_local_client_nmio(['127.0.0.1:27017'],
1374
+ load_balanced: true, direct_connection: false)
1375
+ end
1376
+
1377
+ it 'is accepted' do
1378
+ lambda do
1379
+ client
1380
+ end.should_not raise_error
1381
+ client.options[:load_balanced].should be true
1382
+ client.options[:direct_connection].should be false
1383
+ end
1384
+ end
1385
+
1386
+ context 'load_balanced: false and direct_connection: true' do
1387
+ let(:client) do
1388
+ new_local_client_nmio(['127.0.0.1:27017'],
1389
+ load_balanced: false, direct_connection: true)
1390
+ end
1391
+
1392
+ it 'is accepted' do
1393
+ lambda do
1394
+ client
1395
+ end.should_not raise_error
1396
+ client.options[:load_balanced].should be false
1397
+ client.options[:direct_connection].should be true
1398
+ end
1399
+ end
1400
+
1401
+ [:direct, 'direct', :sharded, 'sharded'].each do |v|
1402
+ context "load_balanced: true and connect: #{v.inspect}" do
1403
+ let(:client) do
1404
+ new_local_client_nmio(['127.0.0.1:27017'],
1405
+ load_balanced: true, connect: v)
1406
+ end
1407
+
1408
+ it 'is rejected' do
1409
+ lambda do
1410
+ client
1411
+ end.should raise_error(ArgumentError, /connect=#{v} cannot be used with load_balanced=true/)
1412
+ end
1413
+ end
1414
+ end
1415
+
1416
+ [nil].each do |v|
1417
+ context "load_balanced: true and connect: #{v.inspect}" do
1418
+ let(:client) do
1419
+ new_local_client_nmio(['127.0.0.1:27017'],
1420
+ load_balanced: true, connect: v)
1421
+ end
1422
+
1423
+ it 'is accepted' do
1424
+ lambda do
1425
+ client
1426
+ end.should_not raise_error
1427
+ client.options[:load_balanced].should be true
1428
+ client.options[:connect].should eq v
1429
+ end
1430
+ end
1431
+ end
1432
+
1433
+ [:load_balanced, 'load_balanced'].each do |v|
1434
+ context "load_balanced: true and connect: #{v.inspect}" do
1435
+ let(:client) do
1436
+ new_local_client_nmio(['127.0.0.1:27017'],
1437
+ load_balanced: true, connect: v)
1438
+ end
1439
+
1440
+ it 'is accepted' do
1441
+ lambda do
1442
+ client
1443
+ end.should_not raise_error
1444
+ client.options[:load_balanced].should be true
1445
+ client.options[:connect].should eq v
1446
+ end
1447
+ end
1448
+
1449
+ context "replica_set and connect: #{v.inspect}" do
1450
+ let(:client) do
1451
+ new_local_client_nmio(['127.0.0.1:27017'],
1452
+ replica_set: 'foo', connect: v)
1453
+ end
1454
+
1455
+ it 'is rejected' do
1456
+ lambda do
1457
+ client
1458
+ end.should raise_error(ArgumentError, /connect=load_balanced cannot be used with replica_set option/)
1459
+ end
1460
+ end
1461
+
1462
+ context "direct_connection=true and connect: #{v.inspect}" do
1463
+ let(:client) do
1464
+ new_local_client_nmio(['127.0.0.1:27017'],
1465
+ direct_connection: true, connect: v)
1466
+ end
1467
+
1468
+ it 'is rejected' do
1469
+ lambda do
1470
+ client
1471
+ end.should raise_error(ArgumentError, /Conflicting client options: direct_connection=true and connect=load_balanced/)
1472
+ end
1473
+ end
1474
+
1475
+ context "multiple seed addresses and connect: #{v.inspect}" do
1476
+ let(:client) do
1477
+ new_local_client_nmio(['127.0.0.1:27017', '127.0.0.1:1234'],
1478
+ connect: v)
1479
+ end
1480
+
1481
+ it 'is rejected' do
1482
+ lambda do
1483
+ client
1484
+ end.should raise_error(ArgumentError, /connect=load_balanced cannot be used with multiple seeds/)
1485
+ end
1486
+ end
1487
+ end
1488
+
1489
+ [:replica_set, 'replica_set'].each do |v|
1490
+ context "load_balanced: true and connect: #{v.inspect}" do
1491
+ let(:client) do
1492
+ new_local_client_nmio(['127.0.0.1:27017'],
1493
+ load_balanced: true, connect: v, replica_set: 'x')
1494
+ end
1495
+
1496
+ it 'is rejected' do
1497
+ lambda do
1498
+ client
1499
+ end.should raise_error(ArgumentError, /connect=replica_set cannot be used with load_balanced=true/)
1500
+ end
1501
+ end
1502
+
1503
+ context "load_balanced: true and #{v.inspect} option" do
1504
+ let(:client) do
1505
+ new_local_client_nmio(['127.0.0.1:27017'],
1506
+ load_balanced: true, v => 'rs')
1507
+ end
1508
+
1509
+ it 'is rejected' do
1510
+ lambda do
1511
+ client
1512
+ end.should raise_error(ArgumentError, /load_balanced=true cannot be used with replica_set option/)
1513
+ end
1514
+ end
1515
+ end
1295
1516
  end
1296
1517
 
1297
1518
  context ':bg_error_backtrace option' do
@@ -2306,7 +2527,12 @@ describe Mongo::Client do
2306
2527
  before do
2307
2528
  client.cluster.next_primary
2308
2529
  events = subscriber.select_started_events(Mongo::Monitoring::Event::ServerHeartbeatStarted)
2309
- events.length.should > 0
2530
+ if ClusterConfig.instance.topology == :load_balanced
2531
+ # No server monitoring in LB topology
2532
+ events.length.should == 0
2533
+ else
2534
+ events.length.should > 0
2535
+ end
2310
2536
  end
2311
2537
 
2312
2538
  it 'does not copy sdam_proc option to new client' do
@@ -2318,7 +2544,12 @@ describe Mongo::Client do
2318
2544
  # Give those some time to be processed.
2319
2545
  sleep 2
2320
2546
 
2321
- expect(subscriber.started_events.length).to be > 0
2547
+ if ClusterConfig.instance.topology == :load_balanced
2548
+ # No server monitoring in LB topology
2549
+ expect(subscriber.started_events.length).to eq 0
2550
+ else
2551
+ expect(subscriber.started_events.length).to be > 0
2552
+ end
2322
2553
  subscriber.started_events.clear
2323
2554
 
2324
2555
  # If this test takes longer than heartbeat interval,
@@ -635,7 +635,7 @@ describe Mongo::Client do
635
635
  root_authorized_client.options.merge(heartbeat_frequency: 100, monitoring: true)
636
636
  end
637
637
 
638
- let(:subscriber) { EventSubscriber.new }
638
+ let(:subscriber) { Mrss::EventSubscriber.new }
639
639
 
640
640
  let(:client) do
641
641
  ClientRegistry.instance.new_local_client(
@@ -939,13 +939,15 @@ describe Mongo::Client do
939
939
  end
940
940
 
941
941
  context 'monitoring present' do
942
+ require_topology :single, :replica_set, :sharded
943
+
942
944
  let(:client) do
943
945
  authorized_client
944
946
  end
945
947
 
946
948
  it 'does not indicate lack of monitoring' do
947
- client.summary.should =~ /servers=.*(STANDALONE|PRIMARY|MONGOS)/
948
- client.summary.should_not =~ /servers=.*(STANDALONE|PRIMARY|MONGOS).*NO-MONITORING/
949
+ client.summary.should =~ /servers=.*(?:STANDALONE|PRIMARY|MONGOS)/
950
+ client.summary.should_not =~ /servers=.*(?:STANDALONE|PRIMARY|MONGOS).*NO-MONITORING/
949
951
  end
950
952
  end
951
953
 
@@ -957,7 +959,7 @@ describe Mongo::Client do
957
959
  end
958
960
 
959
961
  it 'does not indicate lack of monitoring' do
960
- client.summary.should =~ /servers=.*(STANDALONE|PRIMARY|MONGOS).*NO-MONITORING/
962
+ client.summary.should =~ /servers=.*(STANDALONE|PRIMARY|MONGOS|\bLB\b).*NO-MONITORING/
961
963
  end
962
964
  end
963
965
  end
@@ -5,16 +5,18 @@ require 'spec_helper'
5
5
 
6
6
  describe Mongo::Cluster::CursorReaper do
7
7
 
8
+ let(:cluster) { double('cluster') }
9
+
8
10
  before do
9
11
  authorized_collection.drop
10
12
  end
11
13
 
12
14
  let(:reaper) do
13
- described_class.new
15
+ described_class.new(cluster)
14
16
  end
15
17
 
16
- let(:active_cursors) do
17
- reaper.instance_variable_get(:@active_cursors)
18
+ let(:active_cursor_ids) do
19
+ reaper.instance_variable_get(:@active_cursor_ids)
18
20
  end
19
21
 
20
22
  describe '#intialize' do
@@ -24,16 +26,29 @@ describe Mongo::Cluster::CursorReaper do
24
26
  end
25
27
 
26
28
  it 'initializes a set for the list of active cursors' do
27
- expect(reaper.instance_variable_get(:@active_cursors)).to be_a(Set)
29
+ expect(reaper.instance_variable_get(:@active_cursor_ids)).to be_a(Set)
28
30
  end
29
31
  end
30
32
 
31
33
  describe '#schedule_kill_cursor' do
32
34
 
33
- let(:server) { double('server') }
35
+ let(:address) { Mongo::Address.new('localhost') }
36
+ let(:server) do
37
+ double('server').tap do |server|
38
+ allow(server).to receive(:address).and_return(address)
39
+ end
40
+ end
34
41
  let(:cursor_id) { 1 }
35
- let(:op_spec_1) { double('op_spec_1') }
36
- let(:op_spec_2) { double('op_spec_2') }
42
+ let(:cursor_kill_spec_1) do
43
+ Mongo::Cursor::KillSpec.new(
44
+ cursor_id: cursor_id, coll_name: 'c', db_name: 'd', service_id: nil,
45
+ )
46
+ end
47
+ let(:cursor_kill_spec_2) do
48
+ Mongo::Cursor::KillSpec.new(
49
+ cursor_id: cursor_id, coll_name: 'c', db_name: 'q', service_id: nil,
50
+ )
51
+ end
37
52
  let(:to_kill) { reaper.instance_variable_get(:@to_kill)}
38
53
 
39
54
  context 'when the cursor is on the list of active cursors' do
@@ -45,36 +60,36 @@ describe Mongo::Cluster::CursorReaper do
45
60
  context 'when there is not a list already for the server' do
46
61
 
47
62
  before do
48
- reaper.schedule_kill_cursor(cursor_id, op_spec_1, server)
63
+ reaper.schedule_kill_cursor(cursor_kill_spec_1, server)
49
64
  end
50
65
 
51
66
  it 'initializes the list of op specs to a set' do
52
- expect(to_kill.keys).to eq([ server ])
53
- expect(to_kill[server]).to eq(Set.new([op_spec_1]))
67
+ expect(to_kill.keys).to eq([ address.seed ])
68
+ expect(to_kill[address.seed]).to eq(Set.new([cursor_kill_spec_1]))
54
69
  end
55
70
  end
56
71
 
57
72
  context 'when there is a list of ops already for the server' do
58
73
 
59
74
  before do
60
- reaper.schedule_kill_cursor(cursor_id, op_spec_1, server)
61
- reaper.schedule_kill_cursor(cursor_id, op_spec_2, server)
75
+ reaper.schedule_kill_cursor(cursor_kill_spec_1, server)
76
+ reaper.schedule_kill_cursor(cursor_kill_spec_2, server)
62
77
  end
63
78
 
64
79
  it 'adds the op to the server list' do
65
- expect(to_kill.keys).to eq([ server ])
66
- expect(to_kill[server]).to contain_exactly(op_spec_1, op_spec_2)
80
+ expect(to_kill.keys).to eq([ address.seed ])
81
+ expect(to_kill[address.seed]).to contain_exactly(cursor_kill_spec_1, cursor_kill_spec_2)
67
82
  end
68
83
 
69
84
  context 'when the same op is added more than once' do
70
85
 
71
86
  before do
72
- reaper.schedule_kill_cursor(cursor_id, op_spec_2, server)
87
+ reaper.schedule_kill_cursor(cursor_kill_spec_2, server)
73
88
  end
74
89
 
75
90
  it 'does not allow duplicates ops for a server' do
76
- expect(to_kill.keys).to eq([ server ])
77
- expect(to_kill[server]).to contain_exactly(op_spec_1, op_spec_2)
91
+ expect(to_kill.keys).to eq([ address.seed ])
92
+ expect(to_kill[address.seed]).to contain_exactly(cursor_kill_spec_1, cursor_kill_spec_2)
78
93
  end
79
94
  end
80
95
  end
@@ -83,7 +98,7 @@ describe Mongo::Cluster::CursorReaper do
83
98
  context 'when the cursor is not on the list of active cursors' do
84
99
 
85
100
  before do
86
- reaper.schedule_kill_cursor(cursor_id, op_spec_1, server)
101
+ reaper.schedule_kill_cursor(cursor_kill_spec_1, server)
87
102
  end
88
103
 
89
104
  it 'does not add the kill cursors op spec to the list' do
@@ -131,7 +146,7 @@ describe Mongo::Cluster::CursorReaper do
131
146
  end
132
147
 
133
148
  it 'registers the cursor id as active' do
134
- expect(active_cursors).to eq(Set.new([2]))
149
+ expect(active_cursor_ids).to eq(Set.new([2]))
135
150
  end
136
151
  end
137
152
  end
@@ -146,7 +161,7 @@ describe Mongo::Cluster::CursorReaper do
146
161
  end
147
162
 
148
163
  it 'removes the cursor id' do
149
- expect(active_cursors.size).to eq(0)
164
+ expect(active_cursor_ids.size).to eq(0)
150
165
  end
151
166
  end
152
167
  end
@@ -174,7 +189,7 @@ describe Mongo::Cluster::CursorReaper do
174
189
  around do |example|
175
190
  authorized_collection.insert_many(docs)
176
191
  periodic_executor.stop!
177
- cluster.schedule_kill_cursor(cursor.id, cursor.send(:kill_cursors_op_spec),
192
+ cluster.schedule_kill_cursor(cursor.kill_spec,
178
193
  cursor.instance_variable_get(:@server))
179
194
  periodic_executor.flush
180
195
  example.run
@@ -5,8 +5,10 @@ require 'spec_helper'
5
5
 
6
6
  describe Mongo::Cluster::PeriodicExecutor do
7
7
 
8
+ let(:cluster) { double('cluster') }
9
+
8
10
  let(:executor) do
9
- described_class.new
11
+ described_class.new(cluster)
10
12
  end
11
13
 
12
14
  describe '#log_warn' do