mongoid 8.0.9 → 8.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/CHANGELOG.md +3 -3
  4. data/README.md +3 -3
  5. data/Rakefile +18 -67
  6. data/lib/config/locales/en.yml +46 -14
  7. data/lib/mongoid/association/accessors.rb +3 -7
  8. data/lib/mongoid/association/builders.rb +1 -1
  9. data/lib/mongoid/association/eager_loadable.rb +0 -3
  10. data/lib/mongoid/association/embedded/batchable.rb +2 -2
  11. data/lib/mongoid/association/embedded/embedded_in/buildable.rb +2 -2
  12. data/lib/mongoid/association/embedded/embedded_in/proxy.rb +2 -1
  13. data/lib/mongoid/association/embedded/embeds_many/buildable.rb +3 -2
  14. data/lib/mongoid/association/embedded/embeds_many/proxy.rb +6 -6
  15. data/lib/mongoid/association/embedded/embeds_one/buildable.rb +1 -1
  16. data/lib/mongoid/association/embedded/embeds_one/proxy.rb +1 -1
  17. data/lib/mongoid/association/macros.rb +0 -6
  18. data/lib/mongoid/association/nested/one.rb +40 -2
  19. data/lib/mongoid/association/proxy.rb +1 -1
  20. data/lib/mongoid/association/referenced/counter_cache.rb +2 -2
  21. data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +1 -1
  22. data/lib/mongoid/association/referenced/has_many/enumerable.rb +2 -2
  23. data/lib/mongoid/association/referenced/has_many/proxy.rb +3 -3
  24. data/lib/mongoid/association/reflections.rb +2 -2
  25. data/lib/mongoid/atomic.rb +7 -16
  26. data/lib/mongoid/attributes/dynamic.rb +1 -1
  27. data/lib/mongoid/attributes/nested.rb +2 -2
  28. data/lib/mongoid/attributes/processing.rb +5 -29
  29. data/lib/mongoid/attributes/projector.rb +1 -1
  30. data/lib/mongoid/attributes/readonly.rb +1 -1
  31. data/lib/mongoid/attributes.rb +8 -2
  32. data/lib/mongoid/changeable.rb +107 -5
  33. data/lib/mongoid/clients/storage_options.rb +2 -5
  34. data/lib/mongoid/clients/validators/storage.rb +1 -13
  35. data/lib/mongoid/collection_configurable.rb +58 -0
  36. data/lib/mongoid/composable.rb +2 -0
  37. data/lib/mongoid/config/defaults.rb +60 -0
  38. data/lib/mongoid/config/options.rb +0 -3
  39. data/lib/mongoid/config/validators/async_query_executor.rb +24 -0
  40. data/lib/mongoid/config/validators.rb +1 -0
  41. data/lib/mongoid/config.rb +88 -27
  42. data/lib/mongoid/contextual/atomic.rb +1 -1
  43. data/lib/mongoid/contextual/memory.rb +233 -33
  44. data/lib/mongoid/contextual/mongo/documents_loader.rb +177 -0
  45. data/lib/mongoid/contextual/mongo.rb +370 -133
  46. data/lib/mongoid/contextual/none.rb +162 -7
  47. data/lib/mongoid/contextual.rb +12 -0
  48. data/lib/mongoid/criteria/findable.rb +2 -2
  49. data/lib/mongoid/criteria/includable.rb +4 -3
  50. data/lib/mongoid/criteria/queryable/extensions/numeric.rb +1 -15
  51. data/lib/mongoid/criteria/queryable/key.rb +1 -1
  52. data/lib/mongoid/criteria/queryable/mergeable.rb +1 -1
  53. data/lib/mongoid/criteria/queryable/optional.rb +8 -8
  54. data/lib/mongoid/criteria/queryable/selectable.rb +43 -12
  55. data/lib/mongoid/criteria/queryable/selector.rb +1 -1
  56. data/lib/mongoid/criteria/queryable/storable.rb +1 -1
  57. data/lib/mongoid/criteria.rb +6 -5
  58. data/lib/mongoid/deprecable.rb +1 -2
  59. data/lib/mongoid/deprecation.rb +3 -3
  60. data/lib/mongoid/document.rb +1 -8
  61. data/lib/mongoid/errors/create_collection_failure.rb +33 -0
  62. data/lib/mongoid/errors/drop_collection_failure.rb +27 -0
  63. data/lib/mongoid/errors/immutable_attribute.rb +26 -0
  64. data/lib/mongoid/errors/invalid_async_query_executor.rb +25 -0
  65. data/lib/mongoid/errors/invalid_global_executor_concurrency.rb +22 -0
  66. data/lib/mongoid/errors/invalid_storage_parent.rb +2 -0
  67. data/lib/mongoid/errors.rb +4 -1
  68. data/lib/mongoid/extensions/hash.rb +2 -24
  69. data/lib/mongoid/extensions/object.rb +2 -2
  70. data/lib/mongoid/extensions/time.rb +2 -0
  71. data/lib/mongoid/fields/localized.rb +10 -0
  72. data/lib/mongoid/fields/standard.rb +10 -0
  73. data/lib/mongoid/fields.rb +59 -35
  74. data/lib/mongoid/findable.rb +27 -3
  75. data/lib/mongoid/interceptable.rb +6 -116
  76. data/lib/mongoid/matcher/eq_impl.rb +1 -1
  77. data/lib/mongoid/matcher/type.rb +1 -1
  78. data/lib/mongoid/persistable/creatable.rb +1 -0
  79. data/lib/mongoid/persistable/deletable.rb +1 -1
  80. data/lib/mongoid/persistable/savable.rb +13 -1
  81. data/lib/mongoid/persistable/unsettable.rb +2 -2
  82. data/lib/mongoid/persistable/updatable.rb +51 -1
  83. data/lib/mongoid/persistable/upsertable.rb +20 -1
  84. data/lib/mongoid/persistable.rb +3 -0
  85. data/lib/mongoid/query_cache.rb +5 -1
  86. data/lib/mongoid/railties/database.rake +7 -2
  87. data/lib/mongoid/reloadable.rb +5 -3
  88. data/lib/mongoid/stateful.rb +22 -1
  89. data/lib/mongoid/tasks/database.rake +12 -0
  90. data/lib/mongoid/tasks/database.rb +20 -0
  91. data/lib/mongoid/timestamps/created.rb +1 -8
  92. data/lib/mongoid/traversable.rb +0 -12
  93. data/lib/mongoid/utils.rb +22 -0
  94. data/lib/mongoid/validatable/associated.rb +17 -98
  95. data/lib/mongoid/validatable/macros.rb +5 -5
  96. data/lib/mongoid/validatable.rb +4 -9
  97. data/lib/mongoid/version.rb +1 -1
  98. data/lib/mongoid/warnings.rb +17 -1
  99. data/lib/mongoid.rb +16 -3
  100. data/spec/integration/app_spec.rb +2 -2
  101. data/spec/integration/associations/has_and_belongs_to_many_spec.rb +0 -40
  102. data/spec/integration/callbacks_spec.rb +99 -12
  103. data/spec/integration/discriminator_key_spec.rb +4 -5
  104. data/spec/integration/i18n_fallbacks_spec.rb +3 -2
  105. data/spec/mongoid/association/eager_spec.rb +2 -24
  106. data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +27 -0
  107. data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +20 -25
  108. data/spec/mongoid/association/embedded/embeds_many_models.rb +1 -0
  109. data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +0 -4
  110. data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +15 -2
  111. data/spec/mongoid/association/referenced/belongs_to_spec.rb +2 -18
  112. data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +5 -27
  113. data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +9 -50
  114. data/spec/mongoid/association/syncable_spec.rb +1 -1
  115. data/spec/mongoid/association_spec.rb +0 -60
  116. data/spec/mongoid/attributes_spec.rb +3 -33
  117. data/spec/mongoid/changeable_spec.rb +299 -24
  118. data/spec/mongoid/clients_spec.rb +122 -13
  119. data/spec/mongoid/collection_configurable_spec.rb +158 -0
  120. data/spec/mongoid/config/defaults_spec.rb +160 -0
  121. data/spec/mongoid/config_spec.rb +154 -27
  122. data/spec/mongoid/contextual/memory_spec.rb +332 -76
  123. data/spec/mongoid/contextual/mongo/documents_loader_spec.rb +187 -0
  124. data/spec/mongoid/contextual/mongo_spec.rb +1009 -125
  125. data/spec/mongoid/contextual/none_spec.rb +49 -2
  126. data/spec/mongoid/copyable_spec.rb +2 -10
  127. data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +4 -10
  128. data/spec/mongoid/criteria/queryable/options_spec.rb +1 -1
  129. data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +419 -0
  130. data/spec/mongoid/criteria/queryable/selectable_spec.rb +1 -1
  131. data/spec/mongoid/criteria/queryable/selector_spec.rb +3 -76
  132. data/spec/mongoid/criteria/queryable/storable_spec.rb +0 -72
  133. data/spec/mongoid/criteria_projection_spec.rb +1 -4
  134. data/spec/mongoid/criteria_spec.rb +5 -9
  135. data/spec/mongoid/document_spec.rb +0 -27
  136. data/spec/mongoid/errors/readonly_document_spec.rb +2 -2
  137. data/spec/mongoid/extensions/hash_spec.rb +3 -3
  138. data/spec/mongoid/extensions/time_spec.rb +8 -43
  139. data/spec/mongoid/extensions/time_with_zone_spec.rb +7 -52
  140. data/spec/mongoid/fields/localized_spec.rb +46 -28
  141. data/spec/mongoid/fields_spec.rb +136 -77
  142. data/spec/mongoid/findable_spec.rb +391 -34
  143. data/spec/mongoid/indexable_spec.rb +16 -10
  144. data/spec/mongoid/interceptable_spec.rb +153 -442
  145. data/spec/mongoid/interceptable_spec_models.rb +111 -51
  146. data/spec/mongoid/persistable/deletable_spec.rb +26 -6
  147. data/spec/mongoid/persistable/destroyable_spec.rb +26 -6
  148. data/spec/mongoid/persistable/incrementable_spec.rb +37 -0
  149. data/spec/mongoid/persistable/logical_spec.rb +37 -0
  150. data/spec/mongoid/persistable/poppable_spec.rb +36 -0
  151. data/spec/mongoid/persistable/pullable_spec.rb +72 -0
  152. data/spec/mongoid/persistable/pushable_spec.rb +72 -0
  153. data/spec/mongoid/persistable/renamable_spec.rb +36 -0
  154. data/spec/mongoid/persistable/savable_spec.rb +96 -0
  155. data/spec/mongoid/persistable/settable_spec.rb +37 -0
  156. data/spec/mongoid/persistable/unsettable_spec.rb +36 -0
  157. data/spec/mongoid/persistable/updatable_spec.rb +20 -28
  158. data/spec/mongoid/persistable/upsertable_spec.rb +80 -6
  159. data/spec/mongoid/persistence_context_spec.rb +7 -57
  160. data/spec/mongoid/query_cache_spec.rb +56 -61
  161. data/spec/mongoid/reloadable_spec.rb +24 -28
  162. data/spec/mongoid/scopable_spec.rb +70 -0
  163. data/spec/mongoid/serializable_spec.rb +23 -44
  164. data/spec/mongoid/stateful_spec.rb +122 -8
  165. data/spec/mongoid/tasks/database_rake_spec.rb +74 -0
  166. data/spec/mongoid/tasks/database_spec.rb +127 -0
  167. data/spec/mongoid/timestamps/created_spec.rb +0 -23
  168. data/spec/mongoid/timestamps_spec.rb +9 -11
  169. data/spec/mongoid/touchable_spec.rb +277 -5
  170. data/spec/mongoid/touchable_spec_models.rb +3 -1
  171. data/spec/mongoid/traversable_spec.rb +9 -24
  172. data/spec/mongoid/validatable/associated_spec.rb +34 -27
  173. data/spec/mongoid/validatable/uniqueness_spec.rb +2 -3
  174. data/spec/mongoid_spec.rb +36 -10
  175. data/spec/shared/LICENSE +20 -0
  176. data/spec/shared/bin/get-mongodb-download-url +17 -0
  177. data/spec/shared/bin/s3-copy +45 -0
  178. data/spec/shared/bin/s3-upload +69 -0
  179. data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
  180. data/spec/shared/lib/mrss/cluster_config.rb +231 -0
  181. data/spec/shared/lib/mrss/constraints.rb +378 -0
  182. data/spec/shared/lib/mrss/docker_runner.rb +298 -0
  183. data/spec/shared/lib/mrss/eg_config_utils.rb +51 -0
  184. data/spec/shared/lib/mrss/event_subscriber.rb +210 -0
  185. data/spec/shared/lib/mrss/lite_constraints.rb +238 -0
  186. data/spec/shared/lib/mrss/server_version_registry.rb +113 -0
  187. data/spec/shared/lib/mrss/session_registry.rb +69 -0
  188. data/spec/shared/lib/mrss/session_registry_legacy.rb +60 -0
  189. data/spec/shared/lib/mrss/spec_organizer.rb +179 -0
  190. data/spec/shared/lib/mrss/utils.rb +37 -0
  191. data/spec/shared/share/Dockerfile.erb +321 -0
  192. data/spec/shared/share/haproxy-1.conf +16 -0
  193. data/spec/shared/share/haproxy-2.conf +17 -0
  194. data/spec/shared/shlib/config.sh +27 -0
  195. data/spec/shared/shlib/distro.sh +74 -0
  196. data/spec/shared/shlib/server.sh +416 -0
  197. data/spec/shared/shlib/set_env.sh +169 -0
  198. data/spec/spec_helper.rb +5 -0
  199. data/spec/support/immutable_ids.rb +118 -0
  200. data/spec/support/macros.rb +47 -15
  201. data/spec/support/models/artist.rb +0 -1
  202. data/spec/support/models/band.rb +1 -0
  203. data/spec/support/models/book.rb +1 -0
  204. data/spec/support/models/building.rb +2 -0
  205. data/spec/support/models/cover.rb +10 -0
  206. data/spec/support/models/name.rb +0 -10
  207. data/spec/support/models/person.rb +0 -1
  208. data/spec/support/models/product.rb +1 -0
  209. data.tar.gz.sig +0 -0
  210. metadata +746 -636
  211. metadata.gz.sig +2 -0
  212. data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +0 -60
  213. data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +0 -60
  214. data/spec/support/models/purse.rb +0 -9
@@ -0,0 +1,298 @@
1
+ # frozen_string_literal: true
2
+ # encoding: utf-8
3
+
4
+ require 'optparse'
5
+ require 'erb'
6
+ autoload :Dotenv, 'dotenv'
7
+
8
+ module Mrss
9
+ autoload :ServerVersionRegistry, 'mrss/server_version_registry'
10
+
11
+ class DockerRunner
12
+ def initialize(**opts)
13
+ # These options are required:
14
+ opts.fetch(:image_tag)
15
+ opts.fetch(:dockerfile_path)
16
+ opts.fetch(:default_script)
17
+ opts.fetch(:project_lib_subdir)
18
+
19
+ @options = opts.merge(preload: true)
20
+ end
21
+
22
+ attr_reader :options
23
+
24
+ def run
25
+ process_arguments
26
+ unless @options[:exec_only]
27
+ create_dockerfile
28
+ create_image
29
+ end
30
+ if @options[:mongo_only]
31
+ run_deployment
32
+ else
33
+ run_tests
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def process_arguments
40
+ #@options = {}
41
+ OptionParser.new do |opts|
42
+ opts.banner = "Usage: test-on-docker [-d distro] [evergreen_key=value ...]"
43
+
44
+ opts.on("-a", "--add-env=PATH", "Load environment variables from PATH in .env format") do |path|
45
+ @options[:extra_env] ||= {}
46
+ unless File.exist?(path)
47
+ raise "-a option references nonexistent file #{path}"
48
+ end
49
+ Dotenv.parse(path).each do |k, v|
50
+ @options[:extra_env][k] = v
51
+ end
52
+ end
53
+
54
+ opts.on("-d", "--distro=DISTRO", "Distro to use") do |v|
55
+ @options[:distro] = v
56
+ end
57
+
58
+ opts.on('-e', '--exec-only', 'Execute tests using existing Dockerfile (for offline user)') do |v|
59
+ @options[:exec_only] = v
60
+ end
61
+
62
+ opts.on('-m', '--mongo-only=PORT', 'Start the MongoDB deployment and expose it to host on ports starting with PORT') do |v|
63
+ @options[:mongo_only] = v.to_i
64
+ end
65
+
66
+ opts.on('-p', '--preload', 'Preload Ruby toolchain and server binaries in docker (default)') do |v|
67
+ @options[:preload] = v
68
+ end
69
+
70
+ opts.on('-P', '--no-preload', 'Do not preload Ruby toolchain and server binaries in docker') do
71
+ @options[:preload] = false
72
+ end
73
+
74
+ opts.on('-s', '--script=SCRIPT', 'Test script to invoke') do |v|
75
+ @options[:script] = v
76
+ end
77
+
78
+ opts.on('-i', '--interactive', 'Interactive mode - disable per-test timeouts') do |v|
79
+ @options[:interactive] = v
80
+ end
81
+ end.parse!
82
+
83
+ @env = Hash[ARGV.map do |arg|
84
+ arg.split('=', 2)
85
+ end]
86
+
87
+ @env['RVM_RUBY'] ||= 'ruby-2.7'
88
+ unless ruby =~ /^j?ruby-/
89
+ raise "RVM_RUBY option is not in expected format: #{ruby}"
90
+ end
91
+
92
+ @env['MONGODB_VERSION'] ||= '4.4'
93
+ end
94
+
95
+ def create_dockerfile
96
+ template_path = File.join(File.dirname(__FILE__), '../../share/Dockerfile.erb')
97
+ result = ERB.new(File.read(template_path)).result(binding)
98
+ File.open(dockerfile_path, 'w') do |f|
99
+ f << result
100
+ end
101
+ end
102
+
103
+ def image_tag
104
+ options.fetch(:image_tag)
105
+ end
106
+
107
+ def dockerfile_path
108
+ options.fetch(:dockerfile_path)
109
+ end
110
+
111
+ def create_image
112
+ run_command(['docker', 'build',
113
+ '-t', image_tag,
114
+ '-f', dockerfile_path,
115
+ '.'])
116
+ end
117
+
118
+ BASE_TEST_COMMAND = %w(docker run --rm -i --tmpfs /tmpfs:exec).freeze
119
+
120
+ def run_tests
121
+ run_command(BASE_TEST_COMMAND + tty_arg + extra_env + [image_tag] +
122
+ script.split(/\s+/))
123
+ end
124
+
125
+ def run_deployment
126
+ run_command(BASE_TEST_COMMAND + tty_arg + extra_env + [
127
+ '-e', %q`TEST_CMD=watch -x bash -c "ps awwxu |egrep 'mongo|ocsp'"`,
128
+ '-e', 'BIND_ALL=true',
129
+ ] + port_forwards + [image_tag] + script.split(/\s+/))
130
+ end
131
+
132
+ def tty_arg
133
+ tty = File.open('/dev/stdin') do |f|
134
+ f.isatty
135
+ end
136
+ if tty
137
+ %w(-t --init)
138
+ else
139
+ []
140
+ end
141
+ end
142
+
143
+ def extra_env
144
+ if @options[:extra_env]
145
+ @options[:extra_env].map do |k, v|
146
+ # Here the value must not be escaped
147
+ ['-e', "#{k}=#{v}"]
148
+ end.flatten
149
+ else
150
+ []
151
+ end
152
+ end
153
+
154
+ def port_forwards
155
+ args = (0...num_exposed_ports).map do |i|
156
+ host_port = @options[:mongo_only] + i
157
+ container_port = 27017 + i
158
+ ['-p', "#{host_port}:#{container_port}"]
159
+ end.flatten
160
+
161
+ if @env['OCSP_ALGORITHM'] && !@env['OCSP_VERIFIER']
162
+ args += %w(-p 8100:8100)
163
+ end
164
+
165
+ args
166
+ end
167
+
168
+ def run_command(cmd)
169
+ if pid = fork
170
+ Process.wait(pid)
171
+ unless $?.exitstatus == 0
172
+ raise "Process exited with code #{$?.exitstatus}"
173
+ end
174
+ else
175
+ exec(*cmd)
176
+ end
177
+ end
178
+
179
+ def distro
180
+ @options[:distro] || if app_tests?
181
+ 'ubuntu2004'
182
+ else
183
+ case server_version
184
+ when '3.6'
185
+ 'debian9'
186
+ when '4.0', '4.2'
187
+ 'ubuntu1804'
188
+ else
189
+ 'ubuntu2004'
190
+ end
191
+ end
192
+ end
193
+
194
+ BASE_IMAGES = {
195
+ 'debian81' => 'debian:jessie',
196
+ 'debian92' => 'debian:stretch',
197
+ 'debian10' => 'debian:buster',
198
+ 'debian11' => 'debian:bullseye',
199
+ 'ubuntu1404' => 'ubuntu:trusty',
200
+ 'ubuntu1604' => 'ubuntu:xenial',
201
+ 'ubuntu1804' => 'ubuntu:bionic',
202
+ 'ubuntu2004' => 'ubuntu:focal',
203
+ 'ubuntu2204' => 'ubuntu:jammy',
204
+ 'rhel62' => 'centos:6',
205
+ 'rhel70' => 'centos:7',
206
+ 'rhel80' => 'rockylinux:8',
207
+ }.freeze
208
+
209
+ def base_image
210
+ BASE_IMAGES[distro] or raise "Unknown distro: #{distro}"
211
+ end
212
+
213
+ def ruby
214
+ @env['RVM_RUBY']
215
+ end
216
+
217
+ def ruby_head?
218
+ ruby == 'ruby-head'
219
+ end
220
+
221
+ def system_ruby?
222
+ %w(1 true yes).include?(@env['SYSTEM_RUBY']&.downcase)
223
+ end
224
+
225
+ def server_version
226
+ @env['MONGODB_VERSION']
227
+ end
228
+
229
+ def script
230
+ @options[:script] || options.fetch(:default_script)
231
+ end
232
+
233
+ def debian?
234
+ distro =~ /debian|ubuntu/
235
+ end
236
+
237
+ def ubuntu?
238
+ distro=~ /ubuntu/
239
+ end
240
+
241
+ def preload?
242
+ !!@options[:preload]
243
+ end
244
+
245
+ def interactive?
246
+ !!@options[:interactive]
247
+ end
248
+
249
+ def project_lib_subdir
250
+ options.fetch(:project_lib_subdir)
251
+ end
252
+
253
+ def server_download_url
254
+ @server_download_url ||= ServerVersionRegistry.new(server_version, distro).download_url
255
+ end
256
+
257
+ def libmongocrypt_path
258
+ case distro
259
+ when /ubuntu1604/
260
+ "./ubuntu1604/nocrypto/lib64/libmongocrypt.so"
261
+ when /ubuntu1804/
262
+ "./ubuntu1804-64/nocrypto/lib64/libmongocrypt.so"
263
+ when /debian92/
264
+ "./debian92/nocrypto/lib64/libmongocrypt.so"
265
+ else
266
+ raise "This script does not support running FLE tests on #{distro}. Use ubuntu1604, ubuntu1804 or debian92 instead"
267
+ end
268
+ end
269
+
270
+ def expose?
271
+ !!@options[:mongo_only]
272
+ end
273
+
274
+ def fle?
275
+ %w(1 true yes).include?(@env['FLE']&.downcase)
276
+ end
277
+
278
+ # Mongoid
279
+ def app_tests?
280
+ %w(1 true yes).include?(@env['APP_TESTS']&.downcase)
281
+ end
282
+
283
+ def num_exposed_ports
284
+ case @env['TOPOLOGY'] || 'standalone'
285
+ when 'standalone'
286
+ 1
287
+ when 'replica-set'
288
+ 3
289
+ when 'sharded-cluster'
290
+ if @env['SINGLE_MONGOS']
291
+ 1
292
+ else
293
+ 2
294
+ end
295
+ end
296
+ end
297
+ end
298
+ end
@@ -0,0 +1,51 @@
1
+ autoload :YAML, 'yaml'
2
+ require 'erubi'
3
+ require 'erubi/capture_end'
4
+ require 'tilt'
5
+
6
+ module Mrss
7
+ module EgConfigUtils
8
+
9
+ DEBIAN_FOR_RUBY = {
10
+ 'ruby-2.3' => 'debian92',
11
+ 'ruby-2.4' => 'debian92',
12
+ 'ruby-2.5' => 'debian10',
13
+ 'ruby-2.6' => 'debian10',
14
+ 'ruby-2.7' => 'debian10',
15
+ 'ruby-3.0' => 'debian10',
16
+ }
17
+
18
+ def standard_debian_rubies(rubies, key: nil, &block)
19
+ rubies.flatten!
20
+ text = block.call
21
+ contents = YAML.load(text)
22
+ out = rubies.map do |ruby|
23
+ contents.merge(
24
+ 'matrix_name' => "#{contents['matrix_name']} - #{ruby}",
25
+ 'matrix_spec' => contents['matrix_spec'].merge(
26
+ 'ruby' => ruby,
27
+ key || 'os' => DEBIAN_FOR_RUBY.fetch(ruby),
28
+ ),
29
+ )
30
+ end.to_yaml
31
+ text =~ /\A\n?(\s+)/
32
+ unless text
33
+ raise "Couldn't figure out indentation level"
34
+ end
35
+ indent = ' ' * ($1.length - 2)
36
+ "\n" + out.sub(/\A---.*\n/, indent).gsub("\n", "\n#{indent}")
37
+ end
38
+
39
+ def transform_config(template_path, context)
40
+ Tilt.new(template_path, engine_class: Erubi::CaptureEndEngine).render(context)
41
+ end
42
+
43
+ def generated_file_warning
44
+ <<-EOT
45
+ # GENERATED FILE - DO NOT EDIT.
46
+ # Run ./.evergreen/update-evergreen-configs to regenerate this file.
47
+
48
+ EOT
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,210 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mrss
4
+ # Test event subscriber.
5
+ class EventSubscriber
6
+
7
+ # The mappings of event names to types.
8
+ MAPPINGS = {
9
+ 'topology_opening_event' => Mongo::Monitoring::Event::TopologyOpening,
10
+ 'topology_description_changed_event' => Mongo::Monitoring::Event::TopologyChanged,
11
+ 'topology_closed_event' => Mongo::Monitoring::Event::TopologyClosed,
12
+ 'server_opening_event' => Mongo::Monitoring::Event::ServerOpening,
13
+ 'server_description_changed_event' => Mongo::Monitoring::Event::ServerDescriptionChanged,
14
+ 'server_closed_event' => Mongo::Monitoring::Event::ServerClosed
15
+ }.freeze
16
+
17
+ attr_reader :all_events
18
+
19
+ attr_reader :started_events
20
+
21
+ attr_reader :succeeded_events
22
+
23
+ attr_reader :failed_events
24
+
25
+ attr_reader :published_events
26
+
27
+ # @param [ String ] name Optional name for the event subscriber.
28
+ def initialize(name: nil)
29
+ @mutex = Mutex.new
30
+ clear_events!
31
+ @name = name
32
+ end
33
+
34
+ def to_s
35
+ %Q`#<EventSubscriber:#{@name ? "\"#{@name}\"" : '%x' % object_id} \
36
+ started=#{started_events.length} \
37
+ succeeded=#{succeeded_events.length} \
38
+ failed=#{failed_events.length} \
39
+ published=#{published_events.length}>`
40
+ end
41
+
42
+ alias :inspect :to_s
43
+
44
+ # Event retrieval
45
+
46
+ def select_started_events(cls)
47
+ started_events.select do |event|
48
+ event.is_a?(cls)
49
+ end
50
+ end
51
+
52
+ def select_succeeded_events(cls)
53
+ succeeded_events.select do |event|
54
+ event.is_a?(cls)
55
+ end
56
+ end
57
+
58
+ def select_completed_events(*classes)
59
+ (succeeded_events + failed_events).select do |event|
60
+ classes.any? { |c| c === event }
61
+ end
62
+ end
63
+
64
+ def select_published_events(cls)
65
+ published_events.select do |event|
66
+ event.is_a?(cls)
67
+ end
68
+ end
69
+
70
+ # Filters command started events for the specified command name.
71
+ def command_started_events(command_name)
72
+ started_events.select do |event|
73
+ event.command[command_name]
74
+ end
75
+ end
76
+
77
+ def non_auth_command_started_events
78
+ started_events.reject do |event|
79
+ %w(authenticate getnonce saslSstart saslContinue).any? do |cmd|
80
+ event.command[cmd]
81
+ end
82
+ end
83
+ end
84
+
85
+ # Locates command stated events for the specified command name,
86
+ # asserts that there is exactly one such event, and returns it.
87
+ def single_command_started_event(command_name, include_auth: false, database_name: nil)
88
+ events = if include_auth
89
+ started_events
90
+ else
91
+ non_auth_command_started_events
92
+ end
93
+ get_one_event(events, command_name, 'started', database_name: database_name)
94
+ end
95
+
96
+ # Locates command succeeded events for the specified command name,
97
+ # asserts that there is exactly one such event, and returns it.
98
+ def single_command_succeeded_event(command_name, database_name: nil)
99
+ get_one_event(succeeded_events, command_name, 'succeeded', database_name: database_name)
100
+ end
101
+
102
+ def get_one_event(events, command_name, kind, database_name: nil)
103
+ events = events.select do |event|
104
+ event.command_name == command_name and
105
+ database_name.nil? || database_name == event.database_name
106
+ end
107
+ if events.length != 1
108
+ raise "Expected a single '#{command_name}' #{kind} event#{database_name ? " for '#{database_name}'" : ''} but we have #{events.length}"
109
+ end
110
+ events.first
111
+ end
112
+
113
+ # Get the first succeeded event published for the name, and then delete it.
114
+ #
115
+ # @param [ String ] name The event name.
116
+ #
117
+ # @return [ Event ] The matching event.
118
+ def first_event(name)
119
+ cls = MAPPINGS[name]
120
+ if cls.nil?
121
+ raise ArgumentError, "Bogus event name #{name}"
122
+ end
123
+ matching = succeeded_events.find do |event|
124
+ cls === event
125
+ end
126
+ succeeded_events.delete(matching)
127
+ matching
128
+ end
129
+
130
+ # Event recording
131
+
132
+ # Cache the started event.
133
+ #
134
+ # @param [ Event ] event The event.
135
+ def started(event)
136
+ @mutex.synchronize do
137
+ started_events << event
138
+ all_events << event
139
+ end
140
+ end
141
+
142
+ # Cache the succeeded event.
143
+ #
144
+ # @param [ Event ] event The event.
145
+ def succeeded(event)
146
+ @mutex.synchronize do
147
+ succeeded_events << event
148
+ all_events << event
149
+ end
150
+ end
151
+
152
+ # Cache the failed event.
153
+ #
154
+ # @param [ Event ] event The event.
155
+ def failed(event)
156
+ @mutex.synchronize do
157
+ failed_events << event
158
+ all_events << event
159
+ end
160
+ end
161
+
162
+ def published(event)
163
+ @mutex.synchronize do
164
+ published_events << event
165
+ all_events << event
166
+ end
167
+ end
168
+
169
+ # Clear all cached events.
170
+ def clear_events!
171
+ @all_events = []
172
+ @started_events = []
173
+ @succeeded_events = []
174
+ @failed_events = []
175
+ @published_events = []
176
+ self
177
+ end
178
+ end
179
+ # Only handles succeeded events correctly.
180
+ class PhasedEventSubscriber < EventSubscriber
181
+ def initialize
182
+ super
183
+ @phase_events = {}
184
+ end
185
+
186
+ def phase_finished(phase_index)
187
+ @phase_events[phase_index] = succeeded_events
188
+ @succeeded_events = []
189
+ end
190
+
191
+ def phase_events(phase_index)
192
+ @phase_events[phase_index]
193
+ end
194
+
195
+ def event_count
196
+ @phase_events.inject(0) do |sum, event|
197
+ sum + event.length
198
+ end
199
+ end
200
+ end
201
+
202
+ class VerboseEventSubscriber < EventSubscriber
203
+ %w(started succeeded failed published).each do |meth|
204
+ define_method(meth) do |event|
205
+ puts event.summary
206
+ super(event)
207
+ end
208
+ end
209
+ end
210
+ end