mongo 2.13.2 → 2.13.3

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 (40) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/lib/mongo/collection.rb +2 -0
  4. data/lib/mongo/database.rb +14 -2
  5. data/lib/mongo/grid/fs_bucket.rb +37 -37
  6. data/lib/mongo/operation/parallel_scan/command.rb +1 -2
  7. data/lib/mongo/operation/shared/read_preference_supported.rb +38 -36
  8. data/lib/mongo/operation/shared/sessions_supported.rb +3 -2
  9. data/lib/mongo/protocol/msg.rb +2 -2
  10. data/lib/mongo/protocol/query.rb +11 -11
  11. data/lib/mongo/server_selector/secondary_preferred.rb +2 -7
  12. data/lib/mongo/version.rb +1 -1
  13. data/spec/integration/sdam_error_handling_spec.rb +1 -1
  14. data/spec/integration/sdam_events_spec.rb +3 -5
  15. data/spec/integration/secondary_reads_spec.rb +102 -0
  16. data/spec/mongo/index/view_spec.rb +4 -2
  17. data/spec/mongo/operation/read_preference_legacy_spec.rb +9 -19
  18. data/spec/mongo/operation/read_preference_op_msg_spec.rb +3 -3
  19. data/spec/mongo/server/app_metadata_shared.rb +33 -7
  20. data/spec/mongo/server_selector/secondary_preferred_spec.rb +6 -6
  21. data/spec/runners/transactions/operation.rb +13 -2
  22. data/spec/shared/bin/get-mongodb-download-url +17 -0
  23. data/spec/shared/lib/mrss/cluster_config.rb +221 -0
  24. data/spec/shared/lib/mrss/constraints.rb +43 -0
  25. data/spec/shared/lib/mrss/docker_runner.rb +265 -0
  26. data/spec/shared/lib/mrss/lite_constraints.rb +16 -0
  27. data/spec/shared/lib/mrss/server_version_registry.rb +115 -0
  28. data/spec/shared/lib/mrss/spec_organizer.rb +3 -0
  29. data/spec/shared/lib/mrss/utils.rb +15 -0
  30. data/spec/shared/share/Dockerfile.erb +231 -0
  31. data/spec/shared/shlib/distro.sh +73 -0
  32. data/spec/shared/shlib/server.sh +290 -0
  33. data/spec/shared/shlib/set_env.sh +128 -0
  34. data/spec/support/client_registry.rb +8 -4
  35. data/spec/support/client_registry_macros.rb +14 -5
  36. data/spec/support/spec_config.rb +12 -0
  37. data/spec/support/spec_setup.rb +48 -38
  38. data.tar.gz.sig +0 -0
  39. metadata +998 -978
  40. metadata.gz.sig +0 -0
@@ -147,6 +147,33 @@ module Mrss
147
147
  end
148
148
  end
149
149
 
150
+ def require_no_snappy_compression
151
+ before(:all) do
152
+ compressors = SpecConfig.instance.compressors
153
+ if compressors && compressors.include?('snappy')
154
+ skip "Snappy compression is enabled"
155
+ end
156
+ end
157
+ end
158
+
159
+ def require_zstd_compression
160
+ before(:all) do
161
+ compressors = SpecConfig.instance.compressors
162
+ unless compressors && compressors.include?('zstd')
163
+ skip "Zstd compression is not enabled"
164
+ end
165
+ end
166
+ end
167
+
168
+ def require_no_zstd_compression
169
+ before(:all) do
170
+ compressors = SpecConfig.instance.compressors
171
+ if compressors && compressors.include?('zstd')
172
+ skip "Zstd compression is enabled"
173
+ end
174
+ end
175
+ end
176
+
150
177
  def require_no_compression
151
178
  before(:all) do
152
179
  if SpecConfig.instance.compressors
@@ -299,5 +326,21 @@ module Mrss
299
326
  end
300
327
  end
301
328
  end
329
+
330
+ def require_required_api_version
331
+ before(:all) do
332
+ unless ENV['API_VERSION_REQUIRED'] == '1'
333
+ skip 'Set API_VERSION_REQUIRED=1 to run this test'
334
+ end
335
+ end
336
+ end
337
+
338
+ def require_no_required_api_version
339
+ before(:all) do
340
+ if ENV['API_VERSION_REQUIRED'] == '1'
341
+ skip 'Cannot have API_VERSION_REQUIRED=1 to run this test'
342
+ end
343
+ end
344
+ end
302
345
  end
303
346
  end
@@ -0,0 +1,265 @@
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
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') do |v|
67
+ @options[:preload] = v
68
+ end
69
+
70
+ opts.on('-s', '--script=SCRIPT', 'Test script to invoke') do |v|
71
+ @options[:script] = v
72
+ end
73
+
74
+ opts.on('-i', '--interactive', 'Interactive mode - disable per-test timeouts') do |v|
75
+ @options[:interactive] = v
76
+ end
77
+ end.parse!
78
+
79
+ @env = Hash[ARGV.map do |arg|
80
+ arg.split('=', 2)
81
+ end]
82
+
83
+ @env['RVM_RUBY'] ||= 'ruby-2.7'
84
+ unless ruby =~ /^j?ruby-/
85
+ raise "RVM_RUBY option is not in expected format: #{ruby}"
86
+ end
87
+
88
+ @env['MONGODB_VERSION'] ||= '4.4'
89
+ end
90
+
91
+ def create_dockerfile
92
+ template_path = File.join(File.dirname(__FILE__), '../../share/Dockerfile.erb')
93
+ result = ERB.new(File.read(template_path)).result(binding)
94
+ File.open(dockerfile_path, 'w') do |f|
95
+ f << result
96
+ end
97
+ end
98
+
99
+ def image_tag
100
+ options.fetch(:image_tag)
101
+ end
102
+
103
+ def dockerfile_path
104
+ options.fetch(:dockerfile_path)
105
+ end
106
+
107
+ def create_image
108
+ run_command(['docker', 'build',
109
+ '-t', image_tag,
110
+ '-f', dockerfile_path,
111
+ '.'])
112
+ end
113
+
114
+ BASE_TEST_COMMAND = %w(docker run -i --tmpfs /tmpfs:exec).freeze
115
+
116
+ def run_tests
117
+ run_command(BASE_TEST_COMMAND + tty_arg + extra_env + [image_tag] +
118
+ script.split(/\s+/))
119
+ end
120
+
121
+ def run_deployment
122
+ run_command(BASE_TEST_COMMAND + tty_arg + extra_env + [
123
+ '-e', %q`TEST_CMD=watch -x bash -c "ps awwxu |egrep 'mongo|ocsp'"`,
124
+ '-e', 'BIND_ALL=true',
125
+ ] + port_forwards + [image_tag] + script.split(/\s+/))
126
+ end
127
+
128
+ def tty_arg
129
+ tty = File.open('/dev/stdin') do |f|
130
+ f.isatty
131
+ end
132
+ if tty
133
+ %w(-t --init)
134
+ else
135
+ []
136
+ end
137
+ end
138
+
139
+ def extra_env
140
+ if @options[:extra_env]
141
+ @options[:extra_env].map do |k, v|
142
+ # Here the value must not be escaped
143
+ ['-e', "#{k}=#{v}"]
144
+ end.flatten
145
+ else
146
+ []
147
+ end
148
+ end
149
+
150
+ def port_forwards
151
+ args = (0...num_exposed_ports).map do |i|
152
+ host_port = @options[:mongo_only] + i
153
+ container_port = 27017 + i
154
+ ['-p', "#{host_port}:#{container_port}"]
155
+ end.flatten
156
+
157
+ if @env['OCSP_ALGORITHM'] && !@env['OCSP_VERIFIER']
158
+ args += %w(-p 8100:8100)
159
+ end
160
+
161
+ args
162
+ end
163
+
164
+ def run_command(cmd)
165
+ if pid = fork
166
+ Process.wait(pid)
167
+ unless $?.exitstatus == 0
168
+ raise "Process exited with code #{$?.exitstatus}"
169
+ end
170
+ else
171
+ exec(*cmd)
172
+ end
173
+ end
174
+
175
+ def distro
176
+ @options[:distro] || 'ubuntu1604'
177
+ end
178
+
179
+ BASE_IMAGES = {
180
+ 'debian81' => 'debian:jessie',
181
+ 'debian92' => 'debian:stretch',
182
+ 'ubuntu1404' => 'ubuntu:trusty',
183
+ 'ubuntu1604' => 'ubuntu:xenial',
184
+ 'ubuntu1804' => 'ubuntu:bionic',
185
+ 'rhel62' => 'centos:6',
186
+ 'rhel70' => 'centos:7',
187
+ }.freeze
188
+
189
+ def base_image
190
+ BASE_IMAGES[distro] or raise "Unknown distro: #{distro}"
191
+ end
192
+
193
+ def ruby
194
+ @env['RVM_RUBY']
195
+ end
196
+
197
+ def ruby_head?
198
+ ruby == 'ruby-head'
199
+ end
200
+
201
+ def server_version
202
+ @env['MONGODB_VERSION']
203
+ end
204
+
205
+ def script
206
+ @options[:script] || options.fetch(:default_script)
207
+ end
208
+
209
+ def debian?
210
+ distro =~ /debian|ubuntu/
211
+ end
212
+
213
+ def preload?
214
+ !!@options[:preload]
215
+ end
216
+
217
+ def interactive?
218
+ !!@options[:interactive]
219
+ end
220
+
221
+ def project_lib_subdir
222
+ options.fetch(:project_lib_subdir)
223
+ end
224
+
225
+ def server_download_url
226
+ @server_download_url ||= ServerVersionRegistry.new(server_version, distro).download_url
227
+ end
228
+
229
+ def libmongocrypt_path
230
+ case distro
231
+ when /ubuntu1604/
232
+ "./ubuntu1604/nocrypto/lib64/libmongocrypt.so"
233
+ when /ubuntu1804/
234
+ "./ubuntu1804-64/nocrypto/lib64/libmongocrypt.so"
235
+ when /debian92/
236
+ "./debian92/nocrypto/lib64/libmongocrypt.so"
237
+ else
238
+ raise "This script does not support running FLE tests on #{distro}. Use ubuntu1604, ubuntu1804 or debian92 instead"
239
+ end
240
+ end
241
+
242
+ def expose?
243
+ !!@options[:mongo_only]
244
+ end
245
+
246
+ def fle?
247
+ %w(1 true yes).include?(@env['FLE']&.downcase)
248
+ end
249
+
250
+ def num_exposed_ports
251
+ case @env['TOPOLOGY'] || 'standalone'
252
+ when 'standalone'
253
+ 1
254
+ when 'replica-set'
255
+ 3
256
+ when 'sharded-cluster'
257
+ if @env['SINGLE_MONGOS']
258
+ 1
259
+ else
260
+ 2
261
+ end
262
+ end
263
+ end
264
+ end
265
+ end
@@ -171,5 +171,21 @@ module Mrss
171
171
  end
172
172
  end
173
173
  end
174
+
175
+ def require_active_support
176
+ before(:all) do
177
+ if !SpecConfig.instance.active_support?
178
+ skip 'This test requires ActiveSupport; set WITH_ACTIVE_SUPPORT=1 in environment'
179
+ end
180
+ end
181
+ end
182
+
183
+ def no_active_support
184
+ before(:all) do
185
+ if SpecConfig.instance.active_support?
186
+ skip 'This test requires no ActiveSupport; unset WITH_ACTIVE_SUPPORT in environment'
187
+ end
188
+ end
189
+ end
174
190
  end
175
191
  end
@@ -0,0 +1,115 @@
1
+ # frozen_string_literal: true
2
+ # encoding: utf-8
3
+
4
+ autoload :JSON, 'json'
5
+ require 'open-uri'
6
+
7
+ module Mrss
8
+ class ServerVersionRegistry
9
+ class Error < StandardError
10
+ end
11
+
12
+ class UnknownVersion < Error
13
+ end
14
+
15
+ class MissingDownloadUrl < Error
16
+ end
17
+
18
+ class BrokenDownloadUrl < Error
19
+ end
20
+
21
+ def initialize(desired_version, arch)
22
+ @desired_version, @arch = desired_version, arch
23
+ end
24
+
25
+ attr_reader :desired_version, :arch
26
+
27
+ def download_url
28
+ @download_url ||= begin
29
+ version, version_ok = detect_version(current_catalog)
30
+ if version.nil?
31
+ version, full_version_ok = detect_version(full_catalog)
32
+ version_ok ||= full_version_ok
33
+ end
34
+ if version.nil?
35
+ if version_ok
36
+ raise MissingDownloadUrl, "No downloads for version #{desired_version}"
37
+ else
38
+ raise UnknownVersion, "No version #{desired_version}"
39
+ end
40
+ end
41
+ dl = version['downloads'].detect do |dl|
42
+ dl['archive']['url'].index("enterprise-#{arch}") &&
43
+ dl['arch'] == 'x86_64'
44
+ end
45
+ unless dl
46
+ raise MissingDownloadUrl, "No download for #{arch} for #{version['version']}"
47
+ end
48
+ url = dl['archive']['url']
49
+ end
50
+ rescue MissingDownloadUrl
51
+ if %w(4.7 4.7.0).include?(desired_version)
52
+ # 4.7.0 has no advertised downloads but it is downloadable and
53
+ # we do need it. Dirty hack below.
54
+ registry = self.class.new('4.4.3', arch)
55
+ registry.download_url.sub('4.4.3', '4.7.0').tap do |url|
56
+ # Sanity check - ensure the URL we hacked up is a valid one
57
+ io = uri_open(url)
58
+ begin
59
+ io.read(1)
60
+ ensure
61
+ io.close
62
+ end
63
+ end
64
+ else
65
+ raise
66
+ end
67
+ end
68
+
69
+ private
70
+
71
+ def uri_open(*args)
72
+ if RUBY_VERSION < '2.5'
73
+ open(*args)
74
+ else
75
+ URI.open(*args)
76
+ end
77
+ end
78
+
79
+ def detect_version(catalog)
80
+ candidate_versions = catalog['versions'].select do |version|
81
+ version['version'].start_with?(desired_version) &&
82
+ !version['version'].include?('-')
83
+ end
84
+ version_ok = !candidate_versions.empty?
85
+ # Sometimes the download situation is borked and there is a release
86
+ # with no downloads... skip those.
87
+ version = candidate_versions.detect do |version|
88
+ !version['downloads'].empty?
89
+ end
90
+ # Allow RC releases if there isn't a GA release.
91
+ if version.nil?
92
+ candidate_versions = catalog['versions'].select do |version|
93
+ version['version'].start_with?(desired_version)
94
+ end
95
+ version_ok ||= !candidate_versions.empty?
96
+ version = candidate_versions.detect do |version|
97
+ !version['downloads'].empty?
98
+ end
99
+ end
100
+ [version, version_ok]
101
+ end
102
+
103
+ def current_catalog
104
+ @current_catalog ||= begin
105
+ JSON.load(uri_open('http://downloads.mongodb.org/current.json').read)
106
+ end
107
+ end
108
+
109
+ def full_catalog
110
+ @full_catalog ||= begin
111
+ JSON.load(uri_open('http://downloads.mongodb.org/full.json').read)
112
+ end
113
+ end
114
+ end
115
+ end