Skip to content
Browse files

Merge "make mongodb unit test pass with dev_setup" into services-r9

  • Loading branch information...
2 parents 2b874dd + 07f62de commit aa784bcb4b330afa5585d7cba7823e1502e816d8 @cliffwang cliffwang committed with Gerrit Code Review
View
2 mongodb/spec/config/mongodb_backup.yml.erb
@@ -2,7 +2,7 @@ service_name: mongodb
backup_base_dir: <%= BACKUP_DIR %>
local_db: sqlite3:/tmp/mongo/mongodb_node.db
service_base_dir: /tmp/mongo/instances
-mongodump_path: mongodump
+mongodump_path: <%= BINARY_DIR %>/mongodump
timeout: 10
logging:
level: debug
View
1 mongodb/spec/mongodb_backup_spec.rb
@@ -10,6 +10,7 @@
@opts = get_node_config()
@logger = @opts[:logger]
+ BINARY_DIR = File.dirname(@opts[:mongod_path])
@node = Node.new(@opts)
@resp = @node.provision("free")
View
18 mongodb/spec/mongodb_provision_spec.rb
@@ -95,9 +95,18 @@
stats = @node.varz_details
available = stats[:running_services][0]['overall']['connections']['available']
- available.times do
+
+ # ruby mongo client has a issue. When making connection to mongod, it will make two
+ # actual sockets, one for read, one for write. When authentication done, one of them
+ # will be closed. But for here, the maximum connection test, it will cause a problem,
+ # when last available connection met. So here we decrease one for available connection.
+ available = available - 1
+ available.times do |i|
begin
- connections << Mongo::Connection.new('localhost', @resp['port'])
+ conn = Mongo::Connection.new('localhost', @resp['port'])
+ db = conn.db(@resp['db'])
+ auth = db.authenticate(@resp['username'], @resp['password'])
+ connections << conn
rescue Mongo::ConnectionFailure => e
first_conn_refused = true
end
@@ -105,7 +114,10 @@
# max+1's connection should fail
begin
- connections << Mongo::Connection.new('localhost', @resp['port'])
+ conn = Mongo::Connection.new('localhost', @resp['port'])
+ db = conn.db(@resp['db'])
+ auth = db.authenticate(@resp['username'], @resp['password'])
+ connections << conn
rescue Mongo::ConnectionFailure => e
max_conn_refused = true
end
View
15 mongodb/spec/spec_helper.rb
@@ -102,8 +102,21 @@ def parse_property(hash, key, type, options = {})
end
end
+def config_base_dir()
+ config_path = File.join(PWD, "../config/")
+ # detect dev_setup
+ dev_local = File.expand_path("~/.cloudfoundry_deployment_local")
+ if File.exist?(dev_local)
+ File.open(dev_local, "r") do |f|
+ f.read.match('CLOUD_FOUNDRY_CONFIG_PATH=([[:graph:]]+)')
+ config_path = $1
+ end
+ end
+ config_path
+end
+
def get_node_config()
- config_file = File.join(PWD, "../config/mongodb_node.yml")
+ config_file = File.join(config_base_dir, "mongodb_node.yml")
config = YAML.load_file(config_file)
mongodb_conf_template = File.join(PWD, "../resources/mongodb.conf.erb")
options = {

0 comments on commit aa784bc

Please sign in to comment.
Something went wrong with that request. Please try again.