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
@@ -317,6 +317,11 @@ describe Mongo::Server::ConnectionPool do
317
317
  end
318
318
 
319
319
  context 'connection of the same generation as pool' do
320
+ # These tests are also applicable to load balancers, but
321
+ # require different setup and assertions because load balancers
322
+ # do not have a single global generation.
323
+ require_topology :single, :replica_set, :sharded
324
+
320
325
  before do
321
326
  expect(pool.generation).to eq(connection.generation)
322
327
  end
@@ -349,6 +354,11 @@ describe Mongo::Server::ConnectionPool do
349
354
  end
350
355
 
351
356
  context 'connection of earlier generation than pool' do
357
+ # These tests are also applicable to load balancers, but
358
+ # require different setup and assertions because load balancers
359
+ # do not have a single global generation.
360
+ require_topology :single, :replica_set, :sharded
361
+
352
362
  let(:connection) do
353
363
  pool.check_out.tap do |connection|
354
364
  expect(connection).to receive(:generation).at_least(:once).and_return(0)
@@ -364,6 +374,11 @@ describe Mongo::Server::ConnectionPool do
364
374
  end
365
375
 
366
376
  context 'connection of later generation than pool' do
377
+ # These tests are also applicable to load balancers, but
378
+ # require different setup and assertions because load balancers
379
+ # do not have a single global generation.
380
+ require_topology :single, :replica_set, :sharded
381
+
367
382
  let(:connection) do
368
383
  pool.check_out.tap do |connection|
369
384
  expect(connection).to receive(:generation).at_least(:once).and_return(7)
@@ -449,6 +464,11 @@ describe Mongo::Server::ConnectionPool do
449
464
  end
450
465
 
451
466
  context 'when there is an available connection which is stale' do
467
+ # These tests are also applicable to load balancers, but
468
+ # require different setup and assertions because load balancers
469
+ # do not have a single global generation.
470
+ require_topology :single, :replica_set, :sharded
471
+
452
472
  let(:options) do
453
473
  { max_pool_size: 2, max_idle_time: 0.1 }
454
474
  end
@@ -489,13 +509,54 @@ describe Mongo::Server::ConnectionPool do
489
509
 
490
510
  context 'when the max size is reached' do
491
511
 
492
- it 'raises a timeout error' do
493
- expect(Mongo::Server::Connection).to receive(:new).once.and_call_original
494
- expect {
495
- pool.check_out
512
+ context 'without service_id' do
513
+ it 'raises a timeout error' do
514
+ expect(Mongo::Server::Connection).to receive(:new).once.and_call_original
496
515
  pool.check_out
497
- }.to raise_error(::Timeout::Error)
498
- expect(pool.size).to eq(1)
516
+ expect {
517
+ pool.check_out
518
+ }.to raise_error(::Timeout::Error)
519
+ expect(pool.size).to eq(1)
520
+ end
521
+ end
522
+
523
+ context 'with service_id' do
524
+ require_topology :load_balanced
525
+
526
+ let(:service_id) do
527
+ pool.with_connection do |connection|
528
+ connection.service_id.should_not be nil
529
+ connection.service_id
530
+ end
531
+ end
532
+
533
+ it 'raises a timeout error' do
534
+ expect(Mongo::Server::Connection).to receive(:new).once.and_call_original
535
+ service_id
536
+
537
+ pool.check_out(service_id: service_id)
538
+
539
+ expect {
540
+ pool.check_out(service_id: service_id)
541
+ }.to raise_error(Mongo::Error::ConnectionCheckOutTimeout)
542
+
543
+ expect(pool.size).to eq(1)
544
+ end
545
+
546
+ it 'waits for the timeout' do
547
+ expect(Mongo::Server::Connection).to receive(:new).once.and_call_original
548
+ service_id
549
+
550
+ pool.check_out(service_id: service_id)
551
+
552
+ start_time = Mongo::Utils.monotonic_time
553
+ expect {
554
+ pool.check_out(service_id: service_id)
555
+ }.to raise_error(Mongo::Error::ConnectionCheckOutTimeout)
556
+ elapsed_time = Mongo::Utils.monotonic_time - start_time
557
+
558
+ elapsed_time.should > 1
559
+ end
499
560
  end
500
561
  end
501
562
  end
@@ -541,7 +602,7 @@ describe Mongo::Server::ConnectionPool do
541
602
  it 'raises an error and emits ConnectionCheckOutFailedEvent' do
542
603
  pool
543
604
 
544
- subscriber = EventSubscriber.new
605
+ subscriber = Mrss::EventSubscriber.new
545
606
  client.subscribe(Mongo::Monitoring::CONNECTION_POOL, subscriber)
546
607
 
547
608
  subscriber.clear_events!
@@ -579,6 +640,11 @@ describe Mongo::Server::ConnectionPool do
579
640
  end
580
641
 
581
642
  shared_examples_for 'disconnects and removes all connections in the pool and bumps generation' do
643
+ # These tests are also applicable to load balancers, but
644
+ # require different setup and assertions because load balancers
645
+ # do not have a single global generation.
646
+ require_topology :single, :replica_set, :sharded
647
+
582
648
  it 'disconnects and removes and bumps' do
583
649
  old_connections = []
584
650
  pool.instance_variable_get('@available_connections').each do |connection|
@@ -9,6 +9,10 @@ describe Mongo::Server::Connection do
9
9
 
10
10
  clean_slate_for_all
11
11
 
12
+ let(:generation_manager) do
13
+ Mongo::Server::ConnectionPool::GenerationManager.new(server: server)
14
+ end
15
+
12
16
  let!(:address) do
13
17
  default_address
14
18
  end
@@ -41,7 +45,10 @@ describe Mongo::Server::Connection do
41
45
  let(:server_options) { SpecConfig.instance.test_options.merge(monitoring_io: false) }
42
46
  let(:server) do
43
47
  register_server(
44
- Mongo::Server.new(address, cluster, monitoring, listeners, server_options)
48
+ Mongo::Server.new(address, cluster, monitoring, listeners, server_options.merge(
49
+ # Normally the load_balancer option is set by the cluster
50
+ load_balancer: ClusterConfig.instance.topology == :load_balanced,
51
+ ))
45
52
  )
46
53
  end
47
54
 
@@ -59,6 +66,7 @@ describe Mongo::Server::Connection do
59
66
  let(:pool) do
60
67
  double('pool').tap do |pool|
61
68
  allow(pool).to receive(:close)
69
+ allow(pool).to receive(:generation_manager).and_return(generation_manager)
62
70
  end
63
71
  end
64
72
 
@@ -81,7 +89,7 @@ describe Mongo::Server::Connection do
81
89
  context 'when no socket exists' do
82
90
 
83
91
  let(:connection) do
84
- described_class.new(server, server.options)
92
+ described_class.new(server, server.options.merge(connection_pool: pool))
85
93
  end
86
94
 
87
95
  let(:result) do
@@ -226,12 +234,15 @@ describe Mongo::Server::Connection do
226
234
 
227
235
  context 'when #handshake! dependency raises a network exception' do
228
236
  let(:exception) do
229
- Mongo::Error::SocketError.new
237
+ Mongo::Error::SocketError.new.tap do |exc|
238
+ allow(exc).to receive(:service_id).and_return('fake')
239
+ end
230
240
  end
231
241
 
232
242
  let(:error) do
233
243
  # The exception is mutated when notes are added to it
234
- expect_any_instance_of(Mongo::Socket).to receive(:write).and_raise(exception.dup)
244
+ expect_any_instance_of(Mongo::Socket).to receive(:write).and_raise(exception)
245
+ allow(connection).to receive(:service_id).and_return('fake')
235
246
  begin
236
247
  connection.connect!
237
248
  rescue Exception => e
@@ -310,7 +321,7 @@ describe Mongo::Server::Connection do
310
321
  context 'when a socket exists' do
311
322
 
312
323
  let(:connection) do
313
- described_class.new(server, server.options)
324
+ described_class.new(server, server.options.merge(connection_pool: pool))
314
325
  end
315
326
 
316
327
  let(:socket) do
@@ -369,10 +380,12 @@ describe Mongo::Server::Connection do
369
380
  described_class.new(
370
381
  server,
371
382
  SpecConfig.instance.test_options.merge(
372
- :user => 'notauser',
373
- :password => 'password',
374
- :database => SpecConfig.instance.test_db,
375
- :heartbeat_frequency => 30)
383
+ user: 'notauser',
384
+ password: 'password',
385
+ database: SpecConfig.instance.test_db,
386
+ heartbeat_frequency: 30,
387
+ connection_pool: pool,
388
+ )
376
389
  )
377
390
  end
378
391
 
@@ -448,8 +461,16 @@ describe Mongo::Server::Connection do
448
461
  )
449
462
  end
450
463
 
464
+ let(:exception) do
465
+ Mongo::Error::SocketError.new.tap do |exc|
466
+ if server.load_balancer?
467
+ allow(exc).to receive(:service_id).and_return('fake')
468
+ end
469
+ end
470
+ end
471
+
451
472
  let(:error) do
452
- expect_any_instance_of(auth_mechanism).to receive(:login).and_raise(Mongo::Error::SocketError)
473
+ expect_any_instance_of(auth_mechanism).to receive(:login).and_raise(exception)
453
474
  begin
454
475
  connection.send(:connect!)
455
476
  rescue => ex
@@ -473,9 +494,11 @@ describe Mongo::Server::Connection do
473
494
  described_class.new(
474
495
  server,
475
496
  SpecConfig.instance.test_options.merge(
476
- :user => SpecConfig.instance.test_user.name,
477
- :password => SpecConfig.instance.test_user.password,
478
- :database => SpecConfig.instance.test_user.database )
497
+ user: SpecConfig.instance.test_user.name,
498
+ password: SpecConfig.instance.test_user.password,
499
+ database: SpecConfig.instance.test_user.database,
500
+ connection_pool: pool,
501
+ )
479
502
  )
480
503
  end
481
504
 
@@ -563,7 +586,7 @@ describe Mongo::Server::Connection do
563
586
  context 'when a socket is not connected' do
564
587
 
565
588
  let(:connection) do
566
- described_class.new(server, server.options)
589
+ described_class.new(server, server.options.merge(connection_pool: pool))
567
590
  end
568
591
 
569
592
  it 'does not raise an error' do
@@ -574,7 +597,7 @@ describe Mongo::Server::Connection do
574
597
  context 'when a socket is connected' do
575
598
 
576
599
  let(:connection) do
577
- described_class.new(server, server.options)
600
+ described_class.new(server, server.options.merge(connection_pool: pool))
578
601
  end
579
602
 
580
603
  before do
@@ -598,7 +621,8 @@ describe Mongo::Server::Connection do
598
621
  described_class.new(
599
622
  server,
600
623
  SpecConfig.instance.test_options.merge(
601
- :database => SpecConfig.instance.test_user.database,
624
+ database: SpecConfig.instance.test_user.database,
625
+ connection_pool: pool,
602
626
  ).merge(Mongo::Utils.shallow_symbolize_keys(Mongo::Client.canonicalize_ruby_options(
603
627
  SpecConfig.instance.credentials_or_external_user(
604
628
  user: SpecConfig.instance.test_user.name,
@@ -817,8 +841,10 @@ describe Mongo::Server::Connection do
817
841
  # of the test, i.e. to avoid racing with the monitor thread
818
842
  # which may put the server back into non-unknown state before
819
843
  # we can verify that the server was marked unknown, kill off
820
- # the monitor thread
821
- server.monitor.instance_variable_get('@thread').kill
844
+ # the monitor thread.
845
+ unless ClusterConfig.instance.topology == :load_balanced
846
+ server.monitor.instance_variable_get('@thread').kill
847
+ end
822
848
  end
823
849
  end
824
850
 
@@ -844,27 +870,44 @@ describe Mongo::Server::Connection do
844
870
  expect(connection).to be_error
845
871
  end
846
872
 
847
- it 'disconnects connection pool' do
848
- expect(server.pool).to receive(:disconnect!)
849
- result
873
+ context 'in load-balanced topology' do
874
+ require_topology :load_balanced
875
+
876
+ it 'disconnects connection pool for service id' do
877
+ connection.service_id.should_not be nil
878
+
879
+ RSpec::Mocks.with_temporary_scope do
880
+ expect(server.pool).to receive(:disconnect!).with(service_id: connection.service_id)
881
+ result
882
+ end
883
+ end
884
+
885
+ it 'does not mark server unknown' do
886
+ expect(server).not_to be_unknown
887
+ result
888
+ expect(server).not_to be_unknown
889
+ end
850
890
  end
851
891
 
852
- it 'marks server unknown' do
853
- expect(server).not_to be_unknown
854
- result
855
- expect(server).to be_unknown
892
+ context 'in non-lb topologies' do
893
+ require_topology :single, :replica_set, :sharded
894
+
895
+ it 'disconnects connection pool' do
896
+ expect(server.pool).to receive(:disconnect!)
897
+ result
898
+ end
899
+
900
+ it 'marks server unknown' do
901
+ expect(server).not_to be_unknown
902
+ result
903
+ expect(server).to be_unknown
904
+ end
856
905
  end
857
906
 
858
907
  it 'does not request server scan' do
859
908
  expect(server.scan_semaphore).not_to receive(:signal)
860
909
  result
861
910
  end
862
-
863
- it 'marks server unknown' do
864
- expect(server).not_to be_unknown
865
- result
866
- expect(server).to be_unknown
867
- end
868
911
  end
869
912
 
870
913
  context 'when a socket timeout occurs' do
@@ -943,7 +986,7 @@ describe Mongo::Server::Connection do
943
986
  context 'when the socket_timeout is negative' do
944
987
 
945
988
  let(:connection) do
946
- described_class.new(server, server.options).tap do |connection|
989
+ described_class.new(server, server.options.merge(connection_pool: pool)).tap do |connection|
947
990
  connection.connect!
948
991
  end
949
992
  end
@@ -1002,7 +1045,7 @@ describe Mongo::Server::Connection do
1002
1045
  context 'when host and port are provided' do
1003
1046
 
1004
1047
  let(:connection) do
1005
- described_class.new(server, server.options)
1048
+ described_class.new(server, server.options.merge(connection_pool: pool))
1006
1049
  end
1007
1050
 
1008
1051
  it 'sets the address' do
@@ -1017,7 +1060,7 @@ describe Mongo::Server::Connection do
1017
1060
  it 'use incrementing ids' do
1018
1061
  expect(connection.id).to eq(1)
1019
1062
 
1020
- second_connection = described_class.new(server, server.options)
1063
+ second_connection = described_class.new(server, server.options.merge(connection_pool: pool))
1021
1064
  expect(second_connection.id).to eq(2)
1022
1065
  end
1023
1066
  end
@@ -1025,7 +1068,11 @@ describe Mongo::Server::Connection do
1025
1068
  context 'two pools for different servers' do
1026
1069
  let(:server2) do
1027
1070
  register_server(
1028
- Mongo::Server.new(address, cluster, monitoring, listeners, server_options)
1071
+ Mongo::Server.new(address, cluster, monitoring, listeners,
1072
+ server_options.merge(
1073
+ load_balancer: ClusterConfig.instance.topology == :load_balanced,
1074
+ )
1075
+ )
1029
1076
  )
1030
1077
  end
1031
1078
 
@@ -1119,10 +1166,11 @@ describe Mongo::Server::Connection do
1119
1166
  let(:connection) do
1120
1167
  described_class.new(
1121
1168
  server,
1122
- :user => SpecConfig.instance.test_user.name,
1123
- :password => SpecConfig.instance.test_user.password,
1124
- :database => SpecConfig.instance.test_db,
1125
- :auth_mech => :mongodb_cr,
1169
+ user: SpecConfig.instance.test_user.name,
1170
+ password: SpecConfig.instance.test_user.password,
1171
+ database: SpecConfig.instance.test_db,
1172
+ auth_mech: :mongodb_cr,
1173
+ connection_pool: pool,
1126
1174
  )
1127
1175
  end
1128
1176
 
@@ -1155,7 +1203,7 @@ describe Mongo::Server::Connection do
1155
1203
  end
1156
1204
 
1157
1205
  let(:connection) do
1158
- described_class.new(server, server.options)
1206
+ described_class.new(server, server.options.merge(connection_pool: pool))
1159
1207
  end
1160
1208
 
1161
1209
  context 'when a connect_timeout is in the options' do
@@ -1244,7 +1292,7 @@ describe Mongo::Server::Connection do
1244
1292
  describe '#app_metadata' do
1245
1293
  context 'when all options are identical to server' do
1246
1294
  let(:connection) do
1247
- described_class.new(server, server.options)
1295
+ described_class.new(server, server.options.merge(connection_pool: pool))
1248
1296
  end
1249
1297
 
1250
1298
  it 'is the same object as server app_metadata' do
@@ -1255,7 +1303,7 @@ describe Mongo::Server::Connection do
1255
1303
 
1256
1304
  context 'when auth options are identical to server' do
1257
1305
  let(:connection) do
1258
- described_class.new(server, server.options.merge(socket_timeout: 2))
1306
+ described_class.new(server, server.options.merge(socket_timeout: 2, connection_pool: pool))
1259
1307
  end
1260
1308
 
1261
1309
  it 'is the same object as server app_metadata' do
@@ -1268,7 +1316,7 @@ describe Mongo::Server::Connection do
1268
1316
  require_no_external_user
1269
1317
 
1270
1318
  let(:connection) do
1271
- described_class.new(server, server.options.merge(user: 'foo'))
1319
+ described_class.new(server, server.options.merge(user: 'foo', connection_pool: pool))
1272
1320
  end
1273
1321
 
1274
1322
  it 'is different object from server app_metadata' do
@@ -1282,4 +1330,51 @@ describe Mongo::Server::Connection do
1282
1330
  end
1283
1331
  end
1284
1332
  end
1333
+
1334
+ describe '#generation' do
1335
+
1336
+ context 'non-lb' do
1337
+ require_topology :single, :replica_set, :sharded
1338
+
1339
+ it 'is set' do
1340
+ server.with_connection do |conn|
1341
+ conn.service_id.should be nil
1342
+ conn.generation.should be_a(Integer)
1343
+ end
1344
+ end
1345
+
1346
+ context 'clean slate' do
1347
+ clean_slate
1348
+
1349
+ it 'starts from 1' do
1350
+ server.with_connection do |conn|
1351
+ conn.service_id.should be nil
1352
+ conn.generation.should == 1
1353
+ end
1354
+ end
1355
+ end
1356
+ end
1357
+
1358
+ context 'lb' do
1359
+ require_topology :load_balanced
1360
+
1361
+ it 'is set' do
1362
+ server.with_connection do |conn|
1363
+ conn.service_id.should_not be nil
1364
+ conn.generation.should be_a(Integer)
1365
+ end
1366
+ end
1367
+
1368
+ context 'clean slate' do
1369
+ clean_slate
1370
+
1371
+ it 'starts from 1' do
1372
+ server.with_connection do |conn|
1373
+ conn.service_id.should_not be nil
1374
+ conn.generation.should == 1
1375
+ end
1376
+ end
1377
+ end
1378
+ end
1379
+ end
1285
1380
  end
@@ -331,7 +331,7 @@ describe Mongo::Server::Description do
331
331
  describe '#average_round_trip_time' do
332
332
 
333
333
  let(:description) do
334
- described_class.new(address, { 'secondary' => false }, 4.5)
334
+ described_class.new(address, { 'secondary' => false }, average_round_trip_time: 4.5)
335
335
  end
336
336
 
337
337
  it 'defaults to nil' do
@@ -186,16 +186,17 @@ describe Mongo::Server::Monitor do
186
186
  context 'when running after a stop' do
187
187
  it 'starts the thread' do
188
188
  ClientRegistry.instance.close_all_clients
189
+ sleep 1
189
190
  thread
190
- sleep 0.5
191
+ sleep 1
191
192
 
192
193
  RSpec::Mocks.with_temporary_scope do
193
194
  expect(monitor.connection).to receive(:disconnect!).and_call_original
194
195
  monitor.stop!
195
- sleep 0.5
196
+ sleep 1
196
197
  expect(thread.alive?).to be false
197
198
  new_thread = monitor.run!
198
- sleep 0.5
199
+ sleep 1
199
200
  expect(new_thread.alive?).to be(true)
200
201
  end
201
202
  end
@@ -5,7 +5,7 @@ require 'spec_helper'
5
5
 
6
6
  describe Mongo::Session::SessionPool do
7
7
  min_server_fcv '3.6'
8
- require_topology :replica_set, :sharded
8
+ require_topology :replica_set, :sharded, :load_balanced
9
9
  clean_slate_for_all
10
10
 
11
11
  let(:cluster) do
@@ -113,10 +113,26 @@ describe Mongo::Session::SessionPool do
113
113
  pool.checkout
114
114
  end
115
115
 
116
- it 'disposes of the old session and returns a new one' do
117
- expect(checked_out_session).not_to be(old_session_a)
118
- expect(checked_out_session).not_to be(old_session_b)
119
- expect(pool.instance_variable_get(:@queue)).to be_empty
116
+ context "in non load-balanced topology" do
117
+ require_topology :replica_set, :sharded
118
+
119
+ it 'disposes of the old session and returns a new one' do
120
+ old_sessions = [old_session_a, old_session_b]
121
+ expect(old_sessions).not_to include(pool.checkout)
122
+ expect(old_sessions).not_to include(pool.checkout)
123
+ expect(pool.instance_variable_get(:@queue)).to be_empty
124
+ end
125
+ end
126
+
127
+ context "in load-balanced topology" do
128
+ require_topology :load_balanced
129
+
130
+ it 'doed not dispose of the old session' do
131
+ old_sessions = [old_session_a, old_session_b]
132
+ expect(old_sessions).to include(checked_out_session)
133
+ expect(old_sessions).to include(checked_out_session)
134
+ expect(pool.instance_variable_get(:@queue)).to be_empty
135
+ end
120
136
  end
121
137
  end
122
138
  end
@@ -138,10 +154,26 @@ describe Mongo::Session::SessionPool do
138
154
  pool.checkin(old_session_b)
139
155
  end
140
156
 
141
- it 'disposes of the old sessions instead of adding them to the pool' do
142
- expect(pool.checkout).not_to be(old_session_a)
143
- expect(pool.checkout).not_to be(old_session_b)
144
- expect(pool.instance_variable_get(:@queue)).to be_empty
157
+ context "in non load-balanced topology" do
158
+ require_topology :replica_set, :sharded
159
+
160
+ it 'disposes of the old sessions instead of adding them to the pool' do
161
+ old_sessions = [old_session_a, old_session_b]
162
+ expect(old_sessions).not_to include(pool.checkout)
163
+ expect(old_sessions).not_to include(pool.checkout)
164
+ expect(pool.instance_variable_get(:@queue)).to be_empty
165
+ end
166
+ end
167
+
168
+ context "in load-balanced topology" do
169
+ require_topology :load_balanced
170
+
171
+ it 'does not dispose of the old sessions' do
172
+ old_sessions = [old_session_a, old_session_b]
173
+ expect(old_sessions).to include(pool.checkout)
174
+ expect(old_sessions).to include(pool.checkout)
175
+ expect(pool.instance_variable_get(:@queue)).to be_empty
176
+ end
145
177
  end
146
178
  end
147
179
  end
@@ -160,7 +192,7 @@ describe Mongo::Session::SessionPool do
160
192
  pool.checkout
161
193
  end
162
194
 
163
- let(:subscriber) { EventSubscriber.new }
195
+ let(:subscriber) { Mrss::EventSubscriber.new }
164
196
 
165
197
  let(:client) do
166
198
  authorized_client.tap do |client|
@@ -117,25 +117,15 @@ describe Mongo::Session do
117
117
  max_example_run_time 7
118
118
 
119
119
  it 'times out' do
120
- warp = Mongo::Utils.monotonic_time + 200
121
- entered = false
120
+ start = Mongo::Utils.monotonic_time
122
121
 
123
- Thread.new do
124
- until entered
125
- sleep 0.1
126
- end
127
- allow(Mongo::Utils).to receive(:monotonic_time).and_return(warp)
128
- end
122
+ expect(Mongo::Utils).to receive(:monotonic_time).ordered.and_return(start)
123
+ expect(Mongo::Utils).to receive(:monotonic_time).ordered.and_return(start + 1)
124
+ expect(Mongo::Utils).to receive(:monotonic_time).ordered.and_return(start + 2)
125
+ expect(Mongo::Utils).to receive(:monotonic_time).ordered.and_return(start + 200)
129
126
 
130
127
  expect do
131
128
  session.with_transaction do
132
- entered = true
133
-
134
- # This sleep is to give the interrupting thread a chance to run,
135
- # it significantly affects how much time is burned in this
136
- # looping thread
137
- sleep 0.1
138
-
139
129
  exc = Mongo::Error::OperationFailure.new('timeout test')
140
130
  exc.add_label('TransientTransactionError')
141
131
  raise exc
@@ -148,21 +138,23 @@ describe Mongo::Session do
148
138
  context "timeout with commit raising with #{label}" do
149
139
  max_example_run_time 7
150
140
 
141
+ # JRuby seems to burn through the monotonic time expectations
142
+ # very quickly and the retries of the transaction get the original
143
+ # time which causes the transaction to be stuck there.
144
+ fails_on_jruby
145
+
151
146
  before do
152
147
  # create collection if it does not exist
153
148
  collection.insert_one(a: 1)
154
149
  end
155
150
 
156
- it 'times out' do
157
- warp = Mongo::Utils.monotonic_time + 200
158
- entered = false
151
+ it 'times out', retry: 3 do
152
+ start = Mongo::Utils.monotonic_time
159
153
 
160
- Thread.new do
161
- until entered
162
- sleep 0.1
163
- end
164
- allow(Mongo::Utils).to receive(:monotonic_time).and_return(warp)
154
+ 10.times do |i|
155
+ expect(Mongo::Utils).to receive(:monotonic_time).ordered.and_return(start + i)
165
156
  end
157
+ expect(Mongo::Utils).to receive(:monotonic_time).ordered.and_return(start + 200)
166
158
 
167
159
  exc = Mongo::Error::OperationFailure.new('timeout test')
168
160
  exc.add_label(label)
@@ -171,13 +163,6 @@ describe Mongo::Session do
171
163
 
172
164
  expect do
173
165
  session.with_transaction do
174
- entered = true
175
-
176
- # This sleep is to give the interrupting thread a chance to run,
177
- # it significantly affects how much time is burned in this
178
- # looping thread
179
- sleep 0.1
180
-
181
166
  collection.insert_one(a: 2)
182
167
  end
183
168
  end.to raise_error(Mongo::Error::OperationFailure, 'timeout test')
@@ -4,6 +4,7 @@
4
4
  require 'spec_helper'
5
5
 
6
6
  describe Mongo::Socket::Unix do
7
+ require_unix_socket
7
8
 
8
9
  let(:path) { "/tmp/mongodb-#{SpecConfig.instance.any_port}.sock" }
9
10