qa_server 5.3.0 → 5.4.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c2905e19c557faccf19c7dd83f587f06ceacb2c2
4
- data.tar.gz: db5ce48e087afee79569c080898a612f814f5250
3
+ metadata.gz: ab89fc6147c1cf32de828a8b2cecaab3ca66b296
4
+ data.tar.gz: 027160d4a1e0f0090a1c6d81cfdcd74fba5d1423
5
5
  SHA512:
6
- metadata.gz: ac00bc271dd281d3d7e42c5b926cc292210ed200566c9083fab772fbd1e2fd96f0c76f12d9b27536e91c0474d62cdceeca5df0f11ec893776bb7ac86c18482e9
7
- data.tar.gz: c56721d0a15ddc0d683d9b758a621ae4ae9f26a1b1685d97d22d468332caa9370bb6db77376415abcf1dfea53a1437f18bfd6832bc40da3c6c5226fcba628b49
6
+ metadata.gz: aa48a9de27b5b612d590981dfbb9f4316f496a6ecee810bc25735f7ffd1d5fc73c4a6e9f63af65aaeb767a35d983a9c3680ab1cd27b5558ef7b4c11958d73efe
7
+ data.tar.gz: 12c86bbeb3d41de071788f93fdfd3ef632a1300c77182a114124a5fd5895ac733e0c4f76b72e973a3cd7b5a691224b2fb7be21b2651e04a0a935ad283ca8a973
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ### 5.4.0 (2020-01-07)
2
+
3
+ * adds config hour_offset_to_expire_cache
4
+ * deprecates config hour_offset_to_run_monitoring_tests (replaced by hour_offset_to_expire_cache)
5
+ * updates QaServer.monitoring_expires_at to use the new hour_offset_to_expire_cache config
6
+ * adds QaServer.cache_expiry that can be used for expiring all cached data
7
+ * add tests and exceptions for configs
8
+
1
9
  ### 5.3.0 (2019-12-19)
2
10
 
3
11
  * optionally log browser and platform user agent info
@@ -5,12 +5,12 @@ QaServer.config do |config|
5
5
  # @see https://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html for possible values of TimeZone names
6
6
  # config.preferred_time_zone_name = 'Eastern Time (US & Canada)'
7
7
 
8
- # Preferred hour to run monitoring tests
8
+ # Preferred hour to expire caches related to slow running calculations (e.g. monitoring tests, performance data)
9
9
  # @param [Integer] count of hours from midnight (0-23 with 0=midnight)
10
10
  # @example
11
11
  # For preferred_time_zone_name of 'Eastern Time (US & Canada)', use 3 for slow down at midnight PT/3am ET
12
12
  # For preferred_time_zone_name of 'Pacific Time (US & Canada)', use 0 for slow down at midnight PT/3am ET
13
- # config.hour_offset_to_run_monitoring_tests = 3
13
+ # config.hour_offset_to_expire_cache = 3
14
14
 
15
15
  # Displays a graph of historical test data when true
16
16
  # @param [Boolean] display history graph when true
data/lib/qa_server.rb CHANGED
@@ -2,9 +2,13 @@
2
2
  require 'qa_server/engine'
3
3
  require 'qa_server/version'
4
4
  require 'user_agent'
5
+ require 'deprecation'
5
6
 
6
7
  module QaServer
7
8
  extend ActiveSupport::Autoload
9
+ extend Deprecation
10
+
11
+ self.deprecation_horizon = 'LD4P/QaServer v6.0.0'
8
12
 
9
13
  autoload :Configuration
10
14
 
@@ -23,17 +27,27 @@ module QaServer
23
27
  @config
24
28
  end
25
29
 
30
+ # @return [ActiveSupport::TimeWithZone] current DateTime in the configured preferred_time_zone_name
26
31
  def self.current_time
27
32
  Time.now.in_time_zone(QaServer.config.preferred_time_zone_name)
28
33
  end
29
34
 
35
+ # @return [Float] current DateTime in seconds
30
36
  def self.current_time_s
31
37
  current_time.to_f
32
38
  end
33
39
 
40
+ # @return [ActiveSupport::TimeWithZone] DateTime at which cache should expire
34
41
  def self.monitoring_expires_at
35
- offset = QaServer.config.hour_offset_to_run_monitoring_tests
36
- (current_time - offset.hours).beginning_of_day + offset.hours
42
+ offset = QaServer.config.hour_offset_to_expire_cache
43
+ offset_time = current_time
44
+ offset_time = offset_time.tomorrow unless (offset_time + 5.minutes).hour < offset
45
+ offset_time.beginning_of_day + offset.hours - 5.minutes
46
+ end
47
+
48
+ # @return [Float] number of seconds until cache should expire
49
+ def self.cache_expiry
50
+ monitoring_expires_at - current_time
37
51
  end
38
52
 
39
53
  def self.log_agent_info(request)
@@ -9,16 +9,40 @@ module QaServer
9
9
  @preferred_time_zone_name ||= 'Eastern Time (US & Canada)'
10
10
  end
11
11
 
12
- # Preferred hour to run monitoring tests
12
+ # Set preferred hour to expire caches related to slow running calculations (e.g. monitoring tests, performance data)
13
+ # @param [Integer] count of hours after midnight (0-23 with 0=midnight)
14
+ # @raise [ArgumentError] if offset is not between 0 and 23
15
+ # @example
16
+ # For preferred_time_zone_name of 'Eastern Time (US & Canada)', use 3 for slow down at midnight PT/3am ET
17
+ # For preferred_time_zone_name of 'Pacific Time (US & Canada)', use 0 for slow down at midnight PT/3am ET
18
+ def hour_offset_to_expire_cache=(offset)
19
+ raise ArgumentError, 'offset must be between 0 and 23' unless (0..23).cover? offset
20
+ @hour_offset_to_expire_cache = offset
21
+ end
22
+
23
+ # Preferred hour to expire caches related to slow running calculations (e.g. monitoring tests, performance data)
24
+ # @return [Integer] count of hours after midnight (0-23 with 0=midnight)
25
+ def hour_offset_to_expire_cache
26
+ @hour_offset_to_expire_cache ||= 3
27
+ end
28
+
29
+ # Set preferred hour to run monitoring tests (deprecated)
13
30
  # @param [Integer] count of hours from midnight (0-23 with 0=midnight)
14
31
  # @example
15
32
  # For preferred_time_zone_name of 'Eastern Time (US & Canada)', use 3 for slow down at midnight PT/3am ET
16
33
  # For preferred_time_zone_name of 'Pacific Time (US & Canada)', use 0 for slow down at midnight PT/3am ET
17
- attr_writer :hour_offset_to_run_monitoring_tests
18
- def hour_offset_to_run_monitoring_tests
19
- @hour_offset_to_run_monitoring_tests ||= 3
34
+ # @deprecated Use {#hour_offset_to_expire_cache=} instead.
35
+ def hour_offset_to_run_monitoring_tests=(offset)
36
+ Deprecation.warn(QaServer, "hour_offset_to_run_monitoring_tests= is deprecated and will be removed from a future release (use #hour_offset_to_expire_cache= instead)")
37
+ @hour_offset_to_expire_cache = offset
20
38
  end
21
39
 
40
+ # Preferred hour to run monitoring tests (deprecated)
41
+ # @return [Integer] count of hours from midnight (0-23 with 0=midnight)
42
+ # @deprecated Use {#hour_offset_to_expire_cache} instead.
43
+ alias hour_offset_to_run_monitoring_tests hour_offset_to_expire_cache
44
+ deprecation_deprecate hour_offset_to_run_monitoring_tests: "use #hour_offset_to_expire_cache instead"
45
+
22
46
  # Displays a graph of historical test data when true
23
47
  # @param [Boolean] display history graph when true
24
48
  attr_writer :display_historical_graph
@@ -74,8 +98,15 @@ module QaServer
74
98
  end
75
99
 
76
100
  # Performance graph default time period for all graphs. All authorities will show the graph for this time period on page load.
77
- # @param [String] :day, :month, or :year
78
- attr_writer :performance_graph_default_time_period
101
+ # @param [Symbol] time period for default display of performance graphs (i.e., one of :day, :month, or :year)
102
+ # @raise [ArgumentError] if time_period is not one of :day, :month, or :year
103
+ def performance_graph_default_time_period=(time_period)
104
+ raise ArgumentError, 'time_period must be one of :day, :month, or :year' unless [:day, :month, :year].include? time_period
105
+ @performance_graph_default_time_period = time_period
106
+ end
107
+
108
+ # Performance graph default time period for all graphs. All authorities will show the graph for this time period on page load.
109
+ # @return [Symbol] time period for default display of performance graphs (i.e., one of :day, :month, or :year)
79
110
  def performance_graph_default_time_period
80
111
  @performance_graph_default_time_period ||= :month
81
112
  end
@@ -89,8 +120,15 @@ module QaServer
89
120
  end
90
121
 
91
122
  # Performance datatable default time period for calculating stats.
92
- # @param [String] :day, :month, :year, :all
93
- attr_writer :performance_datatable_default_time_period
123
+ # @param [Symbol] time period for calculating performance stats (i.e., one of :day, :month, :year, or :all)
124
+ # @raise [ArgumentError] if time_period is not one of :day, :month, :year, or :all
125
+ def performance_datatable_default_time_period=(time_period)
126
+ raise ArgumentError, 'time_period must be one of :day, :month, :year, or :all' unless [:day, :month, :year, :all].include? time_period
127
+ @performance_datatable_default_time_period = time_period
128
+ end
129
+
130
+ # Performance datatable default time period for calculating stats.
131
+ # @return [Symbol] time period for calculating performance stats (i.e., one of :day, :month, :year, or :all)
94
132
  def performance_datatable_default_time_period
95
133
  @performance_datatable_default_time_period ||= :year
96
134
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module QaServer
3
- VERSION = '5.3.0'
3
+ VERSION = '5.4.0'
4
4
  end
data/qa_server.gemspec CHANGED
@@ -38,6 +38,7 @@ Gem::Specification.new do |spec|
38
38
  # spec.add_development_dependency "capybara", '~> 3.29'
39
39
  # spec.add_development_dependency 'capybara-maleficent', '~> 0.3.0'
40
40
  # spec.add_development_dependency 'chromedriver-helper', '~> 2.1'
41
+ spec.add_development_dependency 'deprecation'
41
42
  spec.add_development_dependency 'engine_cart', '~> 2.0'
42
43
  spec.add_development_dependency "factory_bot", '~> 4.4'
43
44
  spec.add_development_dependency 'simplecov'
@@ -0,0 +1,199 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe QaServer::Configuration do
5
+ let(:config) { described_class.new }
6
+
7
+ describe '#preferred_time_zone_name' do
8
+ it 'returns default as Eastern Time' do
9
+ expect(config.preferred_time_zone_name).to eq 'Eastern Time (US & Canada)'
10
+ end
11
+
12
+ it 'returns set time zone name' do
13
+ config.preferred_time_zone_name = 'Pacific Time (US & Canada)'
14
+ expect(config.preferred_time_zone_name).to eq 'Pacific Time (US & Canada)'
15
+ end
16
+ end
17
+
18
+ describe '#hour_offset_to_expire_cache=' do
19
+ it 'raises exception if offset is negative' do
20
+ expect { config.hour_offset_to_expire_cache = -1 }.to raise_error ArgumentError, 'offset must be between 0 and 23'
21
+ end
22
+
23
+ it 'raises exception if offset is greater than 23' do
24
+ expect { config.hour_offset_to_expire_cache = 24 }.to raise_error ArgumentError, 'offset must be between 0 and 23'
25
+ end
26
+
27
+ it 'sets offset if between 0..23' do
28
+ expect(config.hour_offset_to_expire_cache = 5).to eq 5
29
+ end
30
+ end
31
+
32
+ describe '#hour_offset_to_expire_cache' do
33
+ it 'returns default as 3' do
34
+ expect(config.hour_offset_to_expire_cache).to eq 3
35
+ end
36
+
37
+ it 'returns set offset' do
38
+ config.hour_offset_to_expire_cache = 2
39
+ expect(config.hour_offset_to_expire_cache).to eq 2
40
+ end
41
+ end
42
+
43
+ describe '#display_historical_graph?' do
44
+ it 'return default as false' do
45
+ expect(config.display_historical_graph?).to eq false
46
+ end
47
+
48
+ it 'returns set value' do
49
+ config.display_historical_graph = true
50
+ expect(config.display_historical_graph?).to eq true
51
+ end
52
+ end
53
+
54
+ describe '#display_historical_datatable?' do
55
+ it 'return default as true' do
56
+ expect(config.display_historical_datatable?).to eq true
57
+ end
58
+
59
+ it 'returns set value' do
60
+ config.display_historical_datatable = false
61
+ expect(config.display_historical_datatable?).to eq false
62
+ end
63
+ end
64
+
65
+ describe '#display_performance_graph?' do
66
+ it 'return default as false' do
67
+ expect(config.display_performance_graph?).to eq false
68
+ end
69
+
70
+ it 'returns set value' do
71
+ config.display_performance_graph = true
72
+ expect(config.display_performance_graph?).to eq true
73
+ end
74
+ end
75
+
76
+ describe '#performance_y_axis_max' do
77
+ it 'return default as 4000' do
78
+ expect(config.performance_y_axis_max).to eq 4000
79
+ end
80
+
81
+ it 'returns set value' do
82
+ config.performance_y_axis_max = 3500
83
+ expect(config.performance_y_axis_max).to eq 3500
84
+ end
85
+ end
86
+
87
+ describe '#performance_retrieve_color' do
88
+ it 'return default as #ABC3C9' do
89
+ expect(config.performance_retrieve_color).to eq '#ABC3C9'
90
+ end
91
+
92
+ it 'returns set value' do
93
+ config.performance_retrieve_color = '#FFFFFF'
94
+ expect(config.performance_retrieve_color).to eq '#FFFFFF'
95
+ end
96
+ end
97
+
98
+ describe '#performance_graph_load_color' do
99
+ it 'return default as #ABC3C9' do
100
+ expect(config.performance_graph_load_color).to eq '#E8DCD3'
101
+ end
102
+
103
+ it 'returns set value' do
104
+ config.performance_graph_load_color = '#FFFFFF'
105
+ expect(config.performance_graph_load_color).to eq '#FFFFFF'
106
+ end
107
+ end
108
+
109
+ describe '#performance_normalization_color' do
110
+ it 'return default as #ABC3C9' do
111
+ expect(config.performance_normalization_color).to eq '#CCBE9F'
112
+ end
113
+
114
+ it 'returns set value' do
115
+ config.performance_normalization_color = '#FFFFFF'
116
+ expect(config.performance_normalization_color).to eq '#FFFFFF'
117
+ end
118
+ end
119
+
120
+ describe '#performance_graph_default_time_period=' do
121
+ it 'raises exception if time_period is invalid' do
122
+ expect { config.performance_graph_default_time_period = :decade }.to raise_error ArgumentError, 'time_period must be one of :day, :month, or :year'
123
+ end
124
+
125
+ it 'sets time_period if valid' do
126
+ expect(config.performance_graph_default_time_period = :day).to eq :day
127
+ expect(config.performance_graph_default_time_period = :month).to eq :month
128
+ expect(config.performance_graph_default_time_period = :year).to eq :year
129
+ end
130
+ end
131
+
132
+ describe '#performance_graph_default_time_period' do
133
+ it 'return default as :month' do
134
+ expect(config.performance_graph_default_time_period).to eq :month
135
+ end
136
+
137
+ it 'returns set value' do
138
+ config.performance_graph_default_time_period = :day
139
+ expect(config.performance_graph_default_time_period).to eq :day
140
+ end
141
+ end
142
+
143
+ describe '#display_performance_datatable?' do
144
+ it 'return default as true' do
145
+ expect(config.display_performance_datatable?).to eq true
146
+ end
147
+
148
+ it 'returns set value' do
149
+ config.display_performance_datatable = false
150
+ expect(config.display_performance_datatable?).to eq false
151
+ end
152
+ end
153
+
154
+ describe '#performance_datatable_default_time_period=' do
155
+ it 'raises exception if time_period is invalid' do
156
+ expect { config.performance_datatable_default_time_period = :decade }.to raise_error ArgumentError, 'time_period must be one of :day, :month, :year, or :all'
157
+ end
158
+
159
+ it 'sets time_period if valid' do
160
+ expect(config.performance_datatable_default_time_period = :day).to eq :day
161
+ expect(config.performance_datatable_default_time_period = :month).to eq :month
162
+ expect(config.performance_datatable_default_time_period = :year).to eq :year
163
+ expect(config.performance_datatable_default_time_period = :all).to eq :all
164
+ end
165
+ end
166
+
167
+ describe '#performance_datatable_default_time_period' do
168
+ it 'return default as :year' do
169
+ expect(config.performance_datatable_default_time_period).to eq :year
170
+ end
171
+
172
+ it 'returns set value' do
173
+ config.performance_datatable_default_time_period = :day
174
+ expect(config.performance_datatable_default_time_period).to eq :day
175
+ end
176
+ end
177
+
178
+ describe '#performance_datatable_max_threshold' do
179
+ it 'return default as 1500 (e.g. 1.5s)' do
180
+ expect(config.performance_datatable_max_threshold).to eq 1500
181
+ end
182
+
183
+ it 'returns set value' do
184
+ config.performance_datatable_max_threshold = 1200
185
+ expect(config.performance_datatable_max_threshold).to eq 1200
186
+ end
187
+ end
188
+
189
+ describe '#performance_datatable_warning_threshold' do
190
+ it 'return default as 1000 (e.g. 1s)' do
191
+ expect(config.performance_datatable_warning_threshold).to eq 1000
192
+ end
193
+
194
+ it 'returns set value' do
195
+ config.performance_datatable_warning_threshold = 500
196
+ expect(config.performance_datatable_warning_threshold).to eq 500
197
+ end
198
+ end
199
+ end
@@ -4,9 +4,10 @@ require 'spec_helper'
4
4
  RSpec.describe QaServer do
5
5
  # rubocop:disable RSpec/MessageChain
6
6
  let(:timezone_name) { 'Eastern Time (US & Canada)' }
7
+ before { allow(described_class).to receive_message_chain(:config, :preferred_time_zone_name).and_return(timezone_name) }
8
+
7
9
  describe '.current_time' do
8
10
  before do
9
- allow(described_class).to receive_message_chain(:config, :preferred_time_zone_name).and_return(timezone_name)
10
11
  allow(Time).to receive(:now).and_return(DateTime.parse('2019-12-11 05:00:00 -0500').in_time_zone(timezone_name))
11
12
  end
12
13
 
@@ -18,32 +19,41 @@ RSpec.describe QaServer do
18
19
 
19
20
  describe '.monitoring_expires_at' do
20
21
  before do
21
- allow(described_class).to receive_message_chain(:config, :hour_offset_to_run_monitoring_tests).and_return(3)
22
+ allow(described_class).to receive_message_chain(:config, :hour_offset_to_expire_cache).and_return(3)
22
23
  end
23
24
 
24
- context 'when current hour is after offset time' do
25
+ context 'when current hour is before offset time' do
25
26
  before do
26
- allow(described_class).to receive(:current_time).and_return(DateTime.parse('2019-12-11 05:00:00 -0500').in_time_zone(timezone_name))
27
+ allow(described_class).to receive(:current_time).and_return(DateTime.parse('2019-12-11 02:54:00 -0500').in_time_zone(timezone_name))
27
28
  end
28
29
 
29
30
  it 'returns expiration on current date at offset time' do
30
- puts 'Running QaServer.monitoring_expires_at when current hour is after offset time spec'
31
- expect(described_class.monitoring_expires_at).to eq DateTime.parse('2019-12-11 03:00:00 -0500').in_time_zone(timezone_name)
31
+ expect(described_class.monitoring_expires_at).to eq DateTime.parse('2019-12-11 02:55:00 -0500').in_time_zone(timezone_name)
32
32
  end
33
33
  end
34
34
 
35
- context 'when current hour is before offset time' do
35
+ context 'when current hour is after offset time' do
36
36
  before do
37
- allow(described_class).to receive(:current_time).and_return(DateTime.parse('2019-12-11 01:00:00 -0500').in_time_zone(timezone_name))
37
+ allow(described_class).to receive(:current_time).and_return(DateTime.parse('2019-12-11 02:56:00 -0500').in_time_zone(timezone_name))
38
38
  end
39
39
 
40
40
  it 'returns expiration on previous date at offset time' do
41
- puts 'Running QaServer.monitoring_expires_at when current hour is before offset time spec'
42
- expect(described_class.monitoring_expires_at).to eq DateTime.parse('2019-12-10 03:00:00 -0500').in_time_zone(timezone_name)
41
+ expect(described_class.monitoring_expires_at).to eq DateTime.parse('2019-12-12 02:55:00 -0500').in_time_zone(timezone_name)
43
42
  end
44
43
  end
45
44
  end
46
45
 
46
+ describe '.cache_expiry' do
47
+ before do
48
+ allow(described_class).to receive_message_chain(:config, :hour_offset_to_expire_cache).and_return(3)
49
+ allow(Time).to receive(:now).and_return(DateTime.parse('2019-12-11 02:54:59 -0500').in_time_zone(timezone_name))
50
+ end
51
+
52
+ it 'returns seconds until offset time (simulates 1 second before offset time)' do
53
+ expect(described_class.cache_expiry).to eq 1.second
54
+ end
55
+ end
56
+
47
57
  # rubocop:disable RSpec/MessageSpies
48
58
  describe '.log_agent_info' do
49
59
  let(:request) { double }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qa_server
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.3.0
4
+ version: 5.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - E. Lynette Rayle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-19 00:00:00.000000000 Z
11
+ date: 2020-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: 1.0.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: deprecation
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: engine_cart
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -457,6 +471,7 @@ files:
457
471
  - lib/tasks/qa_server_tasks.rake
458
472
  - qa_server.gemspec
459
473
  - spec/.gitignore
474
+ - spec/lib/configuration_spec.rb
460
475
  - spec/lib/qa_server_spec.rb
461
476
  - spec/rails_helper.rb
462
477
  - spec/spec_helper.rb
@@ -489,6 +504,7 @@ specification_version: 4
489
504
  summary: Authority Lookup Server
490
505
  test_files:
491
506
  - spec/.gitignore
507
+ - spec/lib/configuration_spec.rb
492
508
  - spec/lib/qa_server_spec.rb
493
509
  - spec/rails_helper.rb
494
510
  - spec/spec_helper.rb