New mongo-qa test runner and corresponding driver-side files.

This commit is contained in:
Jim Menard 2009-02-02 13:12:33 -05:00
parent d701fd7133
commit 28c66a060c
9 changed files with 86 additions and 51 deletions

15
bin/run_test_script Executable file
View File

@ -0,0 +1,15 @@
#!/bin/bash
# usage: run_test_script test_name output_file
#
# See http://mongodb.onconfluence.com/display/DOCS/Using+the+Framework+(for+Driver+Developers)
HERE=`dirname $0`
begintime=`date`
ruby $HERE/../tests/mongo-qa/$1
exitval=$?
endtime=`date`
echo "begintime:$begintime" >> $2
echo "endtime:$endtime" >> $2
echo "exit_code:$exitval" >> $2

View File

@ -1,51 +0,0 @@
#!/usr/bin/env ruby
#
# usage: validate somefile.xson somefile.bson
#
# Reads somefile.xson file (XML that describes a Mongo-type document),
# converts it into a Ruby OrderedHash, runs that through the BSON
# serialization code, and writes the BSON bytes to somefile.bson.
#
# In addition, this script takes the generated BSON, reads it in then writes
# it back out to a temp BSON file. If they are different, we report that error
# to STDOUT.
#
# This script is used by the mongo-qa project
# (http://github.com/mongodb/mongo-qa).
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
require 'mongo'
require 'mongo/util/xml_to_ruby'
if ARGV.length < 2
$stderr.puts "usage: validate somefile.xson somefile.bson"
exit 1
end
# Translate the .xson XML into a Ruby object, turn that object into BSON, and
# write the BSON to the file as requested.
obj = File.open(ARGV[0], 'rb') { |f| XMLToRuby.new.xml_to_ruby(f) }
bson = BSON.new.serialize(obj).to_a
File.open(ARGV[1], 'wb') { |f| bson.each { |b| f.putc(b) } }
# Now the additional testing. Read the generated BSON back in, deserialize it,
# and re-serialize the results. Compare that BSON with the BSON from the file
# we output.
bson = File.open(ARGV[1], 'rb') { |f| f.read }
bson = if RUBY_VERSION >= '1.9'
bson.bytes.to_a
else
bson.split(//).collect { |c| c[0] }
end
# Turn the Ruby object into BSON bytes and compare with the BSON bytes from
# the file.
bson_from_ruby = BSON.new.serialize(obj).to_a
if bson.length != bson_from_ruby.length
$stderr.puts "error: round-trip BSON lengths differ when testing #{ARGV[0]}"
exit 1
elsif bson != bson_from_ruby
$stderr.puts "error: round-trip BSON contents differ when testing #{ARGV[0]}"
exit 1
end

View File

@ -0,0 +1,8 @@
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '../..', 'lib')
require 'mongo'
DEFAULT_HOST = '127.0.0.1'
DEFAULT_PORT = 27017
DEFAULT_DB = 'driver_test_framework'
include XGen::Mongo::Driver

17
tests/mongo-qa/capped Executable file
View File

@ -0,0 +1,17 @@
#!/usr/bin/env ruby
require File.join(File.dirname(__FILE__), '_common.rb')
db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
db.create_collection('capped1', :capped => true, :size => 500)
coll = db.collection('capped1')
coll.insert('x' => 1)
coll.insert('x' => 2)
db.create_collection('capped2', :capped => true, :size => 1000, :max => 11)
coll = db.collection('capped2')
str = ''
100.times {
coll.insert('dashes' => str)
str << '-'
}

16
tests/mongo-qa/circular Executable file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env ruby
require File.join(File.dirname(__FILE__), '_common.rb')
db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
colla = db.collection('a')
collb = db.collection('b')
collc = db.collection('c')
colla.insert('c' => 'b')
collb.insert('c' => 1)
x_id = ObjectID.new
x_dbref = DBRef.new(nil, 'thiz', db, 'c', x_id)
x = {'_id' => x_id, 'that' => 2, 'thiz' => x_dbref}
collc.insert(x)

10
tests/mongo-qa/count1 Executable file
View File

@ -0,0 +1,10 @@
#!/usr/bin/env ruby
require File.join(File.dirname(__FILE__), '_common.rb')
db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
puts db.collection('test1').count
puts db.collection('test2').count
puts db.collection('test3').count('i' => 'a')
puts db.collection('test3').count('i' => 3)
puts db.collection('test3').count({'i' => {'$gte' => 67}})

6
tests/mongo-qa/find Executable file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env ruby
require File.join(File.dirname(__FILE__), '_common.rb')
db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
db.collection('test').insert('a' => 2)

7
tests/mongo-qa/remove Executable file
View File

@ -0,0 +1,7 @@
#!/usr/bin/env ruby
require File.join(File.dirname(__FILE__), '_common.rb')
db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
db.collection('remove1').clear
db.collection('remove2').remove('a' => 3)

7
tests/mongo-qa/test1 Executable file
View File

@ -0,0 +1,7 @@
#!/usr/bin/env ruby
require File.join(File.dirname(__FILE__), '_common.rb')
db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
coll = db.collection('part1')
100.times { |i| coll.insert('x' => i) }