coverband 4.2.4 → 4.2.7.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.jrubyrc +1 -0
- data/.rubocop.yml +8 -2
- data/.travis.yml +25 -5
- data/Gemfile +10 -0
- data/Gemfile.rails6 +10 -0
- data/README.md +62 -11
- data/Rakefile +7 -3
- data/changes.md +12 -7
- data/coverband.gemspec +2 -6
- data/lib/alternative_coverband_patch.rb +5 -0
- data/lib/coverband.rb +1 -0
- data/lib/coverband/collectors/coverage.rb +10 -5
- data/lib/coverband/collectors/delta.rb +8 -2
- data/lib/coverband/collectors/view_tracker.rb +9 -1
- data/lib/coverband/configuration.rb +4 -4
- data/lib/coverband/integrations/resque.rb +13 -1
- data/lib/coverband/reporters/web.rb +3 -2
- data/lib/coverband/utils/jruby_ext.rb +19 -0
- data/lib/coverband/version.rb +1 -1
- data/test/benchmarks/benchmark.rake +2 -2
- data/test/big_dog.rb.erb +12 -0
- data/test/coverband/collectors/delta_test.rb +15 -0
- data/test/coverband/configuration_test.rb +12 -12
- data/test/coverband/integrations/resque_worker_test.rb +8 -2
- data/test/coverband/reporters/web_test.rb +6 -0
- data/test/dog.rb.erb +0 -5
- data/test/jruby_check.rb +14 -0
- data/test/rails6_dummy/Rakefile +6 -0
- data/test/rails6_dummy/app/controllers/dummy_controller.rb +5 -0
- data/test/rails6_dummy/config.ru +4 -0
- data/test/rails6_dummy/config/application.rb +14 -0
- data/test/rails6_dummy/config/boot.rb +3 -0
- data/test/rails6_dummy/config/coverband.rb +3 -0
- data/test/rails6_dummy/config/coverband_missing_redis.rb +3 -0
- data/test/rails6_dummy/config/environment.rb +5 -0
- data/test/rails6_dummy/config/routes.rb +4 -0
- data/test/rails6_dummy/config/secrets.yml +3 -0
- data/test/rails6_dummy/tmp/.keep +0 -0
- data/test/test_helper.rb +1 -1
- data/test/unique_files.rb +6 -0
- metadata +36 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68ea5d4222b92fe692d530b929c52d6da5b1c01d710f06bf92d53ea5515e6cba
|
4
|
+
data.tar.gz: 29eb1a2764bd507c7da2376e8566270f581f16ff22d79cb645a5075f59ccdda0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '07931a21e9b83879d81936059173ea3c5c64671d2fafddefa7d0cee8aca02b319352a6ea3cf8786322977581a37a52be95775091bab9367265d4d82502ad5fcf'
|
7
|
+
data.tar.gz: 9d77db00ad0f025b620969840747b7c3774d636ea23c0caf47789a06c1e2c72762a5a2aee53c73c4602840504eacd1d47f6261938b652ef7ed055882cf463869
|
data/.jrubyrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
debug.fullTrace=true
|
data/.rubocop.yml
CHANGED
@@ -3,11 +3,11 @@ AllCops:
|
|
3
3
|
Exclude:
|
4
4
|
- vendor/bundle/**/*
|
5
5
|
- docs/**/*
|
6
|
-
- test/
|
6
|
+
- test/rails6_dummy/**/*
|
7
7
|
- test/rails5_dummy/**/*
|
8
8
|
- test/fixtures/**/*
|
9
9
|
# Get the code passing first then we will enable for tests
|
10
|
-
- test/**/*
|
10
|
+
- test/**/*
|
11
11
|
Documentation:
|
12
12
|
Enabled: false
|
13
13
|
Metrics/MethodLength:
|
@@ -46,6 +46,10 @@ Style/ClassVars:
|
|
46
46
|
Enabled: false
|
47
47
|
Style/MultilineBlockChain:
|
48
48
|
Enabled: false
|
49
|
+
Style/StringLiterals:
|
50
|
+
Enabled: false
|
51
|
+
Style/IfInsideElse:
|
52
|
+
Enabled: false
|
49
53
|
Style/FrozenStringLiteralComment:
|
50
54
|
Enabled: true
|
51
55
|
Style/GuardClause:
|
@@ -58,6 +62,8 @@ Style/NumericLiteralPrefix:
|
|
58
62
|
Enabled: false
|
59
63
|
Style/ClassAndModuleChildren:
|
60
64
|
Enabled: false
|
65
|
+
Style/SymbolArray:
|
66
|
+
Enabled: false
|
61
67
|
Style/SymbolProc:
|
62
68
|
Enabled: false
|
63
69
|
Style/RegexpLiteral:
|
data/.travis.yml
CHANGED
@@ -4,17 +4,37 @@ rvm:
|
|
4
4
|
- "2.4"
|
5
5
|
- "2.5"
|
6
6
|
- "2.6.1"
|
7
|
-
|
8
|
-
|
9
|
-
directories:
|
10
|
-
- $HOME/lua51
|
7
|
+
- "2.7"
|
8
|
+
- jruby-9.2.6.0
|
11
9
|
gemfile:
|
12
10
|
- Gemfile
|
13
11
|
- Gemfile.rails4
|
12
|
+
- Gemfile.rails6
|
13
|
+
env:
|
14
|
+
global:
|
15
|
+
# --dev improves JRuby startup time
|
16
|
+
# See https://github.com/jruby/jruby/wiki/Improving-startup-time
|
17
|
+
- JRUBY_OPTS="--dev"
|
18
|
+
|
19
|
+
jobs:
|
20
|
+
exclude:
|
21
|
+
- rvm: "2.3"
|
22
|
+
gemfile: Gemfile.rails6
|
23
|
+
- rvm: "2.4"
|
24
|
+
gemfile: Gemfile.rails6
|
25
|
+
- rvm: "2.7"
|
26
|
+
gemfile: Gemfile.rails4
|
27
|
+
- rvm: jruby-9.2.6.0
|
28
|
+
gemfile: Gemfile.rails4
|
29
|
+
|
30
|
+
cache:
|
31
|
+
bundler: true
|
32
|
+
directories:
|
33
|
+
- $HOME/lua51
|
14
34
|
services:
|
15
35
|
- redis-server
|
16
36
|
script:
|
17
|
-
- sudo ./lua/install.sh
|
37
|
+
- sudo ./lua/install.sh
|
18
38
|
- $HOME/lua51/bin/busted lua/test/*
|
19
39
|
- bundle exec rake rubocop
|
20
40
|
- COVERBAND_HASH_REDIS_STORE=t bundle exec rake
|
data/Gemfile
CHANGED
@@ -4,6 +4,16 @@ source 'https://rubygems.org'
|
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in coverband.gemspec
|
6
6
|
gemspec
|
7
|
+
|
8
|
+
# add when debugging
|
9
|
+
# require 'byebug'; byebug
|
10
|
+
if ENV['CI']
|
11
|
+
# skipping pry-byebug as it has issues on Ruby 2.3 on travis
|
12
|
+
# and we don't really need it on CI
|
13
|
+
else
|
14
|
+
gem 'pry-byebug', platforms: [:mri, :mingw, :x64_mingw]
|
15
|
+
end
|
16
|
+
|
7
17
|
gem 'rails', '~>5'
|
8
18
|
# these gems are used for testing gem tracking
|
9
19
|
gem 'irb', require: false
|
data/Gemfile.rails6
ADDED
data/README.md
CHANGED
@@ -7,7 +7,6 @@
|
|
7
7
|
[![Maintainability](https://api.codeclimate.com/v1/badges/1e6682f9540d75f26da7/maintainability)](https://codeclimate.com/github/danmayer/coverband/maintainability)
|
8
8
|
[![Discord Shield](https://img.shields.io/discord/609509533999562753)](https://discord.gg/KAH38EV)
|
9
9
|
|
10
|
-
|
11
10
|
<p align="center">
|
12
11
|
<a href="#key-features">Key Features</a> •
|
13
12
|
<a href="#installation">Installation</a> •
|
@@ -116,6 +115,17 @@ The web endpoint is a barebones endpoint that you can either expose direct (afte
|
|
116
115
|
- View individual file details
|
117
116
|
- **clear individual file coverage:** This will clear the details of the file you are looking at. This is helpful if you don't want to lose all Coverage data but made a change that you expect would impact a particular file.
|
118
117
|
|
118
|
+
### JRuby Support
|
119
|
+
|
120
|
+
Coverband is compatible with JRuby. If you want to run on JRuby note that I haven't benchmarked and I believe the perf impact on oldre versions of JRuby could be significant, improved Coverage support is in [JRuby master](https://github.com/jruby/jruby/pull/6180), and will be in the next release.
|
121
|
+
|
122
|
+
* older versions of JRuby need tracing enabled to work (and this could cause bad performance)
|
123
|
+
* run Jruby with the `--debug` option
|
124
|
+
* add into your `.jrubyrc` the `debug.fullTrace=true` setting
|
125
|
+
* For best performance the `oneshot_lines` is recommended, and in the latest releases should have very low overhead
|
126
|
+
* See JRuby support in a Rails app configured to run via JRuby, in [Coverband Demo](https://github.com/coverband-service/coverband_demo)
|
127
|
+
* JRuby is tested via CI against Rails 5 and 6
|
128
|
+
|
119
129
|
### Rake Tasks
|
120
130
|
|
121
131
|
The rake task generates a report locally and opens a browser pointing to `coverage/index.html`.
|
@@ -182,7 +192,7 @@ end
|
|
182
192
|
|
183
193
|
### Working with environment variables
|
184
194
|
|
185
|
-
Do you use figaro, mc-settings, dotenv or something else to inject environment variables into your app? If so ensure you have that done BEFORE coverband is required.
|
195
|
+
Do you use figaro, mc-settings, dotenv or something else to inject environment variables into your app? If so ensure you have that done BEFORE coverband is required.
|
186
196
|
|
187
197
|
For example if you use dotenv, you need to do this, see https://github.com/bkeepers/dotenv#note-on-load-order
|
188
198
|
|
@@ -206,6 +216,8 @@ config.ignore += ['config/application.rb',
|
|
206
216
|
'lib/tasks/*']
|
207
217
|
```
|
208
218
|
|
219
|
+
**Ignoring Custom Gem Locations:** Note, if you have your gems in a custom location under your app folder you likely want to add them to `config.ignore`. For example, if you have your gems not in a default ignored location of `app/vendor` but have them in `app/gems` you would need to add `gems/*` to your ignore list.
|
220
|
+
|
209
221
|
### View Tracking
|
210
222
|
|
211
223
|
Coverband allows an optional feature to track all view files that are used by an application.
|
@@ -237,9 +249,32 @@ ENV['AWS_ACCESS_KEY_ID']
|
|
237
249
|
ENV['AWS_SECRET_ACCESS_KEY']
|
238
250
|
```
|
239
251
|
|
252
|
+
### Fixing Coverage Only Shows Loading Hits
|
253
|
+
|
254
|
+
If all your coverage is being counted as loading or eager_loading coverage, and nothing is showing as runtime Coverage the initialization hook failed for some reason. The most likely reason for this issue is manually calling `eager_load!` on some Plugin/Gem. If you or a plugin is altering the Rails initialization process, you can manually flip Coverband to runtime coverage by calling these two lines, in an `after_initialize` block, in `application.rb`.
|
255
|
+
|
256
|
+
```ruby
|
257
|
+
config.after_initialize do
|
258
|
+
unless Coverband.tasks_to_ignore?
|
259
|
+
Coverband.report_coverage # record the last of the loading coverage
|
260
|
+
Coverband.runtime_coverage! # set all future coverage to runtime
|
261
|
+
end
|
262
|
+
end
|
263
|
+
```
|
264
|
+
|
265
|
+
or if you know you are manually calling eager load anywhere in your initialization process immediately adfter call those two lines. A user reported an issue after calling `ResqueWeb::Engine.eager_load!` for example.
|
266
|
+
|
267
|
+
```ruby
|
268
|
+
Rails.application.routes.draw do
|
269
|
+
ResqueWeb::Engine.eager_load!
|
270
|
+
Coverband.report_coverage
|
271
|
+
Coverband.runtime_coverage!
|
272
|
+
end
|
273
|
+
```
|
274
|
+
|
240
275
|
### Avoiding Cache Stampede
|
241
276
|
|
242
|
-
If you have many servers and they all hit Redis at the same time you can see spikes in your Redis CPU, and memory. This is do to a concept called [cache stampede](https://en.wikipedia.org/wiki/Cache_stampede). It is better to spread out the reporting across your servers. A simple way to do this is to add a random wiggle on your background reporting. This configuration option allows a wiggle. The right amount of wiggle depends on the numbers of servers you have and how willing you are to have delays in your coverage reporting. I would recommend at least 1 second per server.
|
277
|
+
If you have many servers and they all hit Redis at the same time you can see spikes in your Redis CPU, and memory. This is do to a concept called [cache stampede](https://en.wikipedia.org/wiki/Cache_stampede). It is better to spread out the reporting across your servers. A simple way to do this is to add a random wiggle on your background reporting. This configuration option allows a wiggle. The right amount of wiggle depends on the numbers of servers you have and how willing you are to have delays in your coverage reporting. I would recommend at least 1 second per server.
|
243
278
|
|
244
279
|
Add a wiggle (in seconds) to the background thread to avoid all your servers reporting at the same time:
|
245
280
|
|
@@ -247,11 +282,11 @@ Add a wiggle (in seconds) to the background thread to avoid all your servers rep
|
|
247
282
|
|
248
283
|
### Redis Hash Store
|
249
284
|
|
250
|
-
Coverband on very high volume sites with many server processes reporting can have a race condition. To resolve the race condition and reduce Ruby memory overhead we have introduced a new Redis storage option. This moves the some of the work from the Ruby processes to Redis. It is worth noting because of this, it has a larger demands on the Redis server. So adjust your Redis instance accordingly. To help reduce the extra redis load you can also change the background reporting time period.
|
285
|
+
Coverband on very high volume sites with many server processes reporting can have a race condition. To resolve the race condition and reduce Ruby memory overhead we have introduced a new Redis storage option. This moves the some of the work from the Ruby processes to Redis. It is worth noting because of this, it has a larger demands on the Redis server. So adjust your Redis instance accordingly. To help reduce the extra redis load you can also change the background reporting time period.
|
251
286
|
|
252
|
-
|
253
|
-
|
254
|
-
|
287
|
+
- set the new Redis store: `config.store = Coverband::Adapters::HashRedisStore.new(Redis.new(url: redis_url))`
|
288
|
+
- adjust from default 30s reporting `config.background_reporting_sleep_seconds = 120`
|
289
|
+
- reminder it is recommended to have a unique Redis per workload (background jobs, caching, Coverband), for this store, it may be more important to have a dedicated Redis.
|
255
290
|
|
256
291
|
### Clear Coverage
|
257
292
|
|
@@ -289,7 +324,7 @@ rake coverband:coverage # report runtime coverband code coverage
|
|
289
324
|
|
290
325
|
### Collecting Gem / Library Usage
|
291
326
|
|
292
|
-
|
327
|
+
**WARNING:** Gem Tracking is still in experimental stages and not recommended for production. We have some performance issues when view reports on large applications. Gem tracing also during background thread data collection has HIGH memory requirements, during report merging (seemingly around 128mb of extra memory, which is crazy). We recommend deploying WITHOUT `track_gems` first and only enabling it after confirming that Coverband is working and performing well.
|
293
328
|
|
294
329
|
Gem usage can be tracked by enabling the `track_gems` config.
|
295
330
|
|
@@ -346,6 +381,22 @@ Note: To debug issues getting Coverband working. I recommend running in developm
|
|
346
381
|
|
347
382
|
If you are trying to debug locally wondering what code is being run during a request. The verbose modes `config.verbose = true` && `Rails.logger.level = :debug`. With true set it will output the number of lines executed per file, to the passed in log.
|
348
383
|
|
384
|
+
### Solving: stack level too deep errors
|
385
|
+
|
386
|
+
If you start seeing SystemStackError: stack level too deep errors from background jobs after installing Coverband, this means there is another patch for ResqueWorker that conflicts with Coverband's patch in your application. To fix this, change coverband gem line in your Gemfile to the following:
|
387
|
+
|
388
|
+
```
|
389
|
+
gem 'coverband', require: ['alternative_coverband_patch', 'coverband']
|
390
|
+
```
|
391
|
+
|
392
|
+
If you currently have require: false, remove the 'coverband' string from the require array above so the gem line becomes like this:
|
393
|
+
|
394
|
+
```
|
395
|
+
gem 'coverband', require: ['alternative_coverband_patch']
|
396
|
+
```
|
397
|
+
|
398
|
+
This conflict happens when a ruby method is patched twice, once using module prepend, and once using method aliasing. See this ruby issue for details. The fix is to apply all patches the same way. Coverband by default will apply its patch using prepend, but you can change that to method aliasing by adding require: ['alternative_coverband_patch'] to the gem line as shown above.
|
399
|
+
|
349
400
|
# Prerequisites
|
350
401
|
|
351
402
|
- Coverband 3.0.X+ requires Ruby 2.3+
|
@@ -353,7 +404,7 @@ If you are trying to debug locally wondering what code is being run during a req
|
|
353
404
|
|
354
405
|
### Ruby and Rails Version Support
|
355
406
|
|
356
|
-
We will match Heroku & Ruby's support lifetime, supporting the last 3 major Ruby releases. For details see [supported runtimes](https://devcenter.heroku.com/articles/ruby-support#supported-runtimes).
|
407
|
+
We will match Heroku & Ruby's support lifetime, supporting the last 3 major Ruby releases. For details see [supported runtimes](https://devcenter.heroku.com/articles/ruby-support#supported-runtimes).
|
357
408
|
|
358
409
|
For Rails, we will follow the policy of the [Rails team maintenance policy](https://guides.rubyonrails.org/maintenance_policy.html). We officially support the last two major release versions, while providing minimal support (major bugs / security fixes) for an additional version. This means at the moment we primaryly target Rails 6.x, 5.x, and will try to keep current functionality working for Rails 4.x but may release new features that do not work on that target.
|
359
410
|
|
@@ -374,7 +425,7 @@ If you submit a change please make sure the tests and benchmarks are passing.
|
|
374
425
|
|
375
426
|
- run tests:
|
376
427
|
- `bundle exec rake`
|
377
|
-
- `BUNDLE_GEMFILE=Gemfile.
|
428
|
+
- `BUNDLE_GEMFILE=Gemfile.rails6 bundle exec rake` (Same tests using rails 6 instead of 5)
|
378
429
|
- view test coverage: `open coverage/index.html`
|
379
430
|
- run the benchmarks before and after your change to see impact
|
380
431
|
- `rake benchmarks`
|
@@ -385,7 +436,7 @@ If you submit a change please make sure the tests and benchmarks are passing.
|
|
385
436
|
- **total fail** on front end code, for line for line coverage, because of the precompiled template step basically coverage doesn't work well for `erb`, `slim`, and the like.
|
386
437
|
- related it will try to report something, but the line numbers reported for `ERB` files are often off and aren't considered useful. I recommend filtering out .erb using the `config.ignore` option. The default configuration excludes these files
|
387
438
|
- **NOTE:** We now have file level coverage for view files, but don't support line level detail
|
388
|
-
- The view file detection doesn't workf or mailers at the moment only for web related views / JSON templates. This is due to how Rails active mailer notifications work.
|
439
|
+
- The view file detection doesn't workf or mailers at the moment only for web related views / JSON templates. This is due to how Rails active mailer notifications work.
|
389
440
|
|
390
441
|
### Debugging Redis Store
|
391
442
|
|
data/Rakefile
CHANGED
@@ -22,9 +22,13 @@ Rake::TestTask.new(:test) do |test|
|
|
22
22
|
end
|
23
23
|
|
24
24
|
Rake::TestTask.new(:forked_tests) do |test|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
if RUBY_PLATFORM == 'java'
|
26
|
+
puts 'forked tests not supported on JRuby'
|
27
|
+
else
|
28
|
+
test.libs << 'lib' << 'test'
|
29
|
+
test.test_files = FileList['test/forked/**/*_test.rb']
|
30
|
+
test.verbose = true
|
31
|
+
end
|
28
32
|
end
|
29
33
|
|
30
34
|
desc 'load irb with this gem'
|
data/changes.md
CHANGED
@@ -76,9 +76,15 @@ Feature Ideas:
|
|
76
76
|
|
77
77
|
# Alpha / Beta / Release Candidates
|
78
78
|
|
79
|
+
### Coverband 4.2.6
|
80
|
+
|
81
|
+
- Address Redis `exists` deprecation warning by baffers
|
82
|
+
|
79
83
|
### Coverband 4.2.5
|
80
84
|
|
81
|
-
-
|
85
|
+
- alpha support of jRuby
|
86
|
+
- fix for rails 4.0 by rswaminathan
|
87
|
+
- do not error on branch coverage / simplecov compatibility by desertcart
|
82
88
|
|
83
89
|
# Released
|
84
90
|
|
@@ -104,19 +110,18 @@ Feature Ideas:
|
|
104
110
|
- improved messaging around non-loaded files
|
105
111
|
- fix on last updated nil issue
|
106
112
|
- view tracker improvements
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
113
|
+
- clear all
|
114
|
+
- reset individual file
|
115
|
+
- timestamps on last seen activity
|
111
116
|
|
112
117
|
### Coverband 4.2.2
|
113
118
|
|
114
119
|
- new experimental hash redis store for high volume collection
|
115
|
-
(hundreds of clients), thanks @kbaum
|
120
|
+
(hundreds of clients), thanks @kbaum
|
116
121
|
- view_tracker supports tracking view layer files like `.html.erb`
|
117
122
|
- documentation improvements, thanks @brossetti1, @jjb, @kbaum
|
118
123
|
- we now have discordapp for discussions, thanks @kbaum,
|
119
|
-
https://discordapp.com/channels/609509533999562753/609509533999562756
|
124
|
+
https://discordapp.com/channels/609509533999562753/609509533999562756
|
120
125
|
- perf fix on Rails initialization, thanks @skangg
|
121
126
|
- simplified logging
|
122
127
|
|
data/coverband.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.version = Coverband::VERSION
|
10
10
|
spec.authors = ['Dan Mayer', 'Karl Baum']
|
11
11
|
spec.email = ['dan@mayerdan.com']
|
12
|
-
spec.description = 'Rack middleware to
|
13
|
-
spec.summary = 'Rack middleware to
|
12
|
+
spec.description = 'Rack middleware to measure production code usage (LOC runtime usage)'
|
13
|
+
spec.summary = 'Rack middleware to measure production code usage (LOC runtime usage)'
|
14
14
|
spec.homepage = 'https://github.com/danmayer/coverband'
|
15
15
|
spec.license = 'MIT'
|
16
16
|
|
@@ -38,10 +38,6 @@ Gem::Specification.new do |spec|
|
|
38
38
|
spec.add_development_dependency 'rubocop-performance'
|
39
39
|
|
40
40
|
spec.add_development_dependency 'coveralls'
|
41
|
-
# add when debugging
|
42
|
-
# require 'byebug'; byebug
|
43
|
-
spec.add_development_dependency 'pry-byebug'
|
44
|
-
|
45
41
|
spec.add_development_dependency 'minitest-profile'
|
46
42
|
|
47
43
|
# TODO: Remove when other production adapters exist
|
data/lib/coverband.rb
CHANGED
@@ -100,6 +100,7 @@ module Coverband
|
|
100
100
|
end
|
101
101
|
unless ENV['COVERBAND_DISABLE_AUTO_START']
|
102
102
|
begin
|
103
|
+
require 'coverband/utils/jruby_ext' if RUBY_PLATFORM == 'java'
|
103
104
|
# Coverband should be setup as early as possible
|
104
105
|
# to capture usage of things loaded by initializers or other Rails engines
|
105
106
|
configure
|
@@ -89,12 +89,17 @@ module Coverband
|
|
89
89
|
raise NotImplementedError, 'Coverage needs Ruby > 2.3.0' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.3.0')
|
90
90
|
|
91
91
|
require 'coverage'
|
92
|
-
if
|
93
|
-
|
94
|
-
|
95
|
-
::Coverage.start unless ::Coverage.running?
|
92
|
+
if defined?(SimpleCov) && defined?(Rails) && defined?(Rails.env) && Rails.env.test?
|
93
|
+
puts "Coverband: detected SimpleCov in test Env, allowing it to start Coverage"
|
94
|
+
puts "Coverband: to ensure no error logs or missing Coverage call `SimpleCov.start` prior to requiring Coverband"
|
96
95
|
else
|
97
|
-
|
96
|
+
if Coverage.ruby_version_greater_than_or_equal_to?('2.6.0')
|
97
|
+
::Coverage.start(oneshot_lines: Coverband.configuration.use_oneshot_lines_coverage) unless ::Coverage.running?
|
98
|
+
elsif Coverage.ruby_version_greater_than_or_equal_to?('2.5.0')
|
99
|
+
::Coverage.start unless ::Coverage.running?
|
100
|
+
else
|
101
|
+
::Coverage.start
|
102
|
+
end
|
98
103
|
end
|
99
104
|
reset_instance
|
100
105
|
end
|
@@ -44,11 +44,17 @@ module Coverband
|
|
44
44
|
private
|
45
45
|
|
46
46
|
def generate
|
47
|
+
# TODO: if we filtered before doing this we would avoid calculating the line diff on a ton of files
|
48
|
+
# This would be a fairly noticeable perf win
|
47
49
|
current_coverage.each_with_object({}) do |(file, line_counts), new_results|
|
50
|
+
# This handles Coverage branch support, setup by default in
|
51
|
+
# simplecov 0.18.x
|
52
|
+
arr_line_counts = line_counts.is_a?(Hash) ? line_counts[:lines] : line_counts
|
48
53
|
new_results[file] = if @@previous_coverage && @@previous_coverage[file]
|
49
|
-
|
54
|
+
prev_line_counts = @@previous_coverage[file].is_a?(Hash) ? @@previous_coverage[file][:lines] : @@previous_coverage[file]
|
55
|
+
array_diff(arr_line_counts, prev_line_counts)
|
50
56
|
else
|
51
|
-
|
57
|
+
arr_line_counts
|
52
58
|
end
|
53
59
|
end
|
54
60
|
end
|
@@ -108,7 +108,7 @@ module Coverband
|
|
108
108
|
end
|
109
109
|
|
110
110
|
def report_views_tracked
|
111
|
-
redis_store.set(tracker_time_key, Time.now.to_i) unless @one_time_timestamp ||
|
111
|
+
redis_store.set(tracker_time_key, Time.now.to_i) unless @one_time_timestamp || tracker_time_key_exists?
|
112
112
|
@one_time_timestamp = true
|
113
113
|
reported_time = Time.now.to_i
|
114
114
|
views_to_record.each do |file|
|
@@ -145,6 +145,14 @@ module Coverband
|
|
145
145
|
store.raw_store
|
146
146
|
end
|
147
147
|
|
148
|
+
def tracker_time_key_exists?
|
149
|
+
if defined?(redis_store.exists?)
|
150
|
+
redis_store.exists?(tracker_time_key)
|
151
|
+
else
|
152
|
+
redis_store.exists(tracker_time_key)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
148
156
|
def tracker_key
|
149
157
|
'render_tracker_2'
|
150
158
|
end
|
@@ -40,7 +40,7 @@ module Coverband
|
|
40
40
|
# Heroku when building assets runs code from a dynamic directory
|
41
41
|
# /tmp was added to avoid coverage from /tmp/build directories during
|
42
42
|
# heroku asset compilation
|
43
|
-
IGNORE_DEFAULTS = %w[vendor/ .erb$ .slim$ /tmp internal:prelude schema.rb]
|
43
|
+
IGNORE_DEFAULTS = %w[vendor/ .erb$ .slim$ /tmp internal:prelude db/schema.rb]
|
44
44
|
|
45
45
|
# Add in missing files which were never loaded
|
46
46
|
# we need to know what all paths to check for unloaded files
|
@@ -54,7 +54,7 @@ module Coverband
|
|
54
54
|
@root = Dir.pwd
|
55
55
|
@root_paths = []
|
56
56
|
@ignore = IGNORE_DEFAULTS.dup
|
57
|
-
@
|
57
|
+
@search_paths = TRACKED_DEFAULT_PATHS.dup
|
58
58
|
@additional_files = []
|
59
59
|
@verbose = false
|
60
60
|
@reporter = 'scov'
|
@@ -134,14 +134,14 @@ module Coverband
|
|
134
134
|
# Search Paths
|
135
135
|
###
|
136
136
|
def tracked_search_paths
|
137
|
-
"#{Coverband.configuration.current_root}/{#{@
|
137
|
+
"#{Coverband.configuration.current_root}/{#{@search_paths.join(',')}}/**/*.{rb}"
|
138
138
|
end
|
139
139
|
|
140
140
|
###
|
141
141
|
# Don't allow the to override defaults
|
142
142
|
###
|
143
143
|
def search_paths=(path_array)
|
144
|
-
@
|
144
|
+
@search_paths = (@search_paths + path_array).uniq
|
145
145
|
end
|
146
146
|
|
147
147
|
###
|
@@ -22,4 +22,16 @@ module Coverband
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
|
25
|
+
if defined?(Coverband::COVERBAND_ALTERNATE_PATCH)
|
26
|
+
Resque::Job.class_eval do
|
27
|
+
def perform_with_coverband
|
28
|
+
perform_without_coverband
|
29
|
+
ensure
|
30
|
+
Coverband.report_coverage
|
31
|
+
end
|
32
|
+
alias_method perform_without_coverband perform
|
33
|
+
alias_method perform perform_with_coverband
|
34
|
+
end
|
35
|
+
else
|
36
|
+
Resque::Job.prepend(Coverband::ResqueWorker)
|
37
|
+
end
|
@@ -32,8 +32,9 @@ module Coverband
|
|
32
32
|
|
33
33
|
return [401, { 'www-authenticate' => 'Basic realm=""' }, ['']] unless check_auth
|
34
34
|
|
35
|
+
request_path_info = (request.path_info == '') ? '/' : request.path_info
|
35
36
|
if request.post?
|
36
|
-
case
|
37
|
+
case request_path_info
|
37
38
|
when %r{\/clear_view_tracking_file}
|
38
39
|
clear_view_tracking_file
|
39
40
|
when %r{\/clear_view_tracking}
|
@@ -46,7 +47,7 @@ module Coverband
|
|
46
47
|
[404, { 'Content-Type' => 'text/html' }, ['404 error!']]
|
47
48
|
end
|
48
49
|
else
|
49
|
-
case
|
50
|
+
case request_path_info
|
50
51
|
when /.*\.(css|js|gif|png)/
|
51
52
|
@static.call(env)
|
52
53
|
when %r{\/settings}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
####
|
4
|
+
# This exists in CRuby, but not in JRuby, so add it
|
5
|
+
#
|
6
|
+
# Taken from: https://github.com/ruby/ruby/blob/c5eb24349a4535948514fe765c3ddb0628d81004/ext/coverage/lib/coverage.rb
|
7
|
+
####
|
8
|
+
module Coverage
|
9
|
+
def self.line_stub(file)
|
10
|
+
lines = File.foreach(file).map { nil }
|
11
|
+
iseqs = [RubyVM::InstructionSequence.compile_file(file)]
|
12
|
+
until iseqs.empty?
|
13
|
+
iseq = iseqs.pop
|
14
|
+
iseq.trace_points.each { |n, type| lines[n - 1] = 0 if type == :line }
|
15
|
+
iseq.each_child { |child| iseqs << child }
|
16
|
+
end
|
17
|
+
lines
|
18
|
+
end
|
19
|
+
end
|
data/lib/coverband/version.rb
CHANGED
@@ -247,7 +247,7 @@ namespace :benchmarks do
|
|
247
247
|
|
248
248
|
desc 'checks memory of collector'
|
249
249
|
task memory_check: [:setup] do
|
250
|
-
require 'pry-byebug'
|
250
|
+
# require 'pry-byebug'
|
251
251
|
require 'objspace'
|
252
252
|
puts 'memory load check'
|
253
253
|
puts(ObjectSpace.memsize_of_all / 2**20)
|
@@ -337,7 +337,7 @@ namespace :benchmarks do
|
|
337
337
|
require 'memory_profiler'
|
338
338
|
require './test/unique_files'
|
339
339
|
|
340
|
-
4000.times { |index| require_unique_file('
|
340
|
+
4000.times { |index| require_unique_file('big_dog.rb.erb', dog_number: index) }
|
341
341
|
# warmup
|
342
342
|
3.times { Coverband.report_coverage }
|
343
343
|
dogs = 400.times.map { |index| Object.const_get("Dog#{index}") }
|
data/test/big_dog.rb.erb
ADDED
@@ -49,6 +49,21 @@ class CollectorsDeltaTest < Minitest::Test
|
|
49
49
|
assert_equal(current_coverage, results)
|
50
50
|
end
|
51
51
|
|
52
|
+
test 'Coverage has branching enabled and has gone up' do
|
53
|
+
current_coverage = {
|
54
|
+
'car.rb' => { lines: [nil, 1, 5, 1] }
|
55
|
+
}
|
56
|
+
::Coverage.expects(:peek_result).returns(current_coverage)
|
57
|
+
results = Coverband::Collectors::Delta.results
|
58
|
+
|
59
|
+
current_coverage = {
|
60
|
+
'car.rb' => { lines: [nil, 1, 7, 1] }
|
61
|
+
}
|
62
|
+
::Coverage.expects(:peek_result).returns(current_coverage)
|
63
|
+
results = Coverband::Collectors::Delta.results
|
64
|
+
assert_equal({ 'car.rb' => [nil, 0, 2, 0] }, results)
|
65
|
+
end
|
66
|
+
|
52
67
|
if Coverband.configuration.one_shot_coverage_implemented_in_ruby_version?
|
53
68
|
test 'oneshot coverage calls clear' do
|
54
69
|
Coverband.configuration.stubs(:use_oneshot_lines_coverage).returns(true)
|
@@ -16,9 +16,9 @@ class BaseTest < Minitest::Test
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
test
|
20
|
-
|
21
|
-
expected = [
|
19
|
+
test "ignore works with equal" do
|
20
|
+
Coverband::Collectors::Coverage.instance.reset_instance
|
21
|
+
expected = ["vendor/", ".erb$", ".slim$", "/tmp", "internal:prelude", "db/schema.rb", "config/envionments"]
|
22
22
|
assert_equal expected, Coverband.configuration.ignore
|
23
23
|
end
|
24
24
|
|
@@ -26,15 +26,15 @@ class BaseTest < Minitest::Test
|
|
26
26
|
Coverband.configure do |config|
|
27
27
|
config.ignore += ['config/initializers']
|
28
28
|
end
|
29
|
-
|
30
|
-
expected = [
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
29
|
+
Coverband::Collectors::Coverage.instance.reset_instance
|
30
|
+
expected = ["vendor/",
|
31
|
+
".erb$",
|
32
|
+
".slim$",
|
33
|
+
"/tmp",
|
34
|
+
"internal:prelude",
|
35
|
+
"db/schema.rb",
|
36
|
+
"config/envionments",
|
37
|
+
"config/initializers"]
|
38
38
|
assert_equal expected, Coverband.configuration.ignore
|
39
39
|
end
|
40
40
|
|
@@ -35,7 +35,13 @@ class ResqueWorkerTest < Minitest::Test
|
|
35
35
|
Coverband.runtime_coverage!
|
36
36
|
report = Coverband.configuration.store.get_coverage_report
|
37
37
|
|
38
|
-
|
39
|
-
|
38
|
+
if RUBY_PLATFORM == 'java'
|
39
|
+
# NOTE: the todo test only issue seems to be slightly different in JRuby
|
40
|
+
# were nothing is showing up as runtime Coverage... This appears to be a test only issue
|
41
|
+
assert_equal 1, report[Coverband::EAGER_TYPE][relative_job_file]['data'][6]
|
42
|
+
else
|
43
|
+
assert_equal 0, report[Coverband::EAGER_TYPE][relative_job_file]['data'][6]
|
44
|
+
assert_equal 1, report[Coverband::RUNTIME_TYPE][relative_job_file]['data'][6]
|
45
|
+
end
|
40
46
|
end
|
41
47
|
end
|
@@ -27,6 +27,12 @@ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.2.0')
|
|
27
27
|
assert_match 'Coverband Admin', last_response.body
|
28
28
|
end
|
29
29
|
|
30
|
+
test 'renders index content for empty path' do
|
31
|
+
get ''
|
32
|
+
assert last_response.ok?
|
33
|
+
assert_match 'Coverband Admin', last_response.body
|
34
|
+
end
|
35
|
+
|
30
36
|
test 'renders 404' do
|
31
37
|
get '/show'
|
32
38
|
assert last_response.not_found?
|
data/test/dog.rb.erb
CHANGED
data/test/jruby_check.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path('boot', __dir__)
|
4
|
+
|
5
|
+
require 'rails'
|
6
|
+
require 'action_controller/railtie'
|
7
|
+
require 'coverband'
|
8
|
+
Bundler.require(*Rails.groups)
|
9
|
+
|
10
|
+
module Rails6Dummy
|
11
|
+
class Application < Rails::Application
|
12
|
+
config.eager_load = true
|
13
|
+
end
|
14
|
+
end
|
File without changes
|
data/test/test_helper.rb
CHANGED
@@ -15,7 +15,7 @@ require 'ostruct'
|
|
15
15
|
require 'json'
|
16
16
|
require 'redis'
|
17
17
|
require 'resque'
|
18
|
-
require 'pry-byebug'
|
18
|
+
# require 'pry-byebug' unless ENV['CI'] # Ruby 2.3 on CI crashes on pry & JRuby doesn't support it
|
19
19
|
require_relative 'unique_files'
|
20
20
|
$VERBOSE = original_verbosity
|
21
21
|
|
data/test/unique_files.rb
CHANGED
@@ -20,6 +20,12 @@ def require_unique_file(file = 'dog.rb', variables = {})
|
|
20
20
|
Coverband::Utils::RelativeFileConverter.convert(File.expand_path(temp_file))
|
21
21
|
end
|
22
22
|
|
23
|
+
@@dogs = 0
|
24
|
+
def require_class_unique_file
|
25
|
+
@@dogs +=1
|
26
|
+
require_unique_file('dog.rb.erb', dog_number: @@dogs)
|
27
|
+
end
|
28
|
+
|
23
29
|
def remove_unique_files
|
24
30
|
FileUtils.rm_r(UNIQUE_FILES_DIR) if File.exist?(UNIQUE_FILES_DIR)
|
25
31
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coverband
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.2.
|
4
|
+
version: 4.2.7.rc.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Mayer
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-07-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: aws-sdk-s3
|
@@ -221,20 +221,6 @@ dependencies:
|
|
221
221
|
- - ">="
|
222
222
|
- !ruby/object:Gem::Version
|
223
223
|
version: '0'
|
224
|
-
- !ruby/object:Gem::Dependency
|
225
|
-
name: pry-byebug
|
226
|
-
requirement: !ruby/object:Gem::Requirement
|
227
|
-
requirements:
|
228
|
-
- - ">="
|
229
|
-
- !ruby/object:Gem::Version
|
230
|
-
version: '0'
|
231
|
-
type: :development
|
232
|
-
prerelease: false
|
233
|
-
version_requirements: !ruby/object:Gem::Requirement
|
234
|
-
requirements:
|
235
|
-
- - ">="
|
236
|
-
- !ruby/object:Gem::Version
|
237
|
-
version: '0'
|
238
224
|
- !ruby/object:Gem::Dependency
|
239
225
|
name: minitest-profile
|
240
226
|
requirement: !ruby/object:Gem::Requirement
|
@@ -263,7 +249,7 @@ dependencies:
|
|
263
249
|
- - ">="
|
264
250
|
- !ruby/object:Gem::Version
|
265
251
|
version: '0'
|
266
|
-
description: Rack middleware to
|
252
|
+
description: Rack middleware to measure production code usage (LOC runtime usage)
|
267
253
|
email:
|
268
254
|
- dan@mayerdan.com
|
269
255
|
executables: []
|
@@ -271,11 +257,13 @@ extensions: []
|
|
271
257
|
extra_rdoc_files: []
|
272
258
|
files:
|
273
259
|
- ".gitignore"
|
260
|
+
- ".jrubyrc"
|
274
261
|
- ".rubocop.yml"
|
275
262
|
- ".travis.yml"
|
276
263
|
- CODE_OF_CONDUCT.md
|
277
264
|
- Gemfile
|
278
265
|
- Gemfile.rails4
|
266
|
+
- Gemfile.rails6
|
279
267
|
- LICENSE
|
280
268
|
- LICENSE.txt
|
281
269
|
- README.md
|
@@ -283,6 +271,7 @@ files:
|
|
283
271
|
- changes.md
|
284
272
|
- config.ru
|
285
273
|
- coverband.gemspec
|
274
|
+
- lib/alternative_coverband_patch.rb
|
286
275
|
- lib/coverband.rb
|
287
276
|
- lib/coverband/adapters/base.rb
|
288
277
|
- lib/coverband/adapters/file_store.rb
|
@@ -309,6 +298,7 @@ files:
|
|
309
298
|
- lib/coverband/utils/file_list.rb
|
310
299
|
- lib/coverband/utils/gem_list.rb
|
311
300
|
- lib/coverband/utils/html_formatter.rb
|
301
|
+
- lib/coverband/utils/jruby_ext.rb
|
312
302
|
- lib/coverband/utils/lines_classifier.rb
|
313
303
|
- lib/coverband/utils/railtie.rb
|
314
304
|
- lib/coverband/utils/relative_file_converter.rb
|
@@ -356,6 +346,7 @@ files:
|
|
356
346
|
- test/benchmarks/dog.rb
|
357
347
|
- test/benchmarks/graph_bench.sh
|
358
348
|
- test/benchmarks/init_rails.rake
|
349
|
+
- test/big_dog.rb.erb
|
359
350
|
- test/coverband/adapters/base_test.rb
|
360
351
|
- test/coverband/adapters/file_store_test.rb
|
361
352
|
- test/coverband/adapters/hash_redis_store_test.rb
|
@@ -402,6 +393,7 @@ files:
|
|
402
393
|
- test/forked/rails_full_stack_test.rb
|
403
394
|
- test/forked/rails_rake_full_stack_test.rb
|
404
395
|
- test/integration/full_stack_test.rb
|
396
|
+
- test/jruby_check.rb
|
405
397
|
- test/rails4_dummy/Rakefile
|
406
398
|
- test/rails4_dummy/app/controllers/dummy_controller.rb
|
407
399
|
- test/rails4_dummy/config.ru
|
@@ -422,6 +414,17 @@ files:
|
|
422
414
|
- test/rails5_dummy/config/environment.rb
|
423
415
|
- test/rails5_dummy/config/routes.rb
|
424
416
|
- test/rails5_dummy/tmp/.keep
|
417
|
+
- test/rails6_dummy/Rakefile
|
418
|
+
- test/rails6_dummy/app/controllers/dummy_controller.rb
|
419
|
+
- test/rails6_dummy/config.ru
|
420
|
+
- test/rails6_dummy/config/application.rb
|
421
|
+
- test/rails6_dummy/config/boot.rb
|
422
|
+
- test/rails6_dummy/config/coverband.rb
|
423
|
+
- test/rails6_dummy/config/coverband_missing_redis.rb
|
424
|
+
- test/rails6_dummy/config/environment.rb
|
425
|
+
- test/rails6_dummy/config/routes.rb
|
426
|
+
- test/rails6_dummy/config/secrets.yml
|
427
|
+
- test/rails6_dummy/tmp/.keep
|
425
428
|
- test/rails_test_helper.rb
|
426
429
|
- test/test_helper.rb
|
427
430
|
- test/unique_files.rb
|
@@ -449,14 +452,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
449
452
|
version: '0'
|
450
453
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
451
454
|
requirements:
|
452
|
-
- - "
|
455
|
+
- - ">"
|
453
456
|
- !ruby/object:Gem::Version
|
454
|
-
version:
|
457
|
+
version: 1.3.1
|
455
458
|
requirements: []
|
456
459
|
rubygems_version: 3.0.3
|
457
460
|
signing_key:
|
458
461
|
specification_version: 4
|
459
|
-
summary: Rack middleware to
|
462
|
+
summary: Rack middleware to measure production code usage (LOC runtime usage)
|
460
463
|
test_files:
|
461
464
|
- test/benchmarks/.gitignore
|
462
465
|
- test/benchmarks/benchmark.rake
|
@@ -464,6 +467,7 @@ test_files:
|
|
464
467
|
- test/benchmarks/dog.rb
|
465
468
|
- test/benchmarks/graph_bench.sh
|
466
469
|
- test/benchmarks/init_rails.rake
|
470
|
+
- test/big_dog.rb.erb
|
467
471
|
- test/coverband/adapters/base_test.rb
|
468
472
|
- test/coverband/adapters/file_store_test.rb
|
469
473
|
- test/coverband/adapters/hash_redis_store_test.rb
|
@@ -510,6 +514,7 @@ test_files:
|
|
510
514
|
- test/forked/rails_full_stack_test.rb
|
511
515
|
- test/forked/rails_rake_full_stack_test.rb
|
512
516
|
- test/integration/full_stack_test.rb
|
517
|
+
- test/jruby_check.rb
|
513
518
|
- test/rails4_dummy/Rakefile
|
514
519
|
- test/rails4_dummy/app/controllers/dummy_controller.rb
|
515
520
|
- test/rails4_dummy/config.ru
|
@@ -530,6 +535,17 @@ test_files:
|
|
530
535
|
- test/rails5_dummy/config/environment.rb
|
531
536
|
- test/rails5_dummy/config/routes.rb
|
532
537
|
- test/rails5_dummy/tmp/.keep
|
538
|
+
- test/rails6_dummy/Rakefile
|
539
|
+
- test/rails6_dummy/app/controllers/dummy_controller.rb
|
540
|
+
- test/rails6_dummy/config.ru
|
541
|
+
- test/rails6_dummy/config/application.rb
|
542
|
+
- test/rails6_dummy/config/boot.rb
|
543
|
+
- test/rails6_dummy/config/coverband.rb
|
544
|
+
- test/rails6_dummy/config/coverband_missing_redis.rb
|
545
|
+
- test/rails6_dummy/config/environment.rb
|
546
|
+
- test/rails6_dummy/config/routes.rb
|
547
|
+
- test/rails6_dummy/config/secrets.yml
|
548
|
+
- test/rails6_dummy/tmp/.keep
|
533
549
|
- test/rails_test_helper.rb
|
534
550
|
- test/test_helper.rb
|
535
551
|
- test/unique_files.rb
|