coverband 5.0.0.rc.4 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.standard.yml +1 -0
- data/README.md +61 -49
- data/changes.md +9 -1
- data/coverband.gemspec +2 -0
- data/lib/coverband/adapters/web_service_store.rb +2 -4
- data/lib/coverband/configuration.rb +54 -50
- data/lib/coverband/reporters/base.rb +1 -2
- data/lib/coverband/reporters/console_report.rb +2 -8
- data/lib/coverband/version.rb +1 -1
- data/test/coverband/configuration_test.rb +52 -1
- data/test/coverband/integrations/background_test.rb +13 -2
- data/test/coverband/reporters/web_test.rb +2 -2
- data/test/jruby_check.rb +1 -1
- data/test/test_helper.rb +2 -0
- data/views/nav.erb +2 -2
- data/views/settings.erb +2 -2
- metadata +33 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f73e90b7f1451c8f7a47355b680b361fa96e7ab665c1b135282e1cf2f87db8ac
|
4
|
+
data.tar.gz: e0bd9b0e10bd500dcb814091a048902e4123fa09a3532e8bffb7108cf69bea53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67e8d3f7f1c925f030b828eb4a4b37a1b35e887341da8cc6956d4c84ec71cb2a31395f656d48ad3d1782e81404624ae95604a4d0198af4cef2e2c43fc7e08578
|
7
|
+
data.tar.gz: 3d4a7456beb6adfa1e6eeec4bacb35ef4f3b3a25049b9540b603e5f9bcd65aba1d370c1cbf446c7835106d8ccc536209fbdc74f77949847e91262cdffa0c715c
|
data/.standard.yml
CHANGED
@@ -13,6 +13,7 @@ ignore: # default: []
|
|
13
13
|
- Style/RedundantRegexpEscape # fix later, enforcement changed
|
14
14
|
- Layout/ArrayAlignment # WTF all of master broken from a few changes in rubo
|
15
15
|
- Performance/RegexpMatch # Rubocop / standardrb have this WRONG for Ruby 2.3/2.4 not compatiable
|
16
|
+
- Style/GlobalStdStream # Rubocop / standardrb have this WRONG for Ruby 2.3/2.4 not compatiable
|
16
17
|
- "vendor/**/*"
|
17
18
|
- "pkg/**/*"
|
18
19
|
- "test/**/*":
|
data/README.md
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
<p align="center">
|
11
11
|
<a href="#key-features">Key Features</a> •
|
12
12
|
<a href="#installation">Installation</a> •
|
13
|
-
<a href="#
|
13
|
+
<a href="#coverband-web-ui">Coverband Web UI</a> •
|
14
14
|
<a href="#advanced-config">Advanced Config</a> •
|
15
15
|
<a href="#license">License</a> •
|
16
16
|
<a href="/changes.md">Change Log / Roadmap</a> •
|
@@ -28,7 +28,7 @@ The primary goal of Coverband is giving deep insight into your production runtim
|
|
28
28
|
- Low performance overhead
|
29
29
|
- Simple setup and configuration
|
30
30
|
- Out of the box support for all standard code execution paths (web, cron, background jobs, rake tasks, etc)
|
31
|
-
- Splits load time (Rails eager load) and
|
31
|
+
- Splits load time (Rails eager load) and runtime metrics
|
32
32
|
- Easy to understand actionable insights from the report
|
33
33
|
- Development mode, offers deep insight of code usage details (number of LOC execution during single request, etc) during development.
|
34
34
|
- Mountable web interface to easily share reports
|
@@ -41,7 +41,7 @@ Coverband stores coverage data in Redis. The Redis endpoint is looked for in thi
|
|
41
41
|
|
42
42
|
1. `ENV['COVERBAND_REDIS_URL']`
|
43
43
|
2. `ENV['REDIS_URL']`
|
44
|
-
3. `localhost`
|
44
|
+
3. `localhost:6379`
|
45
45
|
|
46
46
|
The redis store can also be explicitly defined within the coverband.rb. See [advanced config](#advanced-config).
|
47
47
|
|
@@ -53,8 +53,6 @@ Add this line to your application's `Gemfile`, remember to `bundle install` afte
|
|
53
53
|
gem 'coverband'
|
54
54
|
```
|
55
55
|
|
56
|
-
## Upgrading to Latest
|
57
|
-
|
58
56
|
### No custom code or middleware required
|
59
57
|
|
60
58
|
With older versions of coverband, projects would report to redis using rack or sidekiq middleware. After coverband 4.0, this should no longer be required and could cause performance issues. Reporting to redis is now automatically done within a background thread with no custom code needed.
|
@@ -67,7 +65,7 @@ The Railtie integration means you shouldn't need to do anything else other than
|
|
67
65
|
|
68
66
|
## Sinatra
|
69
67
|
|
70
|
-
For the best coverage you want this loaded as early as possible.
|
68
|
+
For the best coverage you want this loaded as early as possible. We recommend requiring cover band directly in the `config.ru`. Requiring coverband within an initializer could also work, but you may end up missing some boot up coverage. To start collection require Coverband as early as possible.
|
71
69
|
|
72
70
|
```ruby
|
73
71
|
require 'coverband'
|
@@ -77,7 +75,33 @@ use Coverband::BackgroundMiddleware
|
|
77
75
|
run ActionController::Dispatcher.new
|
78
76
|
```
|
79
77
|
|
80
|
-
|
78
|
+
## Coverband Web UI
|
79
|
+
|
80
|
+
![image](https://raw.github.com/danmayer/coverband/master/docs/coverband_web_ui.png)
|
81
|
+
|
82
|
+
> The web index as available on the [Coverband Demo site](https://coverband-demo.herokuapp.com/coverage?#_Coverage)
|
83
|
+
|
84
|
+
- View overall coverage information
|
85
|
+
|
86
|
+
- Drill into individual file coverage
|
87
|
+
|
88
|
+
- View individual file details
|
89
|
+
|
90
|
+
- Clear Coverage - disabled by default as it could be considered a dangerous operation in production. Enable with `config.web_enable_clear` or leave off and clear from [rake task](#clear-coverage).
|
91
|
+
|
92
|
+
- Clear coverage report
|
93
|
+
|
94
|
+
This will clear the coverage data. This wipes out all collected data.
|
95
|
+
|
96
|
+
- Clear individual file coverage
|
97
|
+
|
98
|
+
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.
|
99
|
+
|
100
|
+
- Force coverage collection
|
101
|
+
|
102
|
+
This triggers coverage collection on the current webserver process. Useful in development but confusing in production environments where many ruby processes are usually running.
|
103
|
+
|
104
|
+
### Mounting as a Rack App
|
81
105
|
|
82
106
|
Coverband comes with a mountable rack app for viewing reports. For Rails this can be done in `config/routes.rb` with:
|
83
107
|
|
@@ -97,49 +121,23 @@ Rails.application.routes.draw do
|
|
97
121
|
end
|
98
122
|
```
|
99
123
|
|
100
|
-
or you can enable basic auth by setting `ENV['COVERBAND_PASSWORD']` or via your configuration `config.password =
|
124
|
+
or you can enable basic auth by setting `ENV['COVERBAND_PASSWORD']` or via your configuration `config.password = <YOUR_COMPLEX_UNGUESSABLE_PASSWORD>`
|
101
125
|
|
102
|
-
###
|
126
|
+
### Standalone
|
103
127
|
|
104
|
-
The
|
128
|
+
The coverage server can also be started standalone with a rake task:
|
105
129
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
- **force coverage collection:** This triggers coverage collection on the current webserver process
|
111
|
-
- **clear coverage report:** This will clear the coverage data. This wipes out all collected data (**dangerous**)
|
112
|
-
- View individual file details
|
113
|
-
- **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.
|
114
|
-
|
115
|
-
### JRuby Support
|
116
|
-
|
117
|
-
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 older 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.
|
118
|
-
|
119
|
-
- older versions of JRuby need tracing enabled to work (and this could cause bad performance)
|
120
|
-
- run Jruby with the `--debug` option
|
121
|
-
- add into your `.jrubyrc` the `debug.fullTrace=true` setting
|
122
|
-
- For best performance the `oneshot_lines` is recommended, and in the latest releases should have very low overhead
|
123
|
-
- See JRuby support in a Rails app configured to run via JRuby, in [Coverband Demo](https://github.com/coverband-service/coverband_demo)
|
124
|
-
- JRuby is tested via CI against Rails 5 and 6
|
125
|
-
|
126
|
-
### Rake Tasks
|
127
|
-
|
128
|
-
The rake task generates a report locally and opens a browser pointing to `coverage/index.html`.
|
129
|
-
|
130
|
-
`rake coverband:coverage`
|
131
|
-
|
132
|
-
This is mostly useful in your local development environment.
|
133
|
-
|
134
|
-
##### Example Output
|
130
|
+
```
|
131
|
+
bundle exec rake coverband:coverage_server
|
132
|
+
```
|
135
133
|
|
136
|
-
|
134
|
+
The web UI should then be available here: http://localhost:1022/
|
137
135
|
|
138
|
-
|
139
|
-
![image](https://raw.github.com/danmayer/coverband/master/docs/coverband_index.png)
|
136
|
+
This is especially useful for projects that are api only and cannot support the mounted rack app. To get production coverage, point coverband at your production redis server and ensure to checkout the production version of your project code locally.
|
140
137
|
|
141
|
-
|
142
|
-
|
138
|
+
```
|
139
|
+
COVERBAND_REDIS_URL=redis://username:password:redis_production_server:2322 bundle exec rake coverband:coverage_server
|
140
|
+
```
|
143
141
|
|
144
142
|
# Coverband Demo
|
145
143
|
|
@@ -245,7 +243,7 @@ end
|
|
245
243
|
|
246
244
|
### Avoiding Cache Stampede
|
247
245
|
|
248
|
-
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.
|
246
|
+
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. Note, the default wiggle is set to 30 seconds.
|
249
247
|
|
250
248
|
Add a wiggle (in seconds) to the background thread to avoid all your servers reporting at the same time:
|
251
249
|
|
@@ -253,11 +251,12 @@ Add a wiggle (in seconds) to the background thread to avoid all your servers rep
|
|
253
251
|
|
254
252
|
### Redis Hash Store
|
255
253
|
|
256
|
-
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
|
254
|
+
Coverband on very high volume sites with many server processes reporting can have a race condition which can cause hit counts to be inaccurate. 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 frequency.
|
257
255
|
|
258
|
-
-
|
259
|
-
-
|
260
|
-
|
256
|
+
- Use a dedicated coverband redis instance: `config.store = Coverband::Adapters::HashRedisStore.new(Redis.new(url: redis_url))`
|
257
|
+
- Adjust from default 30s reporting `config.background_reporting_sleep_seconds = 120`
|
258
|
+
|
259
|
+
See more discussion [here](https://github.com/danmayer/coverband/issues/384).
|
261
260
|
|
262
261
|
### Clear Coverage
|
263
262
|
|
@@ -265,6 +264,8 @@ Now that Coverband uses MD5 hashes there should be no reason to manually clear c
|
|
265
264
|
|
266
265
|
`rake coverband:clear`
|
267
266
|
|
267
|
+
This can also be done through the web if `config.web_enable_clear` is enabled.
|
268
|
+
|
268
269
|
### Coverage Data Migration
|
269
270
|
|
270
271
|
Between the release of 4.0 and 4.1 our data format changed. This resets all your coverage data. If you want to restore your previous coverage data, feel free to migrate.
|
@@ -339,6 +340,17 @@ We will match Heroku & Ruby's support lifetime, supporting the last 3 major Ruby
|
|
339
340
|
|
340
341
|
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.
|
341
342
|
|
343
|
+
### JRuby Support
|
344
|
+
|
345
|
+
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 older 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.
|
346
|
+
|
347
|
+
- older versions of JRuby need tracing enabled to work (and this could cause bad performance)
|
348
|
+
- run Jruby with the `--debug` option
|
349
|
+
- add into your `.jrubyrc` the `debug.fullTrace=true` setting
|
350
|
+
- For best performance the `oneshot_lines` is recommended, and in the latest releases should have very low overhead
|
351
|
+
- See JRuby support in a Rails app configured to run via JRuby, in [Coverband Demo](https://github.com/coverband-service/coverband_demo)
|
352
|
+
- JRuby is tested via CI against Rails 5 and 6
|
353
|
+
|
342
354
|
# Contributing To Coverband
|
343
355
|
|
344
356
|
If you are working on adding features, PRs, or bugfixes to Coverband this section should help get you going.
|
data/changes.md
CHANGED
@@ -61,13 +61,21 @@ Will be the fully modern release that drops maintenance legacy support in favor
|
|
61
61
|
- drops static report support
|
62
62
|
- drops gem support
|
63
63
|
- only loaded web reporter files when required
|
64
|
-
-
|
64
|
+
- configuration improvements
|
65
|
+
- improved load order allowing more time for ENV vars (better dotenv, figaro, rails secrets support)
|
66
|
+
- all config options can be set via coverband config, not requiring ENV var support
|
67
|
+
- deprecation notices on soon to be removed config options
|
68
|
+
- config exceptions on invalid configuration combinations
|
69
|
+
- additional testing around configurations
|
70
|
+
- improved defaults and reduced configuration options
|
65
71
|
- improved resque patching pattern
|
66
72
|
- improved default ignores
|
67
73
|
- additional adapters
|
68
74
|
- supports web-service adapter for http coverage collection
|
69
75
|
- support log/file adapter
|
76
|
+
- extendable pattern to support any additional backends
|
70
77
|
- reduce logs / errors / alerts on bad startup configurations
|
78
|
+
- fix: #301 runtime vs eagerload should always remain correct
|
71
79
|
|
72
80
|
# Released
|
73
81
|
|
data/coverband.gemspec
CHANGED
@@ -25,11 +25,13 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency "memory_profiler"
|
26
26
|
spec.add_development_dependency "minitest"
|
27
27
|
spec.add_development_dependency "minitest-fork_executor"
|
28
|
+
spec.add_development_dependency "minitest-stub-const"
|
28
29
|
spec.add_development_dependency "mocha", "~> 1.7.0"
|
29
30
|
spec.add_development_dependency "rack"
|
30
31
|
spec.add_development_dependency "rack-test"
|
31
32
|
spec.add_development_dependency "rake"
|
32
33
|
spec.add_development_dependency "resque"
|
34
|
+
spec.add_development_dependency "standard", "= 0.2.5"
|
33
35
|
spec.add_development_dependency "standardrb"
|
34
36
|
|
35
37
|
spec.add_development_dependency "coveralls"
|
@@ -3,8 +3,7 @@
|
|
3
3
|
module Coverband
|
4
4
|
module Adapters
|
5
5
|
###
|
6
|
-
# WebServiceStore store a
|
7
|
-
# TODO: add webmock tests
|
6
|
+
# WebServiceStore: store a checkpoint of coverage to a remote service
|
8
7
|
###
|
9
8
|
class WebServiceStore < Base
|
10
9
|
attr_reader :coverband_url, :process_type, :runtime_env, :hostname, :pid
|
@@ -56,8 +55,7 @@ module Coverband
|
|
56
55
|
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
|
57
56
|
http.request(req)
|
58
57
|
end
|
59
|
-
|
60
|
-
coverage_data
|
58
|
+
JSON.parse(res.body)
|
61
59
|
rescue => e
|
62
60
|
logger&.error "Coverband: Error while retrieving coverage #{e}" if Coverband.configuration.verbose || Coverband.configuration.service_dev_mode
|
63
61
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Coverband
|
4
4
|
class Configuration
|
5
5
|
attr_accessor :root_paths, :root,
|
6
|
-
:
|
6
|
+
:verbose,
|
7
7
|
:reporter, :redis_namespace, :redis_ttl,
|
8
8
|
:background_reporting_enabled,
|
9
9
|
:test_env, :web_enable_clear, :gem_details, :web_debug, :report_on_exit,
|
@@ -11,7 +11,7 @@ module Coverband
|
|
11
11
|
:view_tracker
|
12
12
|
attr_writer :logger, :s3_region, :s3_bucket, :s3_access_key_id,
|
13
13
|
:s3_secret_access_key, :password, :api_key, :service_url, :coverband_timeout, :service_dev_mode,
|
14
|
-
:service_test_mode, :
|
14
|
+
:service_test_mode, :process_type, :track_views, :redis_url,
|
15
15
|
:background_reporting_sleep_seconds, :reporting_wiggle
|
16
16
|
|
17
17
|
attr_reader :track_gems, :ignore, :use_oneshot_lines_coverage
|
@@ -20,7 +20,6 @@ module Coverband
|
|
20
20
|
# TODO: This is is brittle and not a great solution to avoid deploy time
|
21
21
|
# actions polluting the 'runtime' metrics
|
22
22
|
#
|
23
|
-
# * should we skip /bin/rails webpacker:compile ?
|
24
23
|
# * Perhaps detect heroku deployment ENV var opposed to tasks?
|
25
24
|
#####
|
26
25
|
IGNORE_TASKS = ["coverband:clear",
|
@@ -28,6 +27,7 @@ module Coverband
|
|
28
27
|
"coverband:coverage_server",
|
29
28
|
"coverband:migrate",
|
30
29
|
"assets:precompile",
|
30
|
+
"webpacker:compile",
|
31
31
|
"db:version",
|
32
32
|
"db:create",
|
33
33
|
"db:drop",
|
@@ -56,7 +56,6 @@ module Coverband
|
|
56
56
|
@root_paths = []
|
57
57
|
@ignore = IGNORE_DEFAULTS.dup
|
58
58
|
@search_paths = TRACKED_DEFAULT_PATHS.dup
|
59
|
-
@additional_files = []
|
60
59
|
@verbose = false
|
61
60
|
@reporter = "scov"
|
62
61
|
@logger = nil
|
@@ -65,8 +64,6 @@ module Coverband
|
|
65
64
|
@background_reporting_sleep_seconds = nil
|
66
65
|
@test_env = nil
|
67
66
|
@web_enable_clear = false
|
68
|
-
@track_gems = false
|
69
|
-
@gem_details = false
|
70
67
|
@track_views = true
|
71
68
|
@view_tracker = nil
|
72
69
|
@web_debug = false
|
@@ -85,17 +82,19 @@ module Coverband
|
|
85
82
|
@service_dev_mode = nil
|
86
83
|
@service_test_mode = nil
|
87
84
|
@proces_type = nil
|
88
|
-
|
85
|
+
|
86
|
+
@redis_url = nil
|
87
|
+
@redis_namespace = nil
|
88
|
+
@redis_ttl = 2_592_000 # in seconds. Default is 30 days.
|
89
|
+
@reporting_wiggle = nil
|
89
90
|
|
90
91
|
# TODO: these are deprecated
|
91
92
|
@s3_region = nil
|
92
93
|
@s3_bucket = nil
|
93
94
|
@s3_access_key_id = nil
|
94
95
|
@s3_secret_access_key = nil
|
95
|
-
|
96
|
-
@
|
97
|
-
@redis_ttl = 2_592_000 # in seconds. Default is 30 days.
|
98
|
-
@reporting_wiggle = nil
|
96
|
+
@track_gems = false
|
97
|
+
@gem_details = false
|
99
98
|
end
|
100
99
|
|
101
100
|
def logger
|
@@ -110,25 +109,16 @@ module Coverband
|
|
110
109
|
@password || ENV["COVERBAND_PASSWORD"]
|
111
110
|
end
|
112
111
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
def s3_region
|
118
|
-
puts "deprecated, s3 is no longer support"
|
119
|
-
end
|
120
|
-
|
121
|
-
def s3_access_key_id
|
122
|
-
puts "deprecated, s3 is no longer support"
|
123
|
-
end
|
124
|
-
|
125
|
-
def s3_secret_access_key
|
126
|
-
puts "deprecated, s3 is no longer support"
|
127
|
-
end
|
128
|
-
|
112
|
+
# The adjustments here either protect the redis or service from being overloaded
|
113
|
+
# the tradeoff being the delay in when reporting data is available
|
114
|
+
# if running your own redis increasing this number reduces load on the redis CPU
|
129
115
|
def background_reporting_sleep_seconds
|
130
|
-
@background_reporting_sleep_seconds ||= if
|
131
|
-
|
116
|
+
@background_reporting_sleep_seconds ||= if service?
|
117
|
+
# default to 10m for service
|
118
|
+
Coverband.configuration.coverband_env == "production" ? 600 : 60
|
119
|
+
elsif store.is_a?(Coverband::Adapters::HashRedisStore)
|
120
|
+
# Default to 5 minutes if using the hash redis store
|
121
|
+
300
|
132
122
|
else
|
133
123
|
60
|
134
124
|
end
|
@@ -139,7 +129,8 @@ module Coverband
|
|
139
129
|
end
|
140
130
|
|
141
131
|
def store
|
142
|
-
@store ||= if
|
132
|
+
@store ||= if service?
|
133
|
+
raise "invalid configuration: unclear default store coverband expects either api_key or redis_url" if ENV["COVERBAND_REDIS_URL"]
|
143
134
|
require "coverband/adapters/web_service_store"
|
144
135
|
Coverband::Adapters::WebServiceStore.new(service_url)
|
145
136
|
else
|
@@ -147,21 +138,18 @@ module Coverband
|
|
147
138
|
end
|
148
139
|
end
|
149
140
|
|
150
|
-
def track_views
|
151
|
-
@track_views ||= service_disabled_dev_test_env? ? false : true
|
152
|
-
end
|
153
|
-
|
154
141
|
def store=(store)
|
155
142
|
raise "Pass in an instance of Coverband::Adapters" unless store.is_a?(Coverband::Adapters::Base)
|
156
|
-
|
157
|
-
|
158
|
-
# This is a safer default for the high server volumes that need the hash store
|
159
|
-
# it should avoid overloading the redis with lots of load
|
160
|
-
@background_reporting_sleep_seconds = 300 if store.is_a?(Coverband::Adapters::HashRedisStore)
|
143
|
+
raise "invalid configuration: only coverband service expects an API Key" if api_key && store.class.to_s != "Coverband::Adapters::WebServiceStore"
|
144
|
+
raise "invalid configuration: coverband service shouldn't have redis url set" if ENV["COVERBAND_REDIS_URL"] && store.class.to_s == "Coverband::Adapters::WebServiceStore"
|
161
145
|
|
162
146
|
@store = store
|
163
147
|
end
|
164
148
|
|
149
|
+
def track_views
|
150
|
+
@track_views ||= service_disabled_dev_test_env? ? false : true
|
151
|
+
end
|
152
|
+
|
165
153
|
###
|
166
154
|
# Search Paths
|
167
155
|
###
|
@@ -183,10 +171,6 @@ module Coverband
|
|
183
171
|
@ignore = (@ignore + ignored_array).uniq
|
184
172
|
end
|
185
173
|
|
186
|
-
def track_gems=(_value)
|
187
|
-
puts "gem tracking is deprecated, setting this will be ignored"
|
188
|
-
end
|
189
|
-
|
190
174
|
def current_root
|
191
175
|
@current_root ||= File.expand_path(Coverband.configuration.root).freeze
|
192
176
|
end
|
@@ -203,7 +187,7 @@ module Coverband
|
|
203
187
|
@all_root_patterns ||= all_root_paths.map { |path| /^#{path}/ }.freeze
|
204
188
|
end
|
205
189
|
|
206
|
-
SKIPPED_SETTINGS = %w[@s3_secret_access_key @store]
|
190
|
+
SKIPPED_SETTINGS = %w[@s3_secret_access_key @store @api_key @password]
|
207
191
|
def to_h
|
208
192
|
instance_variables
|
209
193
|
.each_with_object({}) do |var, hash|
|
@@ -221,6 +205,10 @@ module Coverband
|
|
221
205
|
Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.6.0")
|
222
206
|
end
|
223
207
|
|
208
|
+
def redis_url
|
209
|
+
@redis_url ||= ENV["COVERBAND_REDIS_URL"] || ENV["REDIS_URL"]
|
210
|
+
end
|
211
|
+
|
224
212
|
def api_key
|
225
213
|
@api_key ||= ENV["COVERBAND_API_KEY"]
|
226
214
|
end
|
@@ -245,12 +233,12 @@ module Coverband
|
|
245
233
|
@service_dev_mode ||= ENV["COVERBAND_ENABLE_TEST_MODE"] || false
|
246
234
|
end
|
247
235
|
|
248
|
-
def
|
236
|
+
def process_type
|
249
237
|
@process_type ||= ENV["PROCESS_TYPE"] || "unknown"
|
250
238
|
end
|
251
239
|
|
252
|
-
def
|
253
|
-
|
240
|
+
def service?
|
241
|
+
Coverband.coverband_service? || !api_key.nil?
|
254
242
|
end
|
255
243
|
|
256
244
|
def service_disabled_dev_test_env?
|
@@ -258,12 +246,28 @@ module Coverband
|
|
258
246
|
(coverband_env == "development" && !Coverband.configuration.service_dev_mode)
|
259
247
|
end
|
260
248
|
|
261
|
-
|
249
|
+
def s3_bucket
|
250
|
+
puts "deprecated, s3 is no longer support"
|
251
|
+
end
|
262
252
|
|
263
|
-
def
|
264
|
-
|
253
|
+
def s3_region
|
254
|
+
puts "deprecated, s3 is no longer support"
|
255
|
+
end
|
256
|
+
|
257
|
+
def s3_access_key_id
|
258
|
+
puts "deprecated, s3 is no longer support"
|
259
|
+
end
|
260
|
+
|
261
|
+
def s3_secret_access_key
|
262
|
+
puts "deprecated, s3 is no longer support"
|
263
|
+
end
|
264
|
+
|
265
|
+
def track_gems=(_value)
|
266
|
+
puts "gem tracking is deprecated, setting this will be ignored"
|
265
267
|
end
|
266
268
|
|
269
|
+
private
|
270
|
+
|
267
271
|
def redis_store_options
|
268
272
|
{ttl: Coverband.configuration.redis_ttl,
|
269
273
|
redis_namespace: Coverband.configuration.redis_namespace}
|
@@ -8,14 +8,8 @@ module Coverband
|
|
8
8
|
class ConsoleReport < Base
|
9
9
|
def self.report(store, options = {})
|
10
10
|
scov_style_report = super(store, options)
|
11
|
-
|
12
|
-
|
13
|
-
# TODO: In Coverband 5 deprecate none hash format
|
14
|
-
if usage.is_a?(Hash)
|
15
|
-
Coverband.configuration.logger.info "#{file}: #{usage["data"]}"
|
16
|
-
else
|
17
|
-
Coverband.configuration.logger.info "#{file}: #{usage}"
|
18
|
-
end
|
11
|
+
scov_style_report[:merged].each_pair do |file, usage|
|
12
|
+
Coverband.configuration.logger.info "#{file}: #{usage["data"]}"
|
19
13
|
end
|
20
14
|
scov_style_report
|
21
15
|
end
|
data/lib/coverband/version.rb
CHANGED
@@ -4,6 +4,7 @@ require File.expand_path("../test_helper", File.dirname(__FILE__))
|
|
4
4
|
|
5
5
|
class BaseTest < Minitest::Test
|
6
6
|
def setup
|
7
|
+
Coverband.configuration.reset
|
7
8
|
super
|
8
9
|
Coverband.configuration.reset
|
9
10
|
Coverband.configure do |config|
|
@@ -52,7 +53,7 @@ class BaseTest < Minitest::Test
|
|
52
53
|
assert_equal current_paths, Coverband.configuration.root_paths
|
53
54
|
end
|
54
55
|
|
55
|
-
test "store raises
|
56
|
+
test "store raises when not set to supported adapter" do
|
56
57
|
Coverband::Collectors::Coverage.instance.reset_instance
|
57
58
|
assert_raises RuntimeError do
|
58
59
|
Coverband.configure do |config|
|
@@ -61,6 +62,56 @@ class BaseTest < Minitest::Test
|
|
61
62
|
end
|
62
63
|
end
|
63
64
|
|
65
|
+
test "store defaults to redis store" do
|
66
|
+
Coverband::Collectors::Coverage.instance.reset_instance
|
67
|
+
assert_equal Coverband.configuration.store.class, Coverband::Adapters::RedisStore
|
68
|
+
end
|
69
|
+
|
70
|
+
test "store is a service store when api_key is set" do
|
71
|
+
Coverband::Collectors::Coverage.instance.reset_instance
|
72
|
+
Coverband.configuration.reset
|
73
|
+
Coverband.configure do |config|
|
74
|
+
config.redis_url = nil
|
75
|
+
config.api_key = "test-key"
|
76
|
+
end
|
77
|
+
assert_equal Coverband.configuration.store.class.to_s, "Coverband::Adapters::WebServiceStore"
|
78
|
+
end
|
79
|
+
|
80
|
+
test "store raises when api key set but not set to service" do
|
81
|
+
Coverband::Collectors::Coverage.instance.reset_instance
|
82
|
+
Coverband.configuration.reset
|
83
|
+
assert_raises RuntimeError do
|
84
|
+
Coverband.configure do |config|
|
85
|
+
config.api_key = "test-key"
|
86
|
+
config.redis_url = "redis://localhost:3333"
|
87
|
+
config.store = Coverband::Adapters::RedisStore.new(Coverband::Test.redis, redis_namespace: "coverband_test")
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
test "store raises when api key and coverband redis env" do
|
93
|
+
Coverband::Collectors::Coverage.instance.reset_instance
|
94
|
+
Coverband.configuration.reset
|
95
|
+
|
96
|
+
env = ENV.to_hash.merge("COVERBAND_REDIS_URL" => "redis://localhost:3333")
|
97
|
+
Object.stub_const(:ENV, env) do
|
98
|
+
assert_raises RuntimeError do
|
99
|
+
Coverband.configure do |config|
|
100
|
+
config.api_key = "test-key"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
test "store doesnt raises when api key and redis_url" do
|
107
|
+
Coverband::Collectors::Coverage.instance.reset_instance
|
108
|
+
Coverband.configuration.reset
|
109
|
+
Coverband.configure do |config|
|
110
|
+
config.api_key = "test-key"
|
111
|
+
config.redis_url = "redis://localhost:3333"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
64
115
|
test "use_oneshot_lines_coverage" do
|
65
116
|
refute Coverband.configuration.use_oneshot_lines_coverage
|
66
117
|
|
@@ -12,18 +12,29 @@ class BackgroundTest < Minitest::Test
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
def setup
|
16
|
+
Coverband.configuration.reset
|
17
|
+
super
|
18
|
+
Coverband.configure do |config|
|
19
|
+
config.background_reporting_sleep_seconds = 60
|
20
|
+
Coverband.configuration.reporting_wiggle = 0
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
15
24
|
def test_start
|
25
|
+
sleep_seconds = Coverband.configuration.background_reporting_sleep_seconds.to_i
|
16
26
|
Thread.expects(:new).yields.returns(ThreadDouble.new(true))
|
17
27
|
Coverband::Background.expects(:loop).yields
|
18
|
-
Coverband::Background.expects(:sleep).with(
|
28
|
+
Coverband::Background.expects(:sleep).with(sleep_seconds)
|
19
29
|
Coverband::Collectors::Coverage.instance.expects(:report_coverage).once
|
20
30
|
2.times { Coverband::Background.start }
|
21
31
|
end
|
22
32
|
|
23
33
|
def test_start_with_wiggle
|
34
|
+
sleep_seconds = Coverband.configuration.background_reporting_sleep_seconds.to_i
|
24
35
|
Thread.expects(:new).yields.returns(ThreadDouble.new(true))
|
25
36
|
Coverband::Background.expects(:loop).yields
|
26
|
-
Coverband::Background.expects(:sleep).with(
|
37
|
+
Coverband::Background.expects(:sleep).with(sleep_seconds + 5)
|
27
38
|
Coverband::Background.expects(:rand).with(10).returns(5)
|
28
39
|
Coverband.configuration.reporting_wiggle = 10
|
29
40
|
Coverband::Collectors::Coverage.instance.expects(:report_coverage).once
|
@@ -22,13 +22,13 @@ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.2.0")
|
|
22
22
|
test "renders index content" do
|
23
23
|
get "/"
|
24
24
|
assert last_response.ok?
|
25
|
-
assert_match "Coverband
|
25
|
+
assert_match "Coverband Home", last_response.body
|
26
26
|
end
|
27
27
|
|
28
28
|
test "renders index content for empty path" do
|
29
29
|
get ""
|
30
30
|
assert last_response.ok?
|
31
|
-
assert_match "Coverband
|
31
|
+
assert_match "Coverband Home", last_response.body
|
32
32
|
end
|
33
33
|
|
34
34
|
test "renders 404" do
|
data/test/jruby_check.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -6,6 +6,7 @@ require "rubygems"
|
|
6
6
|
require "simplecov"
|
7
7
|
require "coveralls"
|
8
8
|
require "minitest/autorun"
|
9
|
+
require "minitest/stub_const"
|
9
10
|
require "mocha/minitest"
|
10
11
|
require "ostruct"
|
11
12
|
require "json"
|
@@ -45,6 +46,7 @@ module Coverband
|
|
45
46
|
end
|
46
47
|
|
47
48
|
def self.reset
|
49
|
+
Coverband.configuration.reset
|
48
50
|
Coverband.configuration.redis_namespace = "coverband_test"
|
49
51
|
Coverband.configuration.store.instance_variable_set(:@redis_namespace, "coverband_test")
|
50
52
|
Coverband.configuration.store.class.class_variable_set(:@@path_cache, {})
|
data/views/nav.erb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
<div id="header">
|
3
|
-
<a href='<%= base_path %>'>Coverband
|
4
|
-
<a href='<%= base_path %>settings'>
|
3
|
+
<a href='<%= base_path %>'>Coverband Home</a>
|
4
|
+
<a href='<%= base_path %>settings'>Configuration</a>
|
5
5
|
<% if Coverband.configuration.web_enable_clear %>
|
6
6
|
<%= button("#{base_path}clear", 'clear coverage report', delete: true) %>
|
7
7
|
<% end %>
|
data/views/settings.erb
CHANGED
@@ -11,8 +11,8 @@
|
|
11
11
|
<body>
|
12
12
|
<div id="wrapper" style="">
|
13
13
|
<div id="header">
|
14
|
-
<a href='<%= base_path %>'>Coverband
|
15
|
-
<a href='<%= base_path %>settings'>
|
14
|
+
<a href='<%= base_path %>'>Coverband Home</a>
|
15
|
+
<a href='<%= base_path %>settings'>Configuration</a>
|
16
16
|
</div>
|
17
17
|
<div id="content">
|
18
18
|
<dl>
|
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: 5.0.0
|
4
|
+
version: 5.0.0
|
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: 2020-08-
|
12
|
+
date: 2020-08-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: benchmark-ips
|
@@ -95,6 +95,20 @@ dependencies:
|
|
95
95
|
- - ">="
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '0'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: minitest-stub-const
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
98
112
|
- !ruby/object:Gem::Dependency
|
99
113
|
name: mocha
|
100
114
|
requirement: !ruby/object:Gem::Requirement
|
@@ -165,6 +179,20 @@ dependencies:
|
|
165
179
|
- - ">="
|
166
180
|
- !ruby/object:Gem::Version
|
167
181
|
version: '0'
|
182
|
+
- !ruby/object:Gem::Dependency
|
183
|
+
name: standard
|
184
|
+
requirement: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - '='
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: 0.2.5
|
189
|
+
type: :development
|
190
|
+
prerelease: false
|
191
|
+
version_requirements: !ruby/object:Gem::Requirement
|
192
|
+
requirements:
|
193
|
+
- - '='
|
194
|
+
- !ruby/object:Gem::Version
|
195
|
+
version: 0.2.5
|
168
196
|
- !ruby/object:Gem::Dependency
|
169
197
|
name: standardrb
|
170
198
|
requirement: !ruby/object:Gem::Requirement
|
@@ -434,11 +462,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
434
462
|
version: '0'
|
435
463
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
436
464
|
requirements:
|
437
|
-
- - "
|
465
|
+
- - ">="
|
438
466
|
- !ruby/object:Gem::Version
|
439
|
-
version:
|
467
|
+
version: '0'
|
440
468
|
requirements: []
|
441
|
-
rubygems_version: 3.
|
469
|
+
rubygems_version: 3.1.2
|
442
470
|
signing_key:
|
443
471
|
specification_version: 4
|
444
472
|
summary: Rack middleware to measure production code usage (LOC runtime usage)
|