minitest-perf 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +16 -7
- data/lib/minitest/perf.rb +15 -0
- data/lib/minitest/perf/persistence.rb +41 -31
- data/lib/minitest/perf/test.rb +1 -1
- data/lib/minitest/perf/version.rb +1 -1
- data/test/perf/persistence_test.rb +16 -5
- data/test/perf/test_test.rb +1 -1
- data/test/perf_test.rb +19 -0
- metadata +4 -2
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# MiniTest::Perf
|
2
2
|
|
3
3
|
`minitest-perf` stores information about your minitest runs so that you can later analyze and see where
|
4
|
-
the pain points are. It's in pretty early beta status, so I'm more than glad to receive bug
|
4
|
+
the pain points are. It's in pretty early beta status, so I'm more than glad to receive bug reports and
|
5
5
|
feature suggestions.
|
6
6
|
|
7
7
|
For now it should work with later versions of MiniTest 4, since the biggest test suite I have available
|
@@ -10,18 +10,28 @@ is with this version. MiniTest 5 probably doesn't work yet.
|
|
10
10
|
## How it works
|
11
11
|
|
12
12
|
Every test that is executed is stored in a sqlite database for later query. Just require `minitet/perf`
|
13
|
-
somewhere in your test_helper, and you're good to go. Internally, `minitest/perf` includes itself as
|
13
|
+
somewhere in your test_helper, and you're good to go. Internally, `minitest/perf` includes itself as
|
14
14
|
just another module and starts feeding the sqlite database.
|
15
15
|
|
16
|
-
The sqlite database is stored by default as `.minitest-perf.db`.
|
16
|
+
The sqlite database is stored by default as `.minitest-perf.db`. It can be set using either the
|
17
|
+
environment variable `MINITEST_PERF_DATABASE_URL`, or the `DATABASE_URL`.
|
17
18
|
|
18
|
-
|
19
|
-
|
19
|
+
Or setting it directly via ruby with:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
MiniTest::Perf.database_url = 'sqlite3://localhost/some_other_file.db'
|
23
|
+
```
|
24
|
+
|
25
|
+
So far only local `sqlite3` databases allowed, but I'm using the database url strategy to allow for
|
26
|
+
flexibility in the future.
|
27
|
+
|
28
|
+
An executable is provided that prints a very basic analysis of the information it already has, but
|
29
|
+
the sqlite database is perfectly normal, so you can do your own queries.
|
20
30
|
|
21
31
|
This is an example:
|
22
32
|
|
23
33
|
```
|
24
|
-
$
|
34
|
+
$ minitest-perf
|
25
35
|
Slowest individual tests
|
26
36
|
|
27
37
|
190.98ms | JobsCategoriesControllerLoggedOutTest#test_show_action_should_render_show_page_without_contact_distance_call_for_logged_out_users
|
@@ -54,6 +64,5 @@ Slowest test suites
|
|
54
64
|
|
55
65
|
These are nice to haves I'd like to implement in the future:
|
56
66
|
|
57
|
-
* Customizable db file
|
58
67
|
* Store also in mysql
|
59
68
|
* Web interface
|
data/lib/minitest/perf.rb
CHANGED
@@ -9,6 +9,21 @@ module MiniTest::Perf
|
|
9
9
|
autoload :Plugin, 'minitest/perf/plugin'
|
10
10
|
autoload :Persistence, 'minitest/perf/persistence'
|
11
11
|
autoload :Statistics, 'minitest/perf/statistics'
|
12
|
+
|
13
|
+
class << self
|
14
|
+
attr_accessor :database_url
|
15
|
+
attr_writer :persistence
|
16
|
+
|
17
|
+
def database_url
|
18
|
+
@database_url ||= ENV["MINITEST_PERF_DATABASE_URL"] ||
|
19
|
+
ENV["DATABASE_URL"] ||
|
20
|
+
'sqlite3://localhost/.minitest-perf.db'
|
21
|
+
end
|
22
|
+
def persistence
|
23
|
+
@persistence ||= Persistence.new(database_url)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
12
27
|
end
|
13
28
|
|
14
29
|
class MiniTest::Unit::TestCase
|
@@ -2,42 +2,52 @@ require 'sqlite3'
|
|
2
2
|
|
3
3
|
module MiniTest
|
4
4
|
module Perf
|
5
|
-
|
6
|
-
|
7
|
-
def write(test)
|
8
|
-
db.execute <<-SQL, [test.run.to_s, test.suite, test.name, test.total]
|
9
|
-
INSERT INTO tests (run, suite, name, total)
|
10
|
-
VALUES (?, ?, ?, ?)
|
11
|
-
SQL
|
12
|
-
end
|
5
|
+
class Persistence
|
6
|
+
attr_reader :database_url
|
13
7
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
end
|
8
|
+
def initialize(database_url = Perf.database_url)
|
9
|
+
@database_url = database_url
|
10
|
+
end
|
19
11
|
|
20
|
-
|
21
|
-
|
22
|
-
|
12
|
+
def write(test)
|
13
|
+
db.execute <<-SQL, [test.run.to_s, test.suite, test.name, test.total]
|
14
|
+
INSERT INTO tests (run, suite, name, total)
|
15
|
+
VALUES (?, ?, ?, ?)
|
16
|
+
SQL
|
17
|
+
end
|
23
18
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
@@db ||= begin
|
28
|
-
db = SQLite3::Database.new ".minitest-perf.db"
|
29
|
-
db.execute <<-SQL
|
30
|
-
create table if not exists tests (
|
31
|
-
run varchar(255),
|
32
|
-
suite varchar(255),
|
33
|
-
name varchar(255),
|
34
|
-
total float
|
35
|
-
);
|
36
|
-
SQL
|
37
|
-
db
|
38
|
-
end
|
19
|
+
def read_tests
|
20
|
+
db.execute("SELECT * FROM TESTS").map do |run, suite, name, total|
|
21
|
+
Test.new(run, suite, name, total)
|
39
22
|
end
|
40
23
|
end
|
24
|
+
|
25
|
+
def sql(query)
|
26
|
+
db.execute query
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def db
|
32
|
+
@db ||= begin
|
33
|
+
db = SQLite3::Database.new sqlite3_db_name
|
34
|
+
db.execute <<-SQL
|
35
|
+
create table if not exists tests (
|
36
|
+
run varchar(255),
|
37
|
+
suite varchar(255),
|
38
|
+
name varchar(255),
|
39
|
+
total float
|
40
|
+
);
|
41
|
+
SQL
|
42
|
+
db
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
##
|
47
|
+
# Use a simple regexp, because for now, only sqlite3 is supported.
|
48
|
+
def sqlite3_db_name
|
49
|
+
@database_url.scan(/sqlite3:\/\/localhost\/(.+)/)[0][0]
|
50
|
+
end
|
41
51
|
end
|
42
52
|
end
|
43
53
|
end
|
data/lib/minitest/perf/test.rb
CHANGED
@@ -3,19 +3,26 @@ require 'sqlite3'
|
|
3
3
|
|
4
4
|
module MiniTest::Perf
|
5
5
|
class PersistenceTest < MiniTest::Unit::TestCase
|
6
|
+
TEST_DB_FILE = '.minitest-perf-tests.db'
|
6
7
|
def setup
|
7
|
-
|
8
|
-
Persistence.
|
8
|
+
File.delete(TEST_DB_FILE) rescue Errno::ENOENT # First time won't be here
|
9
|
+
@persistence = Persistence.new("sqlite3://localhost/#{TEST_DB_FILE}")
|
10
|
+
@persistence.sql "delete from tests"
|
9
11
|
end
|
10
12
|
|
11
13
|
def test_exposes_a_sql_interface
|
12
|
-
assert_instance_of Array,
|
14
|
+
assert_instance_of Array, @persistence.sql('select * from tests')
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_really_creates_a_sqlite_db_file
|
18
|
+
db = SQLite3::Database.new TEST_DB_FILE
|
19
|
+
assert_instance_of Array, db.execute('select * from tests')
|
13
20
|
end
|
14
21
|
|
15
22
|
def test_stores_the_test_as_a_new_row
|
16
|
-
|
23
|
+
@persistence.write(Test.new('run', 'suite', 'name', 10))
|
17
24
|
|
18
|
-
result =
|
25
|
+
result = @persistence.sql "SELECT * FROM tests"
|
19
26
|
|
20
27
|
assert_equal 1, result.size
|
21
28
|
|
@@ -26,5 +33,9 @@ module MiniTest::Perf
|
|
26
33
|
assert_equal 'name', name
|
27
34
|
assert_equal 10, total
|
28
35
|
end
|
36
|
+
|
37
|
+
def test_uses_the_database_from_the_database_url
|
38
|
+
assert_equal 'sqlite3://localhost/.minitest-perf-tests.db', @persistence.database_url
|
39
|
+
end
|
29
40
|
end
|
30
41
|
end
|
data/test/perf/test_test.rb
CHANGED
data/test/perf_test.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module MiniTest
|
4
|
+
class PerfTest < MiniTest::Unit::TestCase
|
5
|
+
def test_default_database
|
6
|
+
MiniTest::Perf.database_url = nil
|
7
|
+
|
8
|
+
assert_equal 'sqlite3://localhost/.minitest-perf.db', MiniTest::Perf.database_url
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_customizable_database
|
12
|
+
MiniTest::Perf.persistence = nil
|
13
|
+
MiniTest::Perf.database_url = 'sqlite3://localhost/some_other_file.db'
|
14
|
+
|
15
|
+
assert_equal 'sqlite3://localhost/some_other_file.db', MiniTest::Perf.database_url
|
16
|
+
assert_equal 'sqlite3://localhost/some_other_file.db', MiniTest::Perf.persistence.database_url
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: minitest-perf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Albert Llop
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -135,6 +135,7 @@ files:
|
|
135
135
|
- test/perf/plugin_test.rb
|
136
136
|
- test/perf/run_test.rb
|
137
137
|
- test/perf/test_test.rb
|
138
|
+
- test/perf_test.rb
|
138
139
|
- test/test_helper.rb
|
139
140
|
homepage: https://github.com/mrsimo/minitest-perf
|
140
141
|
licenses:
|
@@ -168,4 +169,5 @@ test_files:
|
|
168
169
|
- test/perf/plugin_test.rb
|
169
170
|
- test/perf/run_test.rb
|
170
171
|
- test/perf/test_test.rb
|
172
|
+
- test/perf_test.rb
|
171
173
|
- test/test_helper.rb
|