Skip to content

Commit 066b665

Browse files
committed
Merge pull request #595 from tamird/misc-cleanup
Misc cleanup and update specs to RSpec 3
2 parents 9f00684 + 7dffe55 commit 066b665

31 files changed

+1011
-1091
lines changed

.rspec

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
--format documentation
21
--colour
3-
--fail-fast
2+
--format documentation
3+
--order rand
4+
--warnings

.travis.yml

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,10 @@
11
language: ruby
2-
bundler_args: --without benchmarks
3-
script:
4-
- bundle exec rake spec
2+
bundler_args: --without benchmarks development
53
before_install:
64
- gem --version
7-
- |
8-
bash -c " # Install MySQL 5.7 if DB=mysql57
9-
if [[ x$DB =~ mysql57 ]]; then
10-
sudo bash .travis_mysql57.sh
11-
fi
12-
"
13-
- |
14-
bash -c " # Install MariaDB if DB=mariadb
15-
if [[ x$DB =~ xmariadb ]]; then
16-
sudo bash .travis_mariadb.sh '$DB'
17-
fi
18-
"
19-
- |
20-
bash -c " # Install MySQL is OS=darwin
21-
if [[ x$OSTYPE =~ ^xdarwin ]]; then
22-
brew install mysql
23-
mysql.server start
24-
fi
25-
"
26-
- |
27-
bash -c " # Configure SSL support
28-
if [[ ! x$OSTYPE =~ ^xdarwin ]]; then
29-
sudo bash .travis_ssl.sh
30-
sudo service mysql restart
31-
fi
32-
"
5+
- bash .travis_setup.sh
336
- mysqld --version
34-
- mysql -u root -e "CREATE DATABASE IF NOT EXISTS test"
35-
- mysql -u root -e "CREATE USER '$USER'@'localhost'" || true
7+
- mysql -u $USER -e "CREATE DATABASE IF NOT EXISTS test"
368
os:
379
- linux
3810
rvm:
@@ -42,19 +14,14 @@ rvm:
4214
- 2.1
4315
- 2.2
4416
- ree
17+
- rbx-2
4518
matrix:
46-
allow_failures:
47-
- env: DB=mysql57
48-
- rvm: rbx-2
49-
- os: osx
5019
include:
5120
- rvm: 2.0.0
5221
env: DB=mariadb55
5322
- rvm: 2.0.0
5423
env: DB=mariadb10
5524
- rvm: 2.0.0
5625
env: DB=mysql57
57-
- rvm: rbx-2
58-
env: RBXOPT=-Xgc.honor_start=true
5926
- rvm: 2.0.0
6027
os: osx

.travis_mariadb.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
#!/bin/sh
1+
#!/usr/bin/env bash
2+
3+
set -eu
24

35
service mysql stop
46
apt-get purge '^mysql*' 'libmysql*'
5-
apt-get install python-software-properties
67
apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
78

89
if [[ x$1 = xmariadb55 ]]; then

.travis_mysql57.sh

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
#!/bin/sh
1+
#!/usr/bin/env bash
22

3-
service mysql stop
3+
set -eu
44

5+
service mysql stop
56
apt-get purge '^mysql*' 'libmysql*'
6-
apt-get autoclean
7-
8-
rm -rf /var/lib/mysql
9-
rm -rf /var/log/mysql
10-
11-
apt-get install python-software-properties
127
apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0x8C718D3B5072E1F5
8+
139
add-apt-repository 'deb http://repo.mysql.com/apt/ubuntu/ precise mysql-5.7-dmr'
1410

1511
apt-get update

.travis_setup.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu
4+
5+
# Install MySQL 5.7 if DB=mysql57
6+
if [[ -n ${DB-} && x$DB =~ mysql57 ]]; then
7+
sudo bash .travis_mysql57.sh
8+
fi
9+
10+
# Install MariaDB if DB=mariadb
11+
if [[ -n ${DB-} && x$DB =~ xmariadb ]]; then
12+
sudo bash .travis_mariadb.sh "$DB"
13+
fi
14+
15+
# Install MySQL if OS=darwin
16+
if [[ x$OSTYPE =~ ^xdarwin ]]; then
17+
brew install mysql
18+
mysql.server start
19+
fi
20+
21+
# TODO: get SSL working on OS X in Travis
22+
if ! [[ x$OSTYPE =~ ^xdarwin ]]; then
23+
sudo bash .travis_ssl.sh
24+
sudo service mysql restart
25+
fi
26+
27+
sudo mysql -e "CREATE USER '$USER'@'localhost'" || true

.travis_ssl.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
#!/bin/sh
1+
#!/usr/bin/env bash
22

3-
# Halt the tests on error
4-
set -e
3+
set -eu
54

65
# Wherever MySQL configs live, go there (this is for cross-platform)
76
cd $(my_print_defaults --help | grep my.cnf | xargs find 2>/dev/null | xargs dirname)

Gemfile

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,29 @@ source 'https://rubygems.org'
22

33
gemspec
44

5-
# benchmarks
5+
gem 'rake', '~> 10.4.2'
6+
gem 'rake-compiler', '~> 0.9.5'
7+
8+
group :test do
9+
gem 'eventmachine' unless RUBY_PLATFORM =~ /mswin|mingw/
10+
gem 'rspec', '~> 3.2'
11+
end
12+
613
group :benchmarks do
714
gem 'activerecord', '>= 3.0'
8-
gem 'mysql'
15+
gem 'benchmark-ips'
916
gem 'do_mysql'
10-
gem 'sequel'
1117
gem 'faker'
18+
gem 'mysql'
19+
gem 'sequel'
1220
end
1321

1422
group :development do
1523
gem 'pry'
16-
gem 'eventmachine' unless RUBY_PLATFORM =~ /mswin|mingw/
1724
end
1825

1926
platforms :rbx do
20-
gem 'rubysl-rake'
21-
gem 'rubysl-drb'
2227
gem 'rubysl-bigdecimal'
28+
gem 'rubysl-drb'
29+
gem 'rubysl-rake'
2330
end

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,13 +437,13 @@ As for field values themselves, I'm workin on it - but expect that soon.
437437

438438
This gem is tested with the following Ruby versions on Linux and Mac OS X:
439439

440-
* Ruby MRI 1.8.7, 1.9.2, 1.9.3, 2.0.0, 2.1.x, 2.2.x (ongoing patch releases)
440+
* Ruby MRI 1.8.7, 1.9.3, 2.0.0, 2.1.x, 2.2.x
441441
* Ruby Enterprise Edition (based on MRI 1.8.7)
442442
* Rubinius 2.x
443443

444444
This gem is tested with the following MySQL and MariaDB versions:
445445

446-
* MySQL 5.0, 5.1, 5.5, 5.6, 5.7
446+
* MySQL 5.5, 5.7
447447
* MySQL Connector/C 6.0 and 6.1 (primarily on Windows)
448448
* MariaDB 5.5, 10.0
449449

benchmark/active_record.rb

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,32 @@
22
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
33

44
require 'rubygems'
5-
require 'benchmark'
5+
require 'benchmark/ips'
66
require 'active_record'
77

88
ActiveRecord::Base.default_timezone = :local
99
ActiveRecord::Base.time_zone_aware_attributes = true
1010

11-
number_of = 10
12-
mysql2_opts = {
13-
:adapter => 'mysql2',
14-
:database => 'test'
15-
}
16-
mysql_opts = {
17-
:adapter => 'mysql',
18-
:database => 'test'
19-
}
20-
21-
class Mysql2Model < ActiveRecord::Base
22-
self.table_name = "mysql2_test"
23-
end
11+
opts = { :database => 'test' }
2412

25-
class MysqlModel < ActiveRecord::Base
26-
self.table_name = "mysql2_test"
13+
class TestModel < ActiveRecord::Base
14+
self.table_name = 'mysql2_test'
2715
end
2816

29-
Benchmark.bmbm do |x|
30-
x.report "Mysql2" do
31-
Mysql2Model.establish_connection(mysql2_opts)
32-
number_of.times do
33-
Mysql2Model.limit(1000).to_a.each{ |r|
34-
r.attributes.keys.each{ |k|
35-
r.send(k.to_sym)
36-
}
37-
}
38-
end
39-
end
17+
batch_size = 1000
18+
19+
Benchmark.ips do |x|
20+
%w(mysql mysql2).each do |adapter|
21+
TestModel.establish_connection(opts.merge(:adapter => adapter))
4022

41-
x.report "Mysql" do
42-
MysqlModel.establish_connection(mysql_opts)
43-
number_of.times do
44-
MysqlModel.limit(1000).to_a.each{ |r|
45-
r.attributes.keys.each{ |k|
23+
x.report(adapter) do
24+
TestModel.limit(batch_size).to_a.each do |r|
25+
r.attributes.keys.each do |k|
4626
r.send(k.to_sym)
47-
}
48-
}
27+
end
28+
end
4929
end
5030
end
31+
32+
x.compare!
5133
end

benchmark/active_record_threaded.rb

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,22 @@
22
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
33

44
require 'rubygems'
5-
require 'benchmark'
5+
require 'benchmark/ips'
66
require 'active_record'
77

8-
times = 25
8+
number_of_threads = 25
9+
opts = { :database => 'test', :pool => number_of_threads }
910

11+
Benchmark.ips do |x|
12+
%w(mysql mysql2).each do |adapter|
13+
ActiveRecord::Base.establish_connection(opts.merge(:adapter => adapter))
1014

11-
# mysql2
12-
mysql2_opts = {
13-
:adapter => 'mysql2',
14-
:database => 'test',
15-
:pool => times
16-
}
17-
ActiveRecord::Base.establish_connection(mysql2_opts)
18-
x = Benchmark.realtime do
19-
threads = []
20-
times.times do
21-
threads << Thread.new { ActiveRecord::Base.connection.execute("select sleep(1)") }
15+
x.report(adapter) do
16+
number_of_threads.times.map do
17+
Thread.new { ActiveRecord::Base.connection.execute('SELECT SLEEP(1)') }
18+
end.each(&:join)
19+
end
2220
end
23-
threads.each {|t| t.join }
24-
end
25-
puts "mysql2: #{x} seconds"
26-
2721

28-
# mysql
29-
mysql2_opts = {
30-
:adapter => 'mysql',
31-
:database => 'test',
32-
:pool => times
33-
}
34-
ActiveRecord::Base.establish_connection(mysql2_opts)
35-
x = Benchmark.realtime do
36-
threads = []
37-
times.times do
38-
threads << Thread.new { ActiveRecord::Base.connection.execute("select sleep(1)") }
39-
end
40-
threads.each {|t| t.join }
22+
x.compare!
4123
end
42-
puts "mysql: #{x} seconds"

0 commit comments

Comments
 (0)