Skip to content

Commit

Permalink
Use travis, fix bug in fuzzer rounding
Browse files Browse the repository at this point in the history
  • Loading branch information
eac committed Feb 15, 2019
1 parent 1d3e686 commit 2d5faf3
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 4 deletions.
9 changes: 8 additions & 1 deletion .travis.yml
@@ -1,6 +1,13 @@
language: ruby
cache: bundler

rvm:
- 2.3

services:
- mysql
- mysql

before_script:
- cp .travis/my.cnf ~/.my.cnf
- mysql -e 'create database shiba_test;'
- mysql shiba_test -e 'source test/structure.sql'
3 changes: 3 additions & 0 deletions .travis/my.cnf
@@ -0,0 +1,3 @@
[client]
user = travis
password =
3 changes: 2 additions & 1 deletion lib/shiba/fuzzer.rb
Expand Up @@ -50,7 +50,8 @@ def guess_table_sizes
index_counts = connection.query(index_count_query).to_a

# 90th table percentile based on number of indexes
large_table_idx = (index_counts.size * 0.9).round
# round down so we don't blow up on small tables
large_table_idx = (index_counts.size * 0.9).floor
large_table_index_count = index_counts[large_table_idx]["index_count"].to_f

sizes = Hash[index_counts.map(&:values)]
Expand Down
6 changes: 5 additions & 1 deletion lib/shiba/index_stats.rb
Expand Up @@ -3,11 +3,16 @@

module Shiba
class IndexStats

def initialize(tables = {})
@tables = tables
build_from_hash!
end

def any?
@tables.any?
end

Table = Struct.new(:name, :count, :indexes) do
def encode_with(coder)
coder.map = self.to_h.stringify_keys
Expand Down Expand Up @@ -203,4 +208,3 @@ def each_index_column(&block)
end
end
end

1 change: 0 additions & 1 deletion test/backtrace_test.rb
@@ -1,7 +1,6 @@
require 'helper'
require 'shiba/backtrace'


describe "Backtrace" do

it "doesn't blow up" do
Expand Down
15 changes: 15 additions & 0 deletions test/integration_test.rb
@@ -0,0 +1,15 @@
require 'helper'
require 'shiba'
require 'shiba/fuzzer'

describe "Connection" do

it "doesn't blow up" do
Shiba.configure('database' => 'shiba_test', 'default_file' => '~/.my.cnf', 'default_group' => 'client')
assert_equal 'shiba_test', Shiba.connection.query("select database() as db").first["db"]

stats = Shiba::Fuzzer.new(Shiba.connection).fuzz!
assert stats.any?, stats.inspect
end

end
28 changes: 28 additions & 0 deletions test/structure.sql
@@ -0,0 +1,28 @@
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`organization_id` int(11) DEFAULT NULL,
`email` varchar(255) NOT NULL,
`name` varchar(255) DEFAULT '',
`created_at` datetime NOT NULL,
`updated_at` datetime(3) NOT NULL,
PRIMARY KEY (`id`),
KEY `index_users_on_organization_id` (`organization_id`)
);

CREATE TABLE `organizations` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT '',
`created_at` datetime NOT NULL,
`updated_at` datetime(3) NOT NULL,
PRIMARY KEY (`id`)
);

CREATE TABLE `comments` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`body` mediumtext NOT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime(3) NOT NULL,
PRIMARY KEY (`id`),
KEY `index_comments_on_user_id` (`user_id`)
);

0 comments on commit 2d5faf3

Please sign in to comment.