Skip to content

Commit 7550873

Browse files
authored
Merge pull request #767 from DataDog/ci/fix_mongo_2.9_breakage
Fix Mongo 2.9 breaking CI build
2 parents 2e0a3b2 + 85643ea commit 7550873

File tree

1 file changed

+34
-16
lines changed

1 file changed

+34
-16
lines changed

spec/ddtrace/contrib/mongodb/client_spec.rb

+34-16
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,22 @@ def discard_spans!
3636
# Clear data between tests
3737
let(:drop_database?) { true }
3838

39+
def suppress_warnings
40+
original_verbosity = $VERBOSE
41+
$VERBOSE = nil
42+
yield
43+
ensure
44+
$VERBOSE = original_verbosity
45+
end
46+
3947
around do |example|
40-
# Reset before and after each example; don't allow global state to linger.
41-
Datadog.registry[:mongo].reset_configuration!
42-
example.run
43-
Datadog.registry[:mongo].reset_configuration!
44-
client.database.drop if drop_database?
48+
suppress_warnings do
49+
# Reset before and after each example; don't allow global state to linger.
50+
Datadog.registry[:mongo].reset_configuration!
51+
example.run
52+
Datadog.registry[:mongo].reset_configuration!
53+
client.database.drop if drop_database?
54+
end
4555
end
4656

4757
it 'evaluates the block given to the constructor' do
@@ -89,6 +99,14 @@ def discard_spans!
8999
end
90100
end
91101

102+
RSpec::Matchers.define :eq_serialized_operation do |expected|
103+
match do |actual|
104+
actual_obj = actual.is_a?(String) ? JSON.parse(actual.gsub(/=>/, ':')) : actual
105+
expected_obj = expected.is_a?(String) ? JSON.parse(expected.gsub(/=>/, ':')) : expected
106+
expect(expected_obj).to eq(actual_obj)
107+
end
108+
end
109+
92110
describe '#insert_one operation' do
93111
before(:each) { client[collection].insert_one(params) }
94112

@@ -101,7 +119,7 @@ def discard_spans!
101119
if mongo_gem_version < Gem::Version.new('2.5')
102120
expect(span.resource).to eq("{\"operation\"=>:insert, \"database\"=>\"#{database}\", \"collection\"=>\"#{collection}\", \"documents\"=>[{:name=>\"?\"}], \"ordered\"=>\"?\"}")
103121
else
104-
expect(span.resource).to eq("{\"operation\"=>\"insert\", \"database\"=>\"#{database}\", \"collection\"=>\"#{collection}\", \"ordered\"=>\"?\", \"lsid\"=>{\"id\"=>\"?\"}, \"documents\"=>[{\"name\"=>\"?\"}]}")
122+
expect(span.resource).to eq_serialized_operation("{\"operation\"=>\"insert\", \"database\"=>\"#{database}\", \"collection\"=>\"#{collection}\", \"ordered\"=>\"?\", \"lsid\"=>{\"id\"=>\"?\"}, \"documents\"=>[{\"name\"=>\"?\"}]}")
105123
end
106124
expect(span.get_tag('mongodb.rows')).to eq('1')
107125
end
@@ -117,7 +135,7 @@ def discard_spans!
117135
if mongo_gem_version < Gem::Version.new('2.5')
118136
expect(span.resource).to eq("{\"operation\"=>:insert, \"database\"=>\"#{database}\", \"collection\"=>\"#{collection}\", \"documents\"=>[{:name=>\"?\", :hobbies=>[\"?\"]}], \"ordered\"=>\"?\"}")
119137
else
120-
expect(span.resource).to eq("{\"operation\"=>\"insert\", \"database\"=>\"#{database}\", \"collection\"=>\"#{collection}\", \"ordered\"=>\"?\", \"lsid\"=>{\"id\"=>\"?\"}, \"documents\"=>[{\"name\"=>\"?\", \"hobbies\"=>[\"?\"]}]}")
138+
expect(span.resource).to eq_serialized_operation("{\"operation\"=>\"insert\", \"database\"=>\"#{database}\", \"collection\"=>\"#{collection}\", \"ordered\"=>\"?\", \"lsid\"=>{\"id\"=>\"?\"}, \"documents\"=>[{\"name\"=>\"?\", \"hobbies\"=>[\"?\"]}]}")
121139
end
122140
expect(span.get_tag('mongodb.rows')).to eq('1')
123141
end
@@ -143,7 +161,7 @@ def discard_spans!
143161
if mongo_gem_version < Gem::Version.new('2.5')
144162
expect(span.resource).to eq("{\"operation\"=>:insert, \"database\"=>\"#{database}\", \"collection\"=>\"#{collection}\", \"documents\"=>[{:name=>\"?\", :hobbies=>[\"?\"]}, \"?\"], \"ordered\"=>\"?\"}")
145163
else
146-
expect(span.resource).to eq("{\"operation\"=>\"insert\", \"database\"=>\"#{database}\", \"collection\"=>\"#{collection}\", \"ordered\"=>\"?\", \"lsid\"=>{\"id\"=>\"?\"}, \"documents\"=>[{\"name\"=>\"?\", \"hobbies\"=>[\"?\"]}, \"?\"]}")
164+
expect(span.resource).to eq_serialized_operation("{\"operation\"=>\"insert\", \"database\"=>\"#{database}\", \"collection\"=>\"#{collection}\", \"ordered\"=>\"?\", \"lsid\"=>{\"id\"=>\"?\"}, \"documents\"=>[{\"name\"=>\"?\", \"hobbies\"=>[\"?\"]}, \"?\"]}")
147165
end
148166
expect(span.get_tag('mongodb.rows')).to eq('2')
149167
end
@@ -170,7 +188,7 @@ def discard_spans!
170188
if mongo_gem_version < Gem::Version.new('2.5')
171189
expect(span.resource).to eq("{\"operation\"=>\"find\", \"database\"=>\"#{database}\", \"collection\"=>\"#{collection}\", \"filter\"=>{}}")
172190
else
173-
expect(span.resource).to eq("{\"operation\"=>\"find\", \"database\"=>\"#{database}\", \"collection\"=>\"#{collection}\", \"filter\"=>{}, \"lsid\"=>{\"id\"=>\"?\"}}")
191+
expect(span.resource).to eq_serialized_operation("{\"operation\"=>\"find\", \"database\"=>\"#{database}\", \"collection\"=>\"#{collection}\", \"filter\"=>{}, \"lsid\"=>{\"id\"=>\"?\"}}")
174192
end
175193
expect(span.get_tag('mongodb.rows')).to be nil
176194
end
@@ -195,7 +213,7 @@ def discard_spans!
195213
if mongo_gem_version < Gem::Version.new('2.5')
196214
expect(span.resource).to eq("{\"operation\"=>\"find\", \"database\"=>\"#{database}\", \"collection\"=>\"#{collection}\", \"filter\"=>{\"name\"=>\"?\"}}")
197215
else
198-
expect(span.resource).to eq("{\"operation\"=>\"find\", \"database\"=>\"#{database}\", \"collection\"=>\"#{collection}\", \"filter\"=>{\"name\"=>\"?\"}, \"lsid\"=>{\"id\"=>\"?\"}}")
216+
expect(span.resource).to eq_serialized_operation("{\"operation\"=>\"find\", \"database\"=>\"#{database}\", \"collection\"=>\"#{collection}\", \"filter\"=>{\"name\"=>\"?\"}, \"lsid\"=>{\"id\"=>\"?\"}}")
199217
end
200218
expect(span.get_tag('mongodb.rows')).to be nil
201219
end
@@ -224,7 +242,7 @@ def discard_spans!
224242
if mongo_gem_version < Gem::Version.new('2.5')
225243
expect(span.resource).to eq("{\"operation\"=>:update, \"database\"=>\"#{database}\", \"collection\"=>\"#{collection}\", \"updates\"=>[{\"q\"=>{\"name\"=>\"?\"}, \"u\"=>{\"$set\"=>{\"phone_number\"=>\"?\"}}, \"multi\"=>\"?\", \"upsert\"=>\"?\"}], \"ordered\"=>\"?\"}")
226244
else
227-
expect(span.resource).to eq("{\"operation\"=>\"update\", \"database\"=>\"#{database}\", \"collection\"=>\"#{collection}\", \"ordered\"=>\"?\", \"lsid\"=>{\"id\"=>\"?\"}, \"updates\"=>[{\"q\"=>{\"name\"=>\"?\"}, \"u\"=>{\"$set\"=>{\"phone_number\"=>\"?\"}}, \"multi\"=>\"?\", \"upsert\"=>\"?\"}]}")
245+
expect(span.resource).to eq_serialized_operation("{\"operation\"=>\"update\", \"database\"=>\"#{database}\", \"collection\"=>\"#{collection}\", \"ordered\"=>\"?\", \"lsid\"=>{\"id\"=>\"?\"}, \"updates\"=>[{\"q\"=>{\"name\"=>\"?\"}, \"u\"=>{\"$set\"=>{\"phone_number\"=>\"?\"}}, \"multi\"=>\"?\", \"upsert\"=>\"?\"}]}")
228246
end
229247
expect(span.get_tag('mongodb.rows')).to eq('1')
230248
end
@@ -261,7 +279,7 @@ def discard_spans!
261279
if mongo_gem_version < Gem::Version.new('2.5')
262280
expect(span.resource).to eq("{\"operation\"=>:update, \"database\"=>\"#{database}\", \"collection\"=>\"#{collection}\", \"updates\"=>[{\"q\"=>{}, \"u\"=>{\"$set\"=>{\"phone_number\"=>\"?\"}}, \"multi\"=>\"?\", \"upsert\"=>\"?\"}], \"ordered\"=>\"?\"}")
263281
else
264-
expect(span.resource).to eq("{\"operation\"=>\"update\", \"database\"=>\"#{database}\", \"collection\"=>\"#{collection}\", \"ordered\"=>\"?\", \"lsid\"=>{\"id\"=>\"?\"}, \"updates\"=>[{\"q\"=>{}, \"u\"=>{\"$set\"=>{\"phone_number\"=>\"?\"}}, \"multi\"=>\"?\", \"upsert\"=>\"?\"}]}")
282+
expect(span.resource).to eq_serialized_operation("{\"operation\"=>\"update\", \"database\"=>\"#{database}\", \"collection\"=>\"#{collection}\", \"ordered\"=>\"?\", \"lsid\"=>{\"id\"=>\"?\"}, \"updates\"=>[{\"q\"=>{}, \"u\"=>{\"$set\"=>{\"phone_number\"=>\"?\"}}, \"multi\"=>\"?\", \"upsert\"=>\"?\"}]}")
265283
end
266284
expect(span.get_tag('mongodb.rows')).to eq('2')
267285
end
@@ -290,7 +308,7 @@ def discard_spans!
290308
if mongo_gem_version < Gem::Version.new('2.5')
291309
expect(span.resource).to eq("{\"operation\"=>:delete, \"database\"=>\"#{database}\", \"collection\"=>\"#{collection}\", \"deletes\"=>[{\"q\"=>{\"name\"=>\"?\"}, \"limit\"=>\"?\"}], \"ordered\"=>\"?\"}")
292310
else
293-
expect(span.resource).to eq("{\"operation\"=>\"delete\", \"database\"=>\"#{database}\", \"collection\"=>\"#{collection}\", \"ordered\"=>\"?\", \"lsid\"=>{\"id\"=>\"?\"}, \"deletes\"=>[{\"q\"=>{\"name\"=>\"?\"}, \"limit\"=>\"?\"}]}")
311+
expect(span.resource).to eq_serialized_operation("{\"operation\"=>\"delete\", \"database\"=>\"#{database}\", \"collection\"=>\"#{collection}\", \"ordered\"=>\"?\", \"lsid\"=>{\"id\"=>\"?\"}, \"deletes\"=>[{\"q\"=>{\"name\"=>\"?\"}, \"limit\"=>\"?\"}]}")
294312
end
295313
expect(span.get_tag('mongodb.rows')).to eq('1')
296314
end
@@ -327,7 +345,7 @@ def discard_spans!
327345
if mongo_gem_version < Gem::Version.new('2.5')
328346
expect(span.resource).to eq("{\"operation\"=>:delete, \"database\"=>\"#{database}\", \"collection\"=>\"#{collection}\", \"deletes\"=>[{\"q\"=>{\"name\"=>\"?\"}, \"limit\"=>\"?\"}], \"ordered\"=>\"?\"}")
329347
else
330-
expect(span.resource).to eq("{\"operation\"=>\"delete\", \"database\"=>\"#{database}\", \"collection\"=>\"#{collection}\", \"ordered\"=>\"?\", \"lsid\"=>{\"id\"=>\"?\"}, \"deletes\"=>[{\"q\"=>{\"name\"=>\"?\"}, \"limit\"=>\"?\"}]}")
348+
expect(span.resource).to eq_serialized_operation("{\"operation\"=>\"delete\", \"database\"=>\"#{database}\", \"collection\"=>\"#{collection}\", \"ordered\"=>\"?\", \"lsid\"=>{\"id\"=>\"?\"}, \"deletes\"=>[{\"q\"=>{\"name\"=>\"?\"}, \"limit\"=>\"?\"}]}")
331349
end
332350
expect(span.get_tag('mongodb.rows')).to eq('2')
333351
end
@@ -344,7 +362,7 @@ def discard_spans!
344362
if mongo_gem_version < Gem::Version.new('2.5')
345363
expect(span.resource).to eq("{\"operation\"=>:dropDatabase, \"database\"=>\"#{database}\", \"collection\"=>1}")
346364
else
347-
expect(span.resource).to eq("{\"operation\"=>\"dropDatabase\", \"database\"=>\"#{database}\", \"collection\"=>1, \"lsid\"=>{\"id\"=>\"?\"}}")
365+
expect(span.resource).to eq_serialized_operation("{\"operation\"=>\"dropDatabase\", \"database\"=>\"#{database}\", \"collection\"=>1, \"lsid\"=>{\"id\"=>\"?\"}}")
348366
end
349367
expect(span.get_tag('mongodb.rows')).to be nil
350368
end
@@ -359,7 +377,7 @@ def discard_spans!
359377
if mongo_gem_version < Gem::Version.new('2.5')
360378
expect(span.resource).to eq("{\"operation\"=>:drop, \"database\"=>\"#{database}\", \"collection\"=>\"#{collection}\"}")
361379
else
362-
expect(span.resource).to eq("{\"operation\"=>\"drop\", \"database\"=>\"#{database}\", \"collection\"=>\"#{collection}\", \"lsid\"=>{\"id\"=>\"?\"}}")
380+
expect(span.resource).to eq_serialized_operation("{\"operation\"=>\"drop\", \"database\"=>\"#{database}\", \"collection\"=>\"#{collection}\", \"lsid\"=>{\"id\"=>\"?\"}}")
363381
end
364382
expect(span.get_tag('mongodb.rows')).to be nil
365383
expect(span.status).to eq(1)

0 commit comments

Comments
 (0)