Skip to content

Commit

Permalink
[correct] quote-related offenses
Browse files Browse the repository at this point in the history
- enforced all interpolating quotes to double
- enforced all non-interpolating quotes to single
  • Loading branch information
julienemo committed Apr 5, 2020
1 parent 6802e5b commit 0b7ce5f
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 69 deletions.
9 changes: 9 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
inherit_from: .rubocop_todo.yml

Style/Documentation:
Enabled: false

Style/StringLiterals:
EnforcedStyle: single_quotes

Style/StringLiteralsInInterpolation:
EnforcedStyle: double_quotes
27 changes: 0 additions & 27 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,33 +128,6 @@ Style/SpecialGlobalVars:
Exclude:
- 'puma_worker_killer.gemspec'

# Offense count: 54
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals:
Exclude:
- 'Gemfile'
- 'lib/puma_worker_killer/puma_memory.rb'
- 'lib/puma_worker_killer/version.rb'
- 'puma_worker_killer.gemspec'
- 'test/fixtures/big.ru'
- 'test/fixtures/config/puma_worker_killer_start.rb'
- 'test/fixtures/default.ru'
- 'test/fixtures/on_calculation.ru'
- 'test/fixtures/pre_term.ru'
- 'test/fixtures/rolling_restart.ru'
- 'test/puma_worker_killer_test.rb'
- 'test/test_helper.rb'

# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiteralsInInterpolation:
Exclude:
- 'test/puma_worker_killer_test.rb'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: AllowNamedUnderscoreVariables.
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

source "https://rubygems.org"
source 'https://rubygems.org'

gemspec

Expand Down
2 changes: 1 addition & 1 deletion lib/puma_worker_killer/puma_memory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def get_master
# sorted by memory ascending (smallest first, largest last)
def set_workers
workers = {}
@master.instance_variable_get("@workers").each do |worker|
@master.instance_variable_get('@workers').each do |worker|
workers[worker] = GetProcessMem.new(worker.pid).mb
end
if workers.any?
Expand Down
2 changes: 1 addition & 1 deletion lib/puma_worker_killer/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module PumaWorkerKiller
VERSION = "0.1.1"
VERSION = '0.1.1'
end
24 changes: 12 additions & 12 deletions puma_worker_killer.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'puma_worker_killer/version'

Gem::Specification.new do |gem|
gem.name = "puma_worker_killer"
gem.name = 'puma_worker_killer'
gem.version = PumaWorkerKiller::VERSION
gem.authors = ["Richard Schneeman"]
gem.email = ["richard.schneeman+rubygems@gmail.com"]
gem.authors = ['Richard Schneeman']
gem.email = ['richard.schneeman+rubygems@gmail.com']
gem.description = %q{ Kills pumas, the code kind }
gem.summary = %q{ If you have a memory leak in your web code puma_worker_killer can keep it in check. }
gem.homepage = "https://github.com/schneems/puma_worker_killer"
gem.license = "MIT"
gem.homepage = 'https://github.com/schneems/puma_worker_killer'
gem.license = 'MIT'

gem.files = `git ls-files`.split($/)
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ["lib"]
gem.require_paths = ['lib']

gem.add_dependency "get_process_mem", "~> 0.2"
gem.add_dependency "puma", ">= 2.7", "< 5"
gem.add_development_dependency "rack", "~> 1.6"
gem.add_development_dependency "rake", "~> 10.1"
gem.add_development_dependency "test-unit", ">= 0"
gem.add_development_dependency "wait_for_it", "~> 0.1"
gem.add_dependency 'get_process_mem', '~> 0.2'
gem.add_dependency 'puma', '>= 2.7', '< 5'
gem.add_development_dependency 'rack', '~> 1.6'
gem.add_development_dependency 'rake', '~> 10.1'
gem.add_development_dependency 'test-unit', '>= 0'
gem.add_development_dependency 'wait_for_it', '~> 0.1'
end
2 changes: 1 addition & 1 deletion test/fixtures/big.ru
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

load File.expand_path("../fixture_helper.rb", __FILE__)
load File.expand_path('../fixture_helper.rb', __FILE__)

PumaWorkerKiller.start

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/config/puma_worker_killer_start.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

load File.expand_path("../../fixture_helper.rb", __FILE__)
load File.expand_path('../../fixture_helper.rb', __FILE__)

before_fork do
require 'puma_worker_killer'
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/default.ru
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

load File.expand_path("../fixture_helper.rb", __FILE__)
load File.expand_path('../fixture_helper.rb', __FILE__)

PumaWorkerKiller.start

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/on_calculation.ru
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

load File.expand_path("../fixture_helper.rb", __FILE__)
load File.expand_path('../fixture_helper.rb', __FILE__)

PumaWorkerKiller.config do |config|
config.on_calculation = lambda { |usage| puts("Current memory footprint: #{usage} mb") }
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/pre_term.ru
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

load File.expand_path("../fixture_helper.rb", __FILE__)
load File.expand_path('../fixture_helper.rb', __FILE__)

PumaWorkerKiller.config do |config|
config.pre_term = lambda { |worker| puts("About to terminate worker: #{worker.inspect}") }
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/rolling_restart.ru
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

load File.expand_path("../fixture_helper.rb", __FILE__)
load File.expand_path('../fixture_helper.rb', __FILE__)

PumaWorkerKiller.enable_rolling_restart(1) # 1 second

Expand Down
40 changes: 20 additions & 20 deletions test/puma_worker_killer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,55 @@ class PumaWorkerKillerTest < Test::Unit::TestCase
def test_starts
port = 0 # http://stackoverflow.com/questions/200484/how-do-you-find-a-free-tcp-server-port-using-ruby
command = "bundle exec puma #{fixture_path.join("default.ru")} -t 1:1 -w 2 --preload --debug -p #{port}"
options = { wait_for: "booted", timeout: 5, env: { "PUMA_FREQUENCY" => 1 } }
options = { wait_for: 'booted', timeout: 5, env: { 'PUMA_FREQUENCY' => 1 } }

WaitForIt.new(command, options) do |spawn|
assert_contains(spawn, "PumaWorkerKiller")
assert_contains(spawn, 'PumaWorkerKiller')
end
end

def test_without_preload
port = 0 # http://stackoverflow.com/questions/200484/how-do-you-find-a-free-tcp-server-port-using-ruby
command = "bundle exec puma #{fixture_path.join("default.ru")} -t 1:1 -w 2 --debug -p #{port} -C #{fixture_path.join("config/puma_worker_killer_start.rb")}"
options = { wait_for: "booted", timeout: 10, env: { "PUMA_FREQUENCY" => 1 } }
options = { wait_for: 'booted', timeout: 10, env: { 'PUMA_FREQUENCY' => 1 } }

WaitForIt.new(command, options) do |spawn|
assert_contains(spawn, "PumaWorkerKiller")
assert_contains(spawn, 'PumaWorkerKiller')
end
end

def test_kills_large_app
file = fixture_path.join("big.ru")
file = fixture_path.join('big.ru')
port = 0
command = "bundle exec puma #{file} -t 1:1 -w 2 --preload --debug -p #{port}"
options = { wait_for: "booted", timeout: 5, env: { "PUMA_FREQUENCY" => 1, 'PUMA_RAM' => 1 } }
options = { wait_for: 'booted', timeout: 5, env: { 'PUMA_FREQUENCY' => 1, 'PUMA_RAM' => 1 } }

WaitForIt.new(command, options) do |spawn|
assert_contains(spawn, "Out of memory")
assert_contains(spawn, 'Out of memory')
end
end

def test_pre_term
file = fixture_path.join("pre_term.ru")
file = fixture_path.join('pre_term.ru')
port = 0
command = "bundle exec puma #{file} -t 1:1 -w 2 --preload --debug -p #{port}"
options = { wait_for: "booted", timeout: 5, env: { "PUMA_FREQUENCY" => 1, 'PUMA_RAM' => 1 } }
options = { wait_for: 'booted', timeout: 5, env: { 'PUMA_FREQUENCY' => 1, 'PUMA_RAM' => 1 } }

WaitForIt.new(command, options) do |spawn|
assert_contains(spawn, "Out of memory")
assert_contains(spawn, "About to terminate worker:") # defined in pre_term.ru
assert_contains(spawn, 'Out of memory')
assert_contains(spawn, 'About to terminate worker:') # defined in pre_term.ru
end
end

def test_on_calculation
file = fixture_path.join("on_calculation.ru")
file = fixture_path.join('on_calculation.ru')
port = 0
command = "bundle exec puma #{file} -t 1:1 -w 2 --preload --debug -p #{port}"
options = { wait_for: "booted", timeout: 5, env: { "PUMA_FREQUENCY" => 1, 'PUMA_RAM' => 1 } }
options = { wait_for: 'booted', timeout: 5, env: { 'PUMA_FREQUENCY' => 1, 'PUMA_RAM' => 1 } }

WaitForIt.new(command, options) do |spawn|
assert_contains(spawn, "Out of memory")
assert_contains(spawn, "Current memory footprint:") # defined in on_calculate.ru
assert_contains(spawn, 'Out of memory')
assert_contains(spawn, 'Current memory footprint:') # defined in on_calculate.ru
end
end

Expand All @@ -63,23 +63,23 @@ def assert_contains(spawn, string)
end

def test_rolling_restart
file = fixture_path.join("rolling_restart.ru")
file = fixture_path.join('rolling_restart.ru')
port = 0
command = "bundle exec puma #{file} -t 1:1 -w 2 --preload --debug -p #{port}"
puts command.inspect
options = { wait_for: "booted", timeout: 15, env: {} }
options = { wait_for: 'booted', timeout: 15, env: {} }

WaitForIt.new(command, options) do |spawn|
assert_contains(spawn, "Rolling Restart")
assert_contains(spawn, 'Rolling Restart')
end
end

def test_rolling_restart_worker_kill_check
file = fixture_path.join("rolling_restart.ru")
file = fixture_path.join('rolling_restart.ru')
port = 0
command = "bundle exec puma #{file} -t 1:1 -w 1 --preload --debug -p #{port}"
puts command.inspect
options = { wait_for: "booted", timeout: 120, env: {} }
options = { wait_for: 'booted', timeout: 120, env: {} }

WaitForIt.new(command, options) do |spawn|
# at least 2 matches for TERM (so we set a timeout value longer - 120sec)
Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
require 'wait_for_it'

def fixture_path
Pathname.new(File.expand_path("../fixtures", __FILE__))
Pathname.new(File.expand_path('../fixtures', __FILE__))
end

0 comments on commit 0b7ce5f

Please sign in to comment.