wip integration servers
This commit is contained in:
parent
2d6f51f68c
commit
bd1c8efe54
6 changed files with 65 additions and 9 deletions
|
|
@ -6,7 +6,7 @@ require 'uri'
|
|||
class AppConfig < Settingslogic
|
||||
|
||||
def self.source_file_name
|
||||
if Rails.env == 'test' || ENV["CI"]
|
||||
if Rails.env == 'test' || ENV["CI"] || Rails.env.include?("integration")
|
||||
File.join(Rails.root, "config", "application.yml.example")
|
||||
else
|
||||
File.join(Rails.root, "config", "application.yml")
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ class Retraction
|
|||
def subscribers(user)
|
||||
unless self.type == 'Person'
|
||||
@subscribers ||= self.object.subscribers(user)
|
||||
@subscribers -= self.object.resharers
|
||||
@subscribers
|
||||
else
|
||||
raise 'HAX: you must set the subscribers manaully before unfriending' if @subscribers.nil?
|
||||
@subscribers
|
||||
|
|
|
|||
|
|
@ -154,3 +154,10 @@ test:
|
|||
open_invitations: false
|
||||
|
||||
|
||||
integration_1:
|
||||
<<: *defaults
|
||||
pod_url: "http://localhost:45789"
|
||||
|
||||
integration_2:
|
||||
<<: *defaults
|
||||
pod_url: "http://localhost:34658"
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ class Chubbies
|
|||
|
||||
def self.run
|
||||
@pid = fork do
|
||||
Process.exec "cd #{Rails.root}/spec/chubbies/ && bundle exec rackup -p #{PORT} 2> /dev/null 1> /dev/null"
|
||||
Process.exec "cd #{Rails.root}/spec/chubbies/ && bundle exec #{run_command} #{nullify}"
|
||||
end
|
||||
|
||||
at_exit do
|
||||
|
|
@ -94,9 +94,13 @@ class Chubbies
|
|||
end
|
||||
end
|
||||
|
||||
def self.run_command
|
||||
"rackup -p #{PORT}"
|
||||
end
|
||||
|
||||
def self.get_pid
|
||||
@pid ||= lambda {
|
||||
processes = `ps ax -o pid,command | grep "rackup -p #{PORT}"`.split("\n")
|
||||
processes = `ps ax -o pid,command | grep "#{run_command}"`.split("\n")
|
||||
processes = processes.select{|p| !p.include?("grep") }
|
||||
processes.first.split(" ").first
|
||||
}.call
|
||||
|
|
|
|||
|
|
@ -2,13 +2,18 @@
|
|||
|
||||
require 'spec_helper'
|
||||
WebMock::Config.instance.allow_localhost = true
|
||||
if Server.all && Server.all.first && Server.all.first.running?
|
||||
unless Server.all.empty?
|
||||
describe Server do
|
||||
before(:all) do
|
||||
WebMock::Config.instance.allow_localhost = true
|
||||
Server.all.each{|s| s.kill if s.running?}
|
||||
Server.all.each{|s| s.run}
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
Server.all.each{|s| s.kill if s.running?}
|
||||
sleep(1)
|
||||
Server.all.each{|s| puts "Server at port #{s.port} still running." if s.running?}
|
||||
WebMock::Config.instance.allow_localhost = false
|
||||
end
|
||||
|
||||
|
|
@ -25,12 +30,12 @@ if Server.all && Server.all.first && Server.all.first.running?
|
|||
it 'takes an environment' do
|
||||
server = Server.new("integration_1")
|
||||
server.env.should == "integration_1"
|
||||
server.port.should == ActiveRecord::Base.configurations["integration_1"]["app_server_port"]
|
||||
end
|
||||
end
|
||||
describe "#running?" do
|
||||
it "verifies that the server is running" do
|
||||
Server.new("integration_1").running?.should be_true
|
||||
server = Server.new("integration_1")
|
||||
server.running?.should be_true
|
||||
end
|
||||
end
|
||||
describe '#db' do
|
||||
|
|
|
|||
|
|
@ -8,11 +8,48 @@ class Server
|
|||
|
||||
attr_reader :port, :env
|
||||
def initialize(env)
|
||||
@config = ActiveRecord::Base.configurations[env]
|
||||
@port = @config["app_server_port"]
|
||||
@db_config = ActiveRecord::Base.configurations[env]
|
||||
@app_config = (YAML.load_file AppConfig.source)[env]
|
||||
@port = URI::parse(@app_config["pod_url"]).port
|
||||
@env = env
|
||||
ensure_database_setup
|
||||
end
|
||||
|
||||
def ensure_database_setup
|
||||
`cd #{Rails.root} && RAILS_ENV=#{@env} bundle exec rake db:create`
|
||||
tables_exist = self.db do
|
||||
ActiveRecord::Base.connection.tables.include?("users")
|
||||
end
|
||||
if tables_exist
|
||||
truncate_database
|
||||
else
|
||||
`cd #{Rails.root} && RAILS_ENV=#{@env} bundle exec rake db:schema:load`
|
||||
end
|
||||
end
|
||||
|
||||
def run
|
||||
@pid = fork do
|
||||
Process.exec "cd #{Rails.root} && RAILS_ENV=#{@env} bundle exec #{run_command}"
|
||||
end
|
||||
end
|
||||
|
||||
def kill
|
||||
puts "I am trying to kill the server"
|
||||
`kill -9 #{get_pid}`
|
||||
end
|
||||
|
||||
def run_command
|
||||
"rails s thin -p #{@port}"
|
||||
end
|
||||
|
||||
def get_pid
|
||||
@pid = lambda {
|
||||
processes = `ps ax -o pid,command | grep "#{run_command}"`.split("\n")
|
||||
processes = processes.select{|p| !p.include?("grep") }
|
||||
processes.first.split(" ").first
|
||||
}.call
|
||||
end
|
||||
|
||||
def running?
|
||||
begin
|
||||
RestClient.get("localhost:#{@port}/users/sign_in")
|
||||
|
|
@ -25,8 +62,9 @@ class Server
|
|||
def db
|
||||
former_env = Rails.env
|
||||
ActiveRecord::Base.establish_connection(env)
|
||||
yield
|
||||
result = yield
|
||||
ActiveRecord::Base.establish_connection(former_env)
|
||||
result
|
||||
end
|
||||
|
||||
def truncate_database
|
||||
|
|
|
|||
Loading…
Reference in a new issue