Skip to content

Commit

Permalink
Merge pull request #266 from LD4P/travis
Browse files Browse the repository at this point in the history
setup travis-ci to run
  • Loading branch information
elrayle committed Dec 12, 2019
2 parents cd439ac + b9fee78 commit 82d7bc4
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 294 deletions.
8 changes: 7 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ AllCops:
- 'script/**/*'
- 'spec/test_app_templates/**/*'
- 'vendor/**/*'
- 'lib/hyrax/specs/**/*'
- 'lib/qa_server/specs/**/*'

Lint/ImplicitStringConcatenation:
Exclude:
- 'lib/generators/qa_server/**/*'

Metrics/BlockLength:
ExcludedMethods: ['included']
Exclude:
- 'qa_server.gemspec'
- 'spec/**/*.rb'
4 changes: 4 additions & 0 deletions .rubocop_fixme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ Lint/RescueException:
Lint/UnusedMethodArgument:
Exclude:
- 'app/models/qa_server/authority_scenario.rb'

Style/SpecialGlobalVars:
Exclude:
- 'tasks/qa_server_dev.rake'
35 changes: 35 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
language: ruby
sudo: required
dist: trusty

addons:
chrome: stable
cache:
bundler: true

before_install:
- gem update --system
- gem install bundler
- google-chrome-stable --headless --disable-gpu --no-sandbox --remote-debugging-port=9222 http://localhost &

rvm:
- 2.4.6
- 2.5.5
- 2.6.3

env:
global:
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true
- ENGINE_CART_RAILS_OPTIONS='--skip-git --skip-bundle --skip-listen --skip-spring --skip-yarn --skip-keeps --skip-action-cable --skip-coffee --skip-puma --skip-test'
# Travis should check every minor version in a range of supported versions, because
# rails does not follow sem-ver conventions, see http://guides.rubyonrails.org/maintenance_policy.html
# It should be sufficient to test only the latest of the patch versions for a minor version, they
# should be compatible across patch versions (only bug fixes are released in patch versions).
matrix:
- "RAILS_VERSION=5.1.7"
- "RAILS_VERSION=5.2.3"

services:
- redis-server
before_script:
- jdk_switcher use oraclejdk8
17 changes: 12 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# frozen_string_literal: true
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
source "https://rubygems.org"
# git_source(:github) { |repo| "https://github.com/#{repo}.git" }

# Declare your gem's dependencies in qa_server.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec
gemspec path: File.expand_path('..', __FILE__)

group :development, :test do
gem 'coveralls', require: false
gem 'simplecov', require: false
end

# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
Expand All @@ -15,7 +20,6 @@ gemspec
# To use a debugger
# gem 'byebug', group: [:development, :test]

# rubocop:disable Bundler/DuplicatedGem
# BEGIN ENGINE_CART BLOCK
# engine_cart: 1.1.0
# engine_cart stanza: 0.10.0
Expand All @@ -31,6 +35,7 @@ if File.exist?(file)
else
Bundler.ui.warn "[EngineCart] Unable to find test application dependencies in #{file}, using placeholder dependencies"

# rubocop:disable Bundler/DuplicatedGem
if ENV['RAILS_VERSION']
if ENV['RAILS_VERSION'] == 'edge'
gem 'rails', github: 'rails/rails'
Expand All @@ -41,15 +46,17 @@ else
end

case ENV['RAILS_VERSION']
when /^5.[12]/
gem 'sass-rails', '~> 5.0'
when /^4.2/
gem 'coffee-rails', '~> 4.1.0'
gem 'responders', '~> 2.0'
gem 'sass-rails', '5.1.6'
when /^4.[01]/
gem 'sass-rails', '5.1.6'
end
# rubocop:enable Bundler/DuplicatedGem
end
# END ENGINE_CART BLOCK
# rubocop:enable Bundler/DuplicatedGem

eval_gemfile File.expand_path('spec/test_app_templates/Gemfile.extra', File.dirname(__FILE__)) unless File.exist?(file)
9 changes: 3 additions & 6 deletions app/models/qa_server/performance_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@ def write_all
size_before = @cache.size
@cache.each do |id, entry|
next if incomplete? entry
QaServer::PerformanceHistory.create(dt_stamp: entry[:dt_stamp],
authority: entry[:authority],
action: entry[:action],
action_time_ms: entry[:action_time_ms],
size_bytes: entry[:size_bytes],
retrieve_time_ms: entry[:retrieve_time_ms],
QaServer::PerformanceHistory.create(dt_stamp: entry[:dt_stamp], authority: entry[:authority],
action: entry[:action], action_time_ms: entry[:action_time_ms],
size_bytes: entry[:size_bytes], retrieve_time_ms: entry[:retrieve_time_ms],
graph_load_time_ms: entry[:graph_load_time_ms],
normalization_time_ms: entry[:normalization_time_ms])
@cache.delete(id)
Expand Down
2 changes: 1 addition & 1 deletion app/prepends/prepended_linked_data/find_term.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module PrependedLinkedData::FindTerm
# Override Qa::Authorities::LinkedData::FindTerm#find method
# @return [Hash] single term results in requested format
def find(id, request_header: {}, language: nil, replacements: {}, subauth: nil, format: nil, performance_data: false) # rubocop:disable Metrics/ParameterLists
def find(id, request_header: {}, language: nil, replacements: {}, subauth: nil, format: nil, performance_data: false) # rubocop:disable Metrics/ParameterLists, Metrics/CyclomaticComplexity
return super if QaServer.config.suppress_performance_gathering

start_time_s = QaServer.current_time_s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def data_table_for(authority_data, action)

def unsupported_action?(stats)
values = stats.values
return true if values.all? &:zero?
return true if values.all?(&:zero?)
values.any? { |v| v.respond_to?(:nan?) && v.nan? }
end

Expand Down
4 changes: 3 additions & 1 deletion app/services/qa_server/performance_graphing_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def graph_filename(authority_name, action, time_period)

def rework_performance_data_for_gruff(performance_data, label_key)
labels = {}
full_load_data = []
# full_load_data = []
retrieve_data = []
graph_load_data = []
normalization_data = []
Expand All @@ -100,7 +100,9 @@ def graph_load_time(data)
# create the graph using the old :load stat when both :retrieve and :graph_load are 0. If the value truly
# is 0, then :load will also be 0.
# NOTE: It's ok to use AVG_RETR for the retrieve data point because it is 0.
# rubocop:disable Style/TernaryParentheses
(data[STATS][AVG_RETR].zero? && data[STATS][AVG_GRPH].zero?) ? data[STATS][AVG_LOAD] : data[STATS][AVG_GRPH]
# rubocop:enable Style/TernaryParentheses
end

def performance_graph_theme(g, x_axis_label)
Expand Down
2 changes: 1 addition & 1 deletion lib/qa_server/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def preferred_time_zone_name
# For preferred_time_zone_name of PT, use 0 for slow down at midnight PT/3am ET
attr_writer :hour_offset_to_run_monitoring_tests
def hour_offset_to_run_monitoring_tests
hour_offset_to_run_monitoring_tests ||= 3
@hour_offset_to_run_monitoring_tests ||= 3
end

# Displays a graph of historical test data when true
Expand Down
8 changes: 8 additions & 0 deletions qa_server.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,19 @@ Gem::Specification.new do |spec|
# spec.add_development_dependency 'chromedriver-helper', '~> 2.1'
spec.add_development_dependency 'engine_cart', '~> 2.0'
spec.add_development_dependency "factory_bot", '~> 4.4'
spec.add_development_dependency 'simplecov'
spec.add_development_dependency 'sqlite3'
spec.add_development_dependency 'rails-controller-testing', '~> 1'
spec.add_development_dependency 'rspec-activemodel-mocks', '~> 1.0'
spec.add_development_dependency 'rspec-its', '~> 1.1'
spec.add_development_dependency 'rspec-rails', '~> 3.1'
spec.add_development_dependency 'selenium-webdriver'
spec.add_development_dependency 'webdrivers', '~> 3.0'
spec.add_development_dependency 'webmock'

########################################################
# Temporarily pinned dependencies. INCLUDE EXPLANATIONS.
#
# Pin sass-rails to 5.x because rails 5.x apps have this same dependency in their generated Gemfiles
spec.add_dependency 'sass-rails', '~> 5.0'
end
22 changes: 14 additions & 8 deletions spec/lib/qa_server_spec.rb
Original file line number Diff line number Diff line change
@@ -1,41 +1,47 @@
# frozen_string_literal: true
require 'spec_helper'

RSpec.describe QaServer do
# rubocop:disable RSpec/MessageChain
let(:timezone_name) { 'Eastern Time (US & Canada)' }
describe '.current_time' do
before do
allow(QaServer).to receive_message_chain(:config, :preferred_time_zone_name).and_return('Eastern Time (US & Canada)')
allow(Time).to receive(:now).and_return(DateTime.parse('2019-12-11 05:00:00 -0500'))
allow(described_class).to receive_message_chain(:config, :preferred_time_zone_name).and_return(timezone_name)
allow(Time).to receive(:now).and_return(DateTime.parse('2019-12-11 05:00:00 -0500').in_time_zone(timezone_name))
end

it 'returns the time in the preferred time zone' do
puts 'Running QaServer.current_time spec'
expect(described_class.current_time.zone).to eq 'EST'
end
end


describe '.monitoring_expires_at' do
before do
allow(QaServer).to receive_message_chain(:config, :hour_offset_to_run_monitoring_tests).and_return(3)
allow(described_class).to receive_message_chain(:config, :hour_offset_to_run_monitoring_tests).and_return(3)
end

context 'when current hour is after offset time' do
before do
allow(QaServer).to receive(:current_time).and_return(DateTime.parse('2019-12-11 05:00:00 -0500'))
allow(described_class).to receive(:current_time).and_return(DateTime.parse('2019-12-11 05:00:00 -0500').in_time_zone(timezone_name))
end

it 'returns expiration on current date at offset time' do
expect(described_class.monitoring_expires_at).to eq DateTime.parse('2019-12-11 03:00:00 -0500')
puts 'Running QaServer.monitoring_expires_at when current hour is after offset time spec'
expect(described_class.monitoring_expires_at).to eq DateTime.parse('2019-12-11 03:00:00 -0500').in_time_zone(timezone_name)
end
end

context 'when current hour is before offset time' do
before do
allow(QaServer).to receive(:current_time).and_return(DateTime.parse('2019-12-11 01:00:00 -0500'))
allow(described_class).to receive(:current_time).and_return(DateTime.parse('2019-12-11 01:00:00 -0500').in_time_zone(timezone_name))
end

it 'returns expiration on previous date at offset time' do
expect(described_class.monitoring_expires_at).to eq DateTime.parse('2019-12-10 03:00:00 -0500')
puts 'Running QaServer.monitoring_expires_at when current hour is before offset time spec'
expect(described_class.monitoring_expires_at).to eq DateTime.parse('2019-12-10 03:00:00 -0500').in_time_zone(timezone_name)
end
end
end
# rubocop:enable RSpec/MessageChain
end
Loading

0 comments on commit 82d7bc4

Please sign in to comment.