Skip to content

Commit

Permalink
Merge ccdf003 into 5110edc
Browse files Browse the repository at this point in the history
  • Loading branch information
hirocaster committed Mar 10, 2016
2 parents 5110edc + ccdf003 commit 7809f0e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
@@ -1 +1 @@
2.2.4
2.3.0
5 changes: 3 additions & 2 deletions .travis.yml
Expand Up @@ -4,6 +4,7 @@ cache:
directories:
- vendor/bundle
rvm:
- 2.3.0
- 2.2.4
- 2.1.8
- 2.0.0-p648
Expand All @@ -24,8 +25,8 @@ before_install:
- chmod +x cpanm
- cd -
- cpanm MySQL::Sandbox
- wget http://ftp.kaist.ac.kr/mysql/Downloads/MySQL-5.6/mysql-5.6.27-linux-glibc2.5-x86_64.tar.gz
- make_replication_sandbox mysql-5.6.27-linux-glibc2.5-x86_64.tar.gz
- wget http://ftp.kaist.ac.kr/mysql/Downloads/MySQL-5.6/mysql-5.6.29-linux-glibc2.5-x86_64.tar.gz
- make_replication_sandbox --sandbox_base_port=2000 mysql-5.6.29-linux-glibc2.5-x86_64.tar.gz
- gem install bundler -v 1.10.6
script:
- bundle exec rake spec
14 changes: 7 additions & 7 deletions spec/active_record/slave/model_spec.rb
@@ -1,13 +1,13 @@
describe ActiveRecord::Slave::Model do
it "connect to master" do
expect(User.connection.pool.spec.config[:port]).to eq 22092
expect(User.connection.pool.spec.config[:port]).to eq 2000
end

it "connect to slaves", retry: 3 do
slave_ports = 10.times.map { User.slave_for.connection.pool.spec.config[:port] }.uniq
expect(slave_ports.count).to eq 2
expect(slave_ports).to include 22093
expect(slave_ports).to include 22094
expect(slave_ports).to include 2001
expect(slave_ports).to include 2002
end

it "connect to default" do
Expand All @@ -27,15 +27,15 @@

describe "multi thread" do
before do
Parallel.each((0..99).to_a, :in_threads => 8) do |dummy|
Parallel.each((0..99).to_a, :in_threads => 2) do |dummy|
User.connection_pool.with_connection do
User.create name: "test#{dummy}"
end
end
end

it "returns writed models" do
Parallel.each((0..14).to_a, :in_threads => 8) do |dummy|
Parallel.each((0..14).to_a, :in_threads => 2) do |dummy|
User.slave_for.connection_pool.with_connection do
expect(User.slave_for.all.count).to eq 100
end
Expand Down Expand Up @@ -95,11 +95,11 @@
end

it "returns master database service port" do
expect(Skill.connection.pool.spec.config[:port]).to eq 22092
expect(Skill.connection.pool.spec.config[:port]).to eq 2000
end

it "returns slave database service port" do
expect(Skill.slave_for.connection.pool.spec.config[:port]).to eq(22093) | eq(22094)
expect(Skill.slave_for.connection.pool.spec.config[:port]).to eq(2001) | eq(2002)
end
end
end
Expand Down
12 changes: 6 additions & 6 deletions spec/models.rb
@@ -1,14 +1,14 @@
base = { "adapter" => "mysql2", "encoding" => "utf8", "pool" => 5, "username" => "root", "password" => "msandbox", "host" => "127.0.0.1" }

ActiveRecord::Base.configurations = {
"test_master" => base.merge("database" => "test_slave", "port" => 22092),
"test_slave_001" => base.merge("database" => "test_slave", "port" => 22093),
"test_slave_002" => base.merge("database" => "test_slave", "port" => 22094),
"test_master" => base.merge("database" => "test_slave", "port" => 2000),
"test_slave_001" => base.merge("database" => "test_slave", "port" => 2001),
"test_slave_002" => base.merge("database" => "test_slave", "port" => 2002),
"test" => base.merge("database" => "test", "port" => 3306, "password" => ""),

"test_task_master" => base.merge("database" => "test_task", "port" => 22092),
"test_task_slave_001" => base.merge("database" => "test_task", "port" => 22093),
"test_task_slave_002" => base.merge("database" => "test_task", "port" => 22094)
"test_task_master" => base.merge("database" => "test_task", "port" => 2000),
"test_task_slave_001" => base.merge("database" => "test_task", "port" => 2001),
"test_task_slave_002" => base.merge("database" => "test_task", "port" => 2002)
}

ActiveRecord::Slave.configure do |config|
Expand Down

0 comments on commit 7809f0e

Please sign in to comment.