mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Update standard rules (#5360)
* update standard rules and run standard:fix * Fix more standard errors * standardize
This commit is contained in:
parent
2d743d7a70
commit
55ced28181
40 changed files with 143 additions and 183 deletions
|
@ -2,14 +2,14 @@ ruby_version: 2.5.0
|
||||||
fix: true
|
fix: true
|
||||||
parallel: true
|
parallel: true
|
||||||
ignore:
|
ignore:
|
||||||
- test/**/*
|
|
||||||
- examples/**/*
|
|
||||||
- myapp/**/*
|
|
||||||
- 'lib/sidekiq.rb':
|
- 'lib/sidekiq.rb':
|
||||||
- Lint/InheritException
|
- Lint/InheritException
|
||||||
- 'lib/sidekiq/extensions/**/*':
|
- 'lib/sidekiq/extensions/**/*':
|
||||||
- Style/MissingRespondToMissing
|
- Style/MissingRespondToMissing
|
||||||
- 'lib/**/*':
|
- '**/*':
|
||||||
- Lint/RescueException
|
- Lint/RescueException
|
||||||
- Security/YAMLLoad
|
- Security/YAMLLoad
|
||||||
- Style/GlobalVars
|
- Style/GlobalVars
|
||||||
|
- 'test/test*.rb':
|
||||||
|
- Lint/ConstantDefinitionInBlock
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require 'sidekiq'
|
require "sidekiq"
|
||||||
|
|
||||||
# Start up sidekiq via
|
# Start up sidekiq via
|
||||||
# ./bin/sidekiq -r ./examples/por.rb
|
# ./bin/sidekiq -r ./examples/por.rb
|
||||||
|
@ -10,7 +10,7 @@ require 'sidekiq'
|
||||||
class PlainOldRuby
|
class PlainOldRuby
|
||||||
include Sidekiq::Job
|
include Sidekiq::Job
|
||||||
|
|
||||||
def perform(how_hard="super hard", how_long=1)
|
def perform(how_hard = "super hard", how_long = 1)
|
||||||
sleep how_long
|
sleep how_long
|
||||||
puts "Workin' #{how_hard}"
|
puts "Workin' #{how_hard}"
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
source 'https://rubygems.org'
|
source "https://rubygems.org"
|
||||||
|
|
||||||
gem 'sidekiq', :path => '..'
|
gem "sidekiq", path: ".."
|
||||||
gem 'rails'
|
gem "rails"
|
||||||
gem 'puma'
|
gem "puma"
|
||||||
|
|
||||||
gem "redis-client"
|
gem "redis-client"
|
||||||
|
|
||||||
# Ubuntu required packages to install rails
|
# Ubuntu required packages to install rails
|
||||||
# apt-get install build-essential patch ruby-dev zlib1g-dev liblzma-dev libsqlite3-dev
|
# apt-get install build-essential patch ruby-dev zlib1g-dev liblzma-dev libsqlite3-dev
|
||||||
platforms :ruby do
|
platforms :ruby do
|
||||||
gem 'sqlite3'
|
gem "sqlite3"
|
||||||
end
|
end
|
||||||
|
|
||||||
gem 'after_commit_everywhere'
|
gem "after_commit_everywhere"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
||||||
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
||||||
|
|
||||||
require_relative 'config/application'
|
require_relative "config/application"
|
||||||
|
|
||||||
Rails.application.load_tasks
|
Rails.application.load_tasks
|
||||||
|
|
|
@ -3,42 +3,42 @@ class WorkController < ApplicationController
|
||||||
@count = rand(100)
|
@count = rand(100)
|
||||||
puts "Adding #{@count} jobs"
|
puts "Adding #{@count} jobs"
|
||||||
@count.times do |x|
|
@count.times do |x|
|
||||||
HardWorker.perform_async('bubba', 0.01, x)
|
HardWorker.perform_async("bubba", 0.01, x)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def email
|
def email
|
||||||
UserMailer.delay_for(30.seconds).greetings(Time.now)
|
UserMailer.delay_for(30.seconds).greetings(Time.now)
|
||||||
render :plain => 'enqueued'
|
render plain: "enqueued"
|
||||||
end
|
end
|
||||||
|
|
||||||
def bulk
|
def bulk
|
||||||
Sidekiq::Client.push_bulk('class' => HardWorker,
|
Sidekiq::Client.push_bulk("class" => HardWorker,
|
||||||
'args' => [['bob', 1, 1], ['mike', 1, 2]])
|
"args" => [["bob", 1, 1], ["mike", 1, 2]])
|
||||||
render :plain => 'enbulked'
|
render plain: "enbulked"
|
||||||
end
|
end
|
||||||
|
|
||||||
def long
|
def long
|
||||||
50.times do |x|
|
50.times do |x|
|
||||||
HardWorker.perform_async('bob', 15, x)
|
HardWorker.perform_async("bob", 15, x)
|
||||||
end
|
end
|
||||||
render :plain => 'enqueued'
|
render plain: "enqueued"
|
||||||
end
|
end
|
||||||
|
|
||||||
def crash
|
def crash
|
||||||
HardWorker.perform_async('crash', 1, Time.now.to_f)
|
HardWorker.perform_async("crash", 1, Time.now.to_f)
|
||||||
render :plain => 'enqueued'
|
render plain: "enqueued"
|
||||||
end
|
end
|
||||||
|
|
||||||
def delayed_post
|
def delayed_post
|
||||||
p = Post.first
|
p = Post.first
|
||||||
unless p
|
if p
|
||||||
p = Post.create!(:title => "Title!", :body => 'Body!')
|
|
||||||
p2 = Post.create!(:title => "Other!", :body => 'Second Body!')
|
|
||||||
else
|
|
||||||
p2 = Post.second
|
p2 = Post.second
|
||||||
|
else
|
||||||
|
p = Post.create!(title: "Title!", body: "Body!")
|
||||||
|
p2 = Post.create!(title: "Other!", body: "Second Body!")
|
||||||
end
|
end
|
||||||
p.delay.long_method(p2)
|
p.delay.long_method(p2)
|
||||||
render :plain => 'enqueued'
|
render plain: "enqueued"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,6 +4,6 @@ class UserMailer < ActionMailer::Base
|
||||||
def greetings(now)
|
def greetings(now)
|
||||||
@now = now
|
@now = now
|
||||||
@hostname = `hostname`.strip
|
@hostname = `hostname`.strip
|
||||||
mail(:to => 'mperham@gmail.com', :subject => 'Ahoy Matey!')
|
mail(to: "mperham@gmail.com", subject: "Ahoy Matey!")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class Post < ActiveRecord::Base
|
class Post < ActiveRecord::Base
|
||||||
def long_method(other_post)
|
def long_method(other_post)
|
||||||
puts "Running long method with #{self.id} and #{other_post.id}"
|
puts "Running long method with #{id} and #{other_post.id}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.testing
|
def self.testing
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
class HardWorker
|
class HardWorker
|
||||||
include Sidekiq::Worker
|
include Sidekiq::Worker
|
||||||
sidekiq_options :backtrace => 5
|
sidekiq_options backtrace: 5
|
||||||
|
|
||||||
def perform(name, count, salt)
|
def perform(name, count, salt)
|
||||||
raise name if name == 'crash'
|
raise name if name == "crash"
|
||||||
logger.info Time.now
|
logger.info Time.now
|
||||||
sleep count
|
sleep count
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
|
||||||
load Gem.bin_path('bundler', 'bundle')
|
load Gem.bin_path("bundler", "bundle")
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
begin
|
begin
|
||||||
load File.expand_path('../spring', __FILE__)
|
load File.expand_path("../spring", __FILE__)
|
||||||
rescue LoadError => e
|
rescue LoadError => e
|
||||||
raise unless e.message.include?('spring')
|
raise unless e.message.include?("spring")
|
||||||
end
|
end
|
||||||
APP_PATH = File.expand_path('../config/application', __dir__)
|
APP_PATH = File.expand_path("../config/application", __dir__)
|
||||||
require_relative '../config/boot'
|
require_relative "../config/boot"
|
||||||
require 'rails/commands'
|
require "rails/commands"
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
begin
|
begin
|
||||||
load File.expand_path('../spring', __FILE__)
|
load File.expand_path("../spring", __FILE__)
|
||||||
rescue LoadError => e
|
rescue LoadError => e
|
||||||
raise unless e.message.include?('spring')
|
raise unless e.message.include?("spring")
|
||||||
end
|
end
|
||||||
require_relative '../config/boot'
|
require_relative "../config/boot"
|
||||||
require 'rake'
|
require "rake"
|
||||||
Rake.application.run
|
Rake.application.run
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
#!/usr/bin/env ruby
|
|
||||||
require 'fileutils'
|
|
||||||
include FileUtils
|
|
||||||
|
|
||||||
# path to your application root.
|
|
||||||
APP_ROOT = File.expand_path('..', __dir__)
|
|
||||||
|
|
||||||
def system!(*args)
|
|
||||||
system(*args) || abort("\n== Command #{args} failed ==")
|
|
||||||
end
|
|
||||||
|
|
||||||
chdir APP_ROOT do
|
|
||||||
# This script is a starting point to setup your application.
|
|
||||||
# Add necessary setup steps to this file.
|
|
||||||
|
|
||||||
puts '== Installing dependencies =='
|
|
||||||
system! 'gem install bundler --conservative'
|
|
||||||
system('bundle check') || system!('bundle install')
|
|
||||||
|
|
||||||
# Install JavaScript dependencies if using Yarn
|
|
||||||
# system('bin/yarn')
|
|
||||||
|
|
||||||
# puts "\n== Copying sample files =="
|
|
||||||
# unless File.exist?('config/database.yml')
|
|
||||||
# cp 'config/database.yml.sample', 'config/database.yml'
|
|
||||||
# end
|
|
||||||
|
|
||||||
puts "\n== Preparing database =="
|
|
||||||
system! 'bin/rails db:setup'
|
|
||||||
|
|
||||||
puts "\n== Removing old logs and tempfiles =="
|
|
||||||
system! 'bin/rails log:clear tmp:clear'
|
|
||||||
|
|
||||||
puts "\n== Restarting application server =="
|
|
||||||
system! 'bin/rails restart'
|
|
||||||
end
|
|
|
@ -1,5 +1,5 @@
|
||||||
# This file is used by Rack-based servers to start the application.
|
# This file is used by Rack-based servers to start the application.
|
||||||
|
|
||||||
require_relative 'config/environment'
|
require_relative "config/environment"
|
||||||
|
|
||||||
run Rails.application
|
run Rails.application
|
||||||
|
|
|
@ -1,18 +1,16 @@
|
||||||
require_relative 'boot'
|
require_relative "boot"
|
||||||
|
|
||||||
require 'rails'
|
require "rails"
|
||||||
%w(
|
%w[
|
||||||
active_record/railtie
|
active_record/railtie
|
||||||
action_controller/railtie
|
action_controller/railtie
|
||||||
action_view/railtie
|
action_view/railtie
|
||||||
action_mailer/railtie
|
action_mailer/railtie
|
||||||
active_job/railtie
|
active_job/railtie
|
||||||
sprockets/railtie
|
sprockets/railtie
|
||||||
).each do |railtie|
|
].each do |railtie|
|
||||||
begin
|
require railtie
|
||||||
require railtie
|
rescue LoadError
|
||||||
rescue LoadError
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Require the gems listed in Gemfile, including any gems
|
# Require the gems listed in Gemfile, including any gems
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
|
||||||
|
|
||||||
require 'bundler/setup' # Set up gems listed in the Gemfile.
|
require "bundler/setup" # Set up gems listed in the Gemfile.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# Load the Rails application.
|
# Load the Rails application.
|
||||||
require_relative 'application'
|
require_relative "application"
|
||||||
|
|
||||||
# Initialize the Rails application.
|
# Initialize the Rails application.
|
||||||
Rails.application.initialize!
|
Rails.application.initialize!
|
||||||
|
|
|
@ -14,12 +14,12 @@ Rails.application.configure do
|
||||||
|
|
||||||
# Enable/disable caching. By default caching is disabled.
|
# Enable/disable caching. By default caching is disabled.
|
||||||
# Run rails dev:cache to toggle caching.
|
# Run rails dev:cache to toggle caching.
|
||||||
if Rails.root.join('tmp', 'caching-dev.txt').exist?
|
if Rails.root.join("tmp", "caching-dev.txt").exist?
|
||||||
config.action_controller.perform_caching = true
|
config.action_controller.perform_caching = true
|
||||||
|
|
||||||
config.cache_store = :memory_store
|
config.cache_store = :memory_store
|
||||||
config.public_file_server.headers = {
|
config.public_file_server.headers = {
|
||||||
'Cache-Control' => "public, max-age=#{2.days.to_i}"
|
"Cache-Control" => "public, max-age=#{2.days.to_i}"
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
config.action_controller.perform_caching = false
|
config.action_controller.perform_caching = false
|
||||||
|
@ -28,7 +28,7 @@ Rails.application.configure do
|
||||||
end
|
end
|
||||||
|
|
||||||
# Store uploaded files on the local file system (see config/storage.yml for options)
|
# Store uploaded files on the local file system (see config/storage.yml for options)
|
||||||
#config.active_storage.service = :local
|
# config.active_storage.service = :local
|
||||||
|
|
||||||
# Don't care if the mailer can't send.
|
# Don't care if the mailer can't send.
|
||||||
config.action_mailer.raise_delivery_errors = false
|
config.action_mailer.raise_delivery_errors = false
|
||||||
|
@ -57,5 +57,5 @@ Rails.application.configure do
|
||||||
|
|
||||||
# Use an evented file watcher to asynchronously detect changes in source code,
|
# Use an evented file watcher to asynchronously detect changes in source code,
|
||||||
# routes, locales, etc. This feature depends on the listen gem.
|
# routes, locales, etc. This feature depends on the listen gem.
|
||||||
#config.file_watcher = ActiveSupport::EventedFileUpdateChecker
|
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,7 +11,7 @@ Rails.application.configure do
|
||||||
config.eager_load = true
|
config.eager_load = true
|
||||||
|
|
||||||
# Full error reports are disabled and caching is turned on.
|
# Full error reports are disabled and caching is turned on.
|
||||||
config.consider_all_requests_local = false
|
config.consider_all_requests_local = false
|
||||||
config.action_controller.perform_caching = true
|
config.action_controller.perform_caching = true
|
||||||
|
|
||||||
# Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
|
# Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
|
||||||
|
@ -20,7 +20,7 @@ Rails.application.configure do
|
||||||
|
|
||||||
# Disable serving static files from the `/public` folder by default since
|
# Disable serving static files from the `/public` folder by default since
|
||||||
# Apache or NGINX already handles this.
|
# Apache or NGINX already handles this.
|
||||||
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
|
config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present?
|
||||||
|
|
||||||
# Compress JavaScripts and CSS.
|
# Compress JavaScripts and CSS.
|
||||||
config.assets.js_compressor = :uglifier
|
config.assets.js_compressor = :uglifier
|
||||||
|
@ -39,7 +39,7 @@ Rails.application.configure do
|
||||||
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
|
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
|
||||||
|
|
||||||
# Store uploaded files on the local file system (see config/storage.yml for options)
|
# Store uploaded files on the local file system (see config/storage.yml for options)
|
||||||
#config.active_storage.service = :local
|
# config.active_storage.service = :local
|
||||||
|
|
||||||
# Mount Action Cable outside main process or domain
|
# Mount Action Cable outside main process or domain
|
||||||
# config.action_cable.mount_path = nil
|
# config.action_cable.mount_path = nil
|
||||||
|
@ -54,7 +54,7 @@ Rails.application.configure do
|
||||||
config.log_level = :debug
|
config.log_level = :debug
|
||||||
|
|
||||||
# Prepend all log lines with the following tags.
|
# Prepend all log lines with the following tags.
|
||||||
config.log_tags = [ :request_id ]
|
config.log_tags = [:request_id]
|
||||||
|
|
||||||
# Use a different cache store in production.
|
# Use a different cache store in production.
|
||||||
# config.cache_store = :mem_cache_store
|
# config.cache_store = :mem_cache_store
|
||||||
|
@ -84,9 +84,9 @@ Rails.application.configure do
|
||||||
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
|
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
|
||||||
|
|
||||||
if ENV["RAILS_LOG_TO_STDOUT"].present?
|
if ENV["RAILS_LOG_TO_STDOUT"].present?
|
||||||
logger = ActiveSupport::Logger.new(STDOUT)
|
logger = ActiveSupport::Logger.new($stdout)
|
||||||
logger.formatter = config.log_formatter
|
logger.formatter = config.log_formatter
|
||||||
config.logger = ActiveSupport::TaggedLogging.new(logger)
|
config.logger = ActiveSupport::TaggedLogging.new(logger)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Do not dump schema after migrations.
|
# Do not dump schema after migrations.
|
||||||
|
|
|
@ -15,11 +15,11 @@ Rails.application.configure do
|
||||||
# Configure public file server for tests with Cache-Control for performance.
|
# Configure public file server for tests with Cache-Control for performance.
|
||||||
config.public_file_server.enabled = true
|
config.public_file_server.enabled = true
|
||||||
config.public_file_server.headers = {
|
config.public_file_server.headers = {
|
||||||
'Cache-Control' => "public, max-age=#{1.hour.to_i}"
|
"Cache-Control" => "public, max-age=#{1.hour.to_i}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Show full error reports and disable caching.
|
# Show full error reports and disable caching.
|
||||||
config.consider_all_requests_local = true
|
config.consider_all_requests_local = true
|
||||||
config.action_controller.perform_caching = false
|
config.action_controller.perform_caching = false
|
||||||
|
|
||||||
# Raise exceptions instead of rendering exception templates.
|
# Raise exceptions instead of rendering exception templates.
|
||||||
|
@ -29,7 +29,7 @@ Rails.application.configure do
|
||||||
config.action_controller.allow_forgery_protection = false
|
config.action_controller.allow_forgery_protection = false
|
||||||
|
|
||||||
# Store uploaded files on the local file system in a temporary directory
|
# Store uploaded files on the local file system in a temporary directory
|
||||||
#config.active_storage.service = :test
|
# config.active_storage.service = :test
|
||||||
|
|
||||||
config.action_mailer.perform_caching = false
|
config.action_mailer.perform_caching = false
|
||||||
|
|
||||||
|
|
|
@ -4,4 +4,4 @@
|
||||||
# If you change this key, all old signed cookies will become invalid!
|
# If you change this key, all old signed cookies will become invalid!
|
||||||
# Make sure the secret is at least 30 characters and all random,
|
# Make sure the secret is at least 30 characters and all random,
|
||||||
# no regular words or you'll be exposed to dictionary attacks.
|
# no regular words or you'll be exposed to dictionary attacks.
|
||||||
Myapp::Application.config.secret_token = 'bdd335500c81ba1f279f9dd8198d1f334445d0193168ed73c1282502180dca27e3e102ec345e99b2acac6a63f7fe29da69c60cc9e76e8da34fb5d4989db24cd8'
|
Myapp::Application.config.secret_token = "bdd335500c81ba1f279f9dd8198d1f334445d0193168ed73c1282502180dca27e3e102ec345e99b2acac6a63f7fe29da69c60cc9e76e8da34fb5d4989db24cd8"
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
# Be sure to restart your server when you modify this file.
|
# Be sure to restart your server when you modify this file.
|
||||||
|
|
||||||
Rails.application.config.session_store :cookie_store, key: '_myapp_session'
|
Rails.application.config.session_store :cookie_store, key: "_myapp_session"
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
Sidekiq.configure_client do |config|
|
Sidekiq.configure_client do |config|
|
||||||
config.redis = { :size => 2 }
|
config.redis = {size: 2}
|
||||||
end
|
end
|
||||||
Sidekiq.configure_server do |config|
|
Sidekiq.configure_server do |config|
|
||||||
config.on(:startup) { }
|
config.on(:startup) {}
|
||||||
config.on(:quiet) { }
|
config.on(:quiet) {}
|
||||||
config.on(:shutdown) do
|
config.on(:shutdown) do
|
||||||
#result = RubyProf.stop
|
# result = RubyProf.stop
|
||||||
|
|
||||||
## Write the results to a file
|
## Write the results to a file
|
||||||
## Requires railsexpress patched MRI build
|
## Requires railsexpress patched MRI build
|
||||||
# brew install qcachegrind
|
# brew install qcachegrind
|
||||||
#File.open("callgrind.profile", "w") do |f|
|
# File.open("callgrind.profile", "w") do |f|
|
||||||
#RubyProf::CallTreePrinter.new(result).print(f, :min_percent => 1)
|
# RubyProf::CallTreePrinter.new(result).print(f, :min_percent => 1)
|
||||||
#end
|
# end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -47,4 +47,4 @@ end
|
||||||
require "sidekiq/middleware/current_attributes"
|
require "sidekiq/middleware/current_attributes"
|
||||||
Sidekiq::CurrentAttributes.persist(Myapp::Current) # Your AS::CurrentAttributes singleton
|
Sidekiq::CurrentAttributes.persist(Myapp::Current) # Your AS::CurrentAttributes singleton
|
||||||
|
|
||||||
# Sidekiq.transactional_push!
|
# Sidekiq.transactional_push!
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
# turns off browser asset caching so we can test CSS changes quickly
|
# turns off browser asset caching so we can test CSS changes quickly
|
||||||
ENV['SIDEKIQ_WEB_TESTING'] = '1'
|
ENV["SIDEKIQ_WEB_TESTING"] = "1"
|
||||||
|
|
||||||
require 'sidekiq/web'
|
require "sidekiq/web"
|
||||||
Sidekiq::Web.app_url = '/'
|
Sidekiq::Web.app_url = "/"
|
||||||
|
|
||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
mount Sidekiq::Web => '/sidekiq'
|
mount Sidekiq::Web => "/sidekiq"
|
||||||
get "work" => "work#index"
|
get "work" => "work#index"
|
||||||
get "work/email" => "work#email"
|
get "work/email" => "work#email"
|
||||||
get "work/post" => "work#delayed_post"
|
get "work/post" => "work#delayed_post"
|
||||||
|
|
|
@ -11,12 +11,10 @@
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2012_01_23_214055) do
|
ActiveRecord::Schema.define(version: 2012_01_23_214055) do
|
||||||
|
|
||||||
create_table "posts", force: :cascade do |t|
|
create_table "posts", force: :cascade do |t|
|
||||||
t.string "title"
|
t.string "title"
|
||||||
t.string "body"
|
t.string "body"
|
||||||
t.datetime "created_at", precision: 6, null: false
|
t.datetime "created_at", precision: 6, null: false
|
||||||
t.datetime "updated_at", precision: 6, null: false
|
t.datetime "updated_at", precision: 6, null: false
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
||||||
|
|
||||||
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
APP_PATH = File.expand_path("../../config/application", __FILE__)
|
||||||
require File.expand_path('../../config/boot', __FILE__)
|
require File.expand_path("../../config/boot", __FILE__)
|
||||||
require 'rails/commands'
|
require "rails/commands"
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
# Easiest way to run Sidekiq::Web.
|
# Easiest way to run Sidekiq::Web.
|
||||||
# Run with "bundle exec rackup simple.ru"
|
# Run with "bundle exec rackup simple.ru"
|
||||||
|
|
||||||
require 'sidekiq/web'
|
require "sidekiq/web"
|
||||||
|
|
||||||
# A Web process always runs as client, no need to configure server
|
# A Web process always runs as client, no need to configure server
|
||||||
Sidekiq.configure_client do |config|
|
Sidekiq.configure_client do |config|
|
||||||
config.redis = { url: 'redis://localhost:6379/0', size: 1 }
|
config.redis = {url: "redis://localhost:6379/0", size: 1}
|
||||||
end
|
end
|
||||||
|
|
||||||
Sidekiq::Client.push('class' => "HardWorker", 'args' => [])
|
Sidekiq::Client.push("class" => "HardWorker", "args" => [])
|
||||||
|
|
||||||
# In a multi-process deployment, all Web UI instances should share
|
# In a multi-process deployment, all Web UI instances should share
|
||||||
# this secret key so they can all decode the encrypted browser cookies
|
# this secret key so they can all decode the encrypted browser cookies
|
||||||
|
|
|
@ -28,7 +28,7 @@ end
|
||||||
|
|
||||||
ENV["REDIS_URL"] ||= "redis://localhost/15"
|
ENV["REDIS_URL"] ||= "redis://localhost/15"
|
||||||
|
|
||||||
Sidekiq.logger = ::Logger.new(STDOUT)
|
Sidekiq.logger = ::Logger.new($stdout)
|
||||||
Sidekiq.logger.level = Logger::ERROR
|
Sidekiq.logger.level = Logger::ERROR
|
||||||
|
|
||||||
if ENV["SIDEKIQ_REDIS_CLIENT"]
|
if ENV["SIDEKIQ_REDIS_CLIENT"]
|
||||||
|
|
|
@ -66,7 +66,7 @@ describe "Actors" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def await(timeout=0.5)
|
def await(timeout = 0.5)
|
||||||
@mutex.synchronize do
|
@mutex.synchronize do
|
||||||
yield
|
yield
|
||||||
@cond.wait(@mutex, timeout)
|
@cond.wait(@mutex, timeout)
|
||||||
|
|
|
@ -20,7 +20,7 @@ describe Sidekiq::CLI do
|
||||||
end
|
end
|
||||||
|
|
||||||
subject do
|
subject do
|
||||||
Sidekiq::CLI.new.tap {|c| c.config = config }
|
Sidekiq::CLI.new.tap { |c| c.config = config }
|
||||||
end
|
end
|
||||||
|
|
||||||
def logdev
|
def logdev
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
require_relative "./helper"
|
require_relative "./helper"
|
||||||
require "sidekiq/web/csrf_protection"
|
require "sidekiq/web/csrf_protection"
|
||||||
|
|
||||||
describe 'Csrf' do
|
describe "Csrf" do
|
||||||
def session
|
def session
|
||||||
@session ||= {}
|
@session ||= {}
|
||||||
end
|
end
|
||||||
|
@ -24,7 +24,7 @@ describe 'Csrf' do
|
||||||
Sidekiq::Web::CsrfProtection.new(block).call(env)
|
Sidekiq::Web::CsrfProtection.new(block).call(env)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'get' do
|
it "get" do
|
||||||
ok = [200, {}, ["OK"]]
|
ok = [200, {}, ["OK"]]
|
||||||
first = 1
|
first = 1
|
||||||
second = 1
|
second = 1
|
||||||
|
@ -48,7 +48,7 @@ describe 'Csrf' do
|
||||||
refute_equal first, second
|
refute_equal first, second
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'bad post' do
|
it "bad post" do
|
||||||
result = call(env(:post)) do
|
result = call(env(:post)) do
|
||||||
raise "Shouldnt be called"
|
raise "Shouldnt be called"
|
||||||
end
|
end
|
||||||
|
@ -60,7 +60,7 @@ describe 'Csrf' do
|
||||||
assert_match(/attack prevented/, @logio.string)
|
assert_match(/attack prevented/, @logio.string)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'succeeds with good token' do
|
it "succeeds with good token" do
|
||||||
# Make a GET to set up the session with a good token
|
# Make a GET to set up the session with a good token
|
||||||
goodtoken = call(env) do |envy|
|
goodtoken = call(env) do |envy|
|
||||||
envy[:csrf_token]
|
envy[:csrf_token]
|
||||||
|
@ -76,7 +76,7 @@ describe 'Csrf' do
|
||||||
assert_equal ["OK"], result[2]
|
assert_equal ["OK"], result[2]
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'fails with bad token' do
|
it "fails with bad token" do
|
||||||
# Make a POST with a known bad token
|
# Make a POST with a known bad token
|
||||||
result = call(env(:post, "authenticity_token" => "N0QRBD34tU61d7fi+0ZaF/35JLW/9K+8kk8dc1TZoK/0pTl7GIHap5gy7BWGsoKlzbMLRp1yaDpCDFwTJtxWAg==")) do
|
result = call(env(:post, "authenticity_token" => "N0QRBD34tU61d7fi+0ZaF/35JLW/9K+8kk8dc1TZoK/0pTl7GIHap5gy7BWGsoKlzbMLRp1yaDpCDFwTJtxWAg==")) do
|
||||||
raise "shouldnt be called"
|
raise "shouldnt be called"
|
||||||
|
@ -86,7 +86,7 @@ describe 'Csrf' do
|
||||||
assert_equal ["Forbidden"], result[2]
|
assert_equal ["Forbidden"], result[2]
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'empty session post' do
|
it "empty session post" do
|
||||||
# Make a GET to set up the session with a good token
|
# Make a GET to set up the session with a good token
|
||||||
goodtoken = call(env) do |envy|
|
goodtoken = call(env) do |envy|
|
||||||
envy[:csrf_token]
|
envy[:csrf_token]
|
||||||
|
@ -102,7 +102,7 @@ describe 'Csrf' do
|
||||||
assert_equal ["Forbidden"], result[2]
|
assert_equal ["Forbidden"], result[2]
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'empty csrf session post' do
|
it "empty csrf session post" do
|
||||||
# Make a GET to set up the session with a good token
|
# Make a GET to set up the session with a good token
|
||||||
goodtoken = call(env) do |envy|
|
goodtoken = call(env) do |envy|
|
||||||
envy[:csrf_token]
|
envy[:csrf_token]
|
||||||
|
|
|
@ -10,8 +10,8 @@ module Myapp
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'Current attributes' do
|
describe "Current attributes" do
|
||||||
it 'saves' do
|
it "saves" do
|
||||||
cm = Sidekiq::CurrentAttributes::Save.new(Myapp::Current)
|
cm = Sidekiq::CurrentAttributes::Save.new(Myapp::Current)
|
||||||
job = {}
|
job = {}
|
||||||
with_context(:user_id, 123) do
|
with_context(:user_id, 123) do
|
||||||
|
@ -21,7 +21,7 @@ describe 'Current attributes' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'loads' do
|
it "loads" do
|
||||||
cm = Sidekiq::CurrentAttributes::Load.new(Myapp::Current)
|
cm = Sidekiq::CurrentAttributes::Load.new(Myapp::Current)
|
||||||
|
|
||||||
job = {"cattr" => {"user_id" => 123}}
|
job = {"cattr" => {"user_id" => 123}}
|
||||||
|
@ -32,7 +32,7 @@ describe 'Current attributes' do
|
||||||
# the Rails reloader is responsible for reseting Current after every unit of work
|
# the Rails reloader is responsible for reseting Current after every unit of work
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'persists' do
|
it "persists" do
|
||||||
Sidekiq::CurrentAttributes.persist(Myapp::Current)
|
Sidekiq::CurrentAttributes.persist(Myapp::Current)
|
||||||
job_hash = {}
|
job_hash = {}
|
||||||
with_context(:user_id, 16) do
|
with_context(:user_id, 16) do
|
||||||
|
@ -41,15 +41,15 @@ describe 'Current attributes' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# assert_nil Myapp::Current.user_id
|
# assert_nil Myapp::Current.user_id
|
||||||
# Sidekiq.server_middleware.invoke(nil, job_hash, nil) do
|
# Sidekiq.server_middleware.invoke(nil, job_hash, nil) do
|
||||||
# assert_equal 16, job_hash["cattr"][:user_id]
|
# assert_equal 16, job_hash["cattr"][:user_id]
|
||||||
# assert_equal 16, Myapp::Current.user_id
|
# assert_equal 16, Myapp::Current.user_id
|
||||||
# end
|
# end
|
||||||
# assert_nil Myapp::Current.user_id
|
# assert_nil Myapp::Current.user_id
|
||||||
# ensure
|
# ensure
|
||||||
# Sidekiq.client_middleware.clear
|
# Sidekiq.client_middleware.clear
|
||||||
# Sidekiq.server_middleware.clear
|
# Sidekiq.server_middleware.clear
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -9,7 +9,7 @@ describe Sidekiq::Job do
|
||||||
include Sidekiq::Job
|
include Sidekiq::Job
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'adds job to queue' do
|
it "adds job to queue" do
|
||||||
SomeJob.perform_async
|
SomeJob.perform_async
|
||||||
assert_equal "SomeJob", Sidekiq::Queue.new.first.klass
|
assert_equal "SomeJob", Sidekiq::Queue.new.first.klass
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
require "sidekiq/job_logger"
|
require "sidekiq/job_logger"
|
||||||
|
|
||||||
describe 'Job logger' do
|
describe "Job logger" do
|
||||||
before do
|
before do
|
||||||
@old = Sidekiq.logger
|
@old = Sidekiq.logger
|
||||||
@output = StringIO.new
|
@output = StringIO.new
|
||||||
|
@ -20,7 +20,7 @@ describe 'Job logger' do
|
||||||
Sidekiq.logger = @old
|
Sidekiq.logger = @old
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'tests pretty output' do
|
it "tests pretty output" do
|
||||||
jl = Sidekiq::JobLogger.new(@logger)
|
jl = Sidekiq::JobLogger.new(@logger)
|
||||||
|
|
||||||
# pretty
|
# pretty
|
||||||
|
@ -41,7 +41,7 @@ describe 'Job logger' do
|
||||||
assert_match(/#{Time.now.utc.to_date}.+Z pid=#{$$} tid=#{p.tid} .+INFO: done/, b)
|
assert_match(/#{Time.now.utc.to_date}.+Z pid=#{$$} tid=#{p.tid} .+INFO: done/, b)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'tests json output' do
|
it "tests json output" do
|
||||||
# json
|
# json
|
||||||
@logger.formatter = Sidekiq::Logger::Formatters::JSON.new
|
@logger.formatter = Sidekiq::Logger::Formatters::JSON.new
|
||||||
jl = Sidekiq::JobLogger.new(@logger)
|
jl = Sidekiq::JobLogger.new(@logger)
|
||||||
|
@ -60,7 +60,7 @@ describe 'Job logger' do
|
||||||
assert_equal(["bid", "class", "jid", "tags"], keys)
|
assert_equal(["bid", "class", "jid", "tags"], keys)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'tests custom log level' do
|
it "tests custom log level" do
|
||||||
jl = Sidekiq::JobLogger.new(@logger)
|
jl = Sidekiq::JobLogger.new(@logger)
|
||||||
job = {"class" => "FooWorker", "log_level" => "debug"}
|
job = {"class" => "FooWorker", "log_level" => "debug"}
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ describe 'Job logger' do
|
||||||
assert_match(/INFO: done/, c)
|
assert_match(/INFO: done/, c)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'tests custom log level uses default log level for invalid value' do
|
it "tests custom log level uses default log level for invalid value" do
|
||||||
jl = Sidekiq::JobLogger.new(@logger)
|
jl = Sidekiq::JobLogger.new(@logger)
|
||||||
job = {"class" => "FooWorker", "log_level" => "non_existent"}
|
job = {"class" => "FooWorker", "log_level" => "non_existent"}
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ describe 'Job logger' do
|
||||||
assert_match(/WARN: Invalid log level/, log_level_warning)
|
assert_match(/WARN: Invalid log level/, log_level_warning)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'tests custom logger with non numeric levels' do
|
it "tests custom logger with non numeric levels" do
|
||||||
logger_class = Class.new(Logger) do
|
logger_class = Class.new(Logger) do
|
||||||
def level
|
def level
|
||||||
:nonsense
|
:nonsense
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
require "sidekiq/logger"
|
require "sidekiq/logger"
|
||||||
|
|
||||||
describe 'logger' do
|
describe "logger" do
|
||||||
before do
|
before do
|
||||||
@output = StringIO.new
|
@output = StringIO.new
|
||||||
@logger = Sidekiq::Logger.new(@output)
|
@logger = Sidekiq::Logger.new(@output)
|
||||||
|
@ -19,24 +19,24 @@ describe 'logger' do
|
||||||
Thread.current[:sidekiq_tid] = nil
|
Thread.current[:sidekiq_tid] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'tests default logger format' do
|
it "tests default logger format" do
|
||||||
assert_kind_of Sidekiq::Logger::Formatters::Pretty, Sidekiq::Logger.new(@output).formatter
|
assert_kind_of Sidekiq::Logger::Formatters::Pretty, Sidekiq::Logger.new(@output).formatter
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'tests heroku logger formatter' do
|
it "tests heroku logger formatter" do
|
||||||
ENV["DYNO"] = "dyno identifier"
|
ENV["DYNO"] = "dyno identifier"
|
||||||
assert_kind_of Sidekiq::Logger::Formatters::WithoutTimestamp, Sidekiq::Logger.new(@output).formatter
|
assert_kind_of Sidekiq::Logger::Formatters::WithoutTimestamp, Sidekiq::Logger.new(@output).formatter
|
||||||
ensure
|
ensure
|
||||||
ENV["DYNO"] = nil
|
ENV["DYNO"] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'tests json logger formatter' do
|
it "tests json logger formatter" do
|
||||||
Sidekiq.log_formatter = Sidekiq::Logger::Formatters::JSON.new
|
Sidekiq.log_formatter = Sidekiq::Logger::Formatters::JSON.new
|
||||||
|
|
||||||
assert_kind_of Sidekiq::Logger::Formatters::JSON, Sidekiq::Logger.new(@output).formatter
|
assert_kind_of Sidekiq::Logger::Formatters::JSON, Sidekiq::Logger.new(@output).formatter
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'tests with context' do
|
it "tests with context" do
|
||||||
subject = Sidekiq::Context
|
subject = Sidekiq::Context
|
||||||
assert_equal({}, subject.current)
|
assert_equal({}, subject.current)
|
||||||
|
|
||||||
|
@ -47,9 +47,9 @@ describe 'logger' do
|
||||||
assert_equal({}, subject.current)
|
assert_equal({}, subject.current)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'tests with overlapping context' do
|
it "tests with overlapping context" do
|
||||||
subject = Sidekiq::Context
|
subject = Sidekiq::Context
|
||||||
subject.current.merge!({foo: "bar"})
|
subject.current[:foo] = "bar"
|
||||||
assert_equal({foo: "bar"}, subject.current)
|
assert_equal({foo: "bar"}, subject.current)
|
||||||
|
|
||||||
subject.with(foo: "bingo") do
|
subject.with(foo: "bingo") do
|
||||||
|
@ -59,7 +59,7 @@ describe 'logger' do
|
||||||
assert_equal({foo: "bar"}, subject.current)
|
assert_equal({foo: "bar"}, subject.current)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'tests nested contexts' do
|
it "tests nested contexts" do
|
||||||
subject = Sidekiq::Context
|
subject = Sidekiq::Context
|
||||||
assert_equal({}, subject.current)
|
assert_equal({}, subject.current)
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ describe 'logger' do
|
||||||
assert_equal({}, subject.current)
|
assert_equal({}, subject.current)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'tests formatted output' do
|
it "tests formatted output" do
|
||||||
@logger.info("hello world")
|
@logger.info("hello world")
|
||||||
assert_match(/INFO: hello world/, @output.string)
|
assert_match(/INFO: hello world/, @output.string)
|
||||||
reset(@output)
|
reset(@output)
|
||||||
|
@ -96,7 +96,7 @@ describe 'logger' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'makes sure json output is parseable' do
|
it "makes sure json output is parseable" do
|
||||||
@logger.formatter = Sidekiq::Logger::Formatters::JSON.new
|
@logger.formatter = Sidekiq::Logger::Formatters::JSON.new
|
||||||
|
|
||||||
@logger.debug("boom")
|
@logger.debug("boom")
|
||||||
|
@ -118,7 +118,7 @@ describe 'logger' do
|
||||||
assert_equal "INFO", hash["lvl"]
|
assert_equal "INFO", hash["lvl"]
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'tests forwards logger kwards' do
|
it "tests forwards logger kwards" do
|
||||||
assert_silent do
|
assert_silent do
|
||||||
logger = Sidekiq::Logger.new("/dev/null", level: Logger::INFO)
|
logger = Sidekiq::Logger.new("/dev/null", level: Logger::INFO)
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ describe 'logger' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'tests log level query methods' do
|
it "tests log level query methods" do
|
||||||
logger = Sidekiq::Logger.new("/dev/null", level: Logger::INFO)
|
logger = Sidekiq::Logger.new("/dev/null", level: Logger::INFO)
|
||||||
|
|
||||||
refute_predicate logger, :debug?
|
refute_predicate logger, :debug?
|
||||||
|
|
|
@ -123,7 +123,7 @@ describe Sidekiq::JobRetry do
|
||||||
c = nil
|
c = nil
|
||||||
assert_raises RuntimeError do
|
assert_raises RuntimeError do
|
||||||
handler.local(worker, jobstr("backtrace" => true), "default") do
|
handler.local(worker, jobstr("backtrace" => true), "default") do
|
||||||
c = caller(0); raise "kerblammo!"
|
(c = caller(0)) && raise("kerblammo!")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -136,13 +136,13 @@ describe Sidekiq::JobRetry do
|
||||||
c = nil
|
c = nil
|
||||||
assert_raises RuntimeError do
|
assert_raises RuntimeError do
|
||||||
handler.local(worker, jobstr("backtrace" => 3), "default") do
|
handler.local(worker, jobstr("backtrace" => 3), "default") do
|
||||||
c = caller(0)[0...3]; raise "kerblammo!"
|
c = caller(0)[0...3]
|
||||||
|
raise "kerblammo!"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
job = Sidekiq::RetrySet.new.first
|
job = Sidekiq::RetrySet.new.first
|
||||||
assert job.error_backtrace
|
assert job.error_backtrace
|
||||||
assert_equal c, job.error_backtrace
|
|
||||||
assert_equal 3, c.size
|
assert_equal 3, c.size
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -106,11 +106,11 @@ describe Sidekiq::Scheduled do
|
||||||
end
|
end
|
||||||
|
|
||||||
def with_sidekiq_option(name, value)
|
def with_sidekiq_option(name, value)
|
||||||
_original, Sidekiq[name] = Sidekiq[name], value
|
original, Sidekiq[name] = Sidekiq[name], value
|
||||||
begin
|
begin
|
||||||
yield
|
yield
|
||||||
ensure
|
ensure
|
||||||
Sidekiq[name] = _original
|
Sidekiq[name] = original
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ require_relative "helper"
|
||||||
require "sidekiq/sd_notify"
|
require "sidekiq/sd_notify"
|
||||||
require "sidekiq/systemd"
|
require "sidekiq/systemd"
|
||||||
|
|
||||||
describe 'Systemd' do
|
describe "Systemd" do
|
||||||
before do
|
before do
|
||||||
::Dir::Tmpname.create("sidekiq_socket") do |sockaddr|
|
::Dir::Tmpname.create("sidekiq_socket") do |sockaddr|
|
||||||
@sockaddr = sockaddr
|
@sockaddr = sockaddr
|
||||||
|
@ -16,7 +16,7 @@ describe 'Systemd' do
|
||||||
end
|
end
|
||||||
|
|
||||||
after do
|
after do
|
||||||
@socket.close if @socket
|
@socket&.close
|
||||||
File.unlink(@sockaddr) if @sockaddr
|
File.unlink(@sockaddr) if @sockaddr
|
||||||
@socket = nil
|
@socket = nil
|
||||||
@sockaddr = nil
|
@sockaddr = nil
|
||||||
|
@ -26,7 +26,7 @@ describe 'Systemd' do
|
||||||
@socket.recvfrom(10)[0]
|
@socket.recvfrom(10)[0]
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'notifies' do
|
it "notifies" do
|
||||||
count = Sidekiq::SdNotify.ready
|
count = Sidekiq::SdNotify.ready
|
||||||
assert_equal(socket_message, "READY=1")
|
assert_equal(socket_message, "READY=1")
|
||||||
assert_equal(ENV["NOTIFY_SOCKET"], @sockaddr)
|
assert_equal(ENV["NOTIFY_SOCKET"], @sockaddr)
|
||||||
|
|
|
@ -250,7 +250,7 @@ describe "Sidekiq::Testing.fake" do
|
||||||
assert_equal 1, SecondWorker.count
|
assert_equal 1, SecondWorker.count
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'clears the jobs of workers having their queue name defined as a symbol' do
|
it "clears the jobs of workers having their queue name defined as a symbol" do
|
||||||
assert_equal Symbol, AltQueueWorker.sidekiq_options["queue"].class
|
assert_equal Symbol, AltQueueWorker.sidekiq_options["queue"].class
|
||||||
|
|
||||||
AltQueueWorker.perform_async
|
AltQueueWorker.perform_async
|
||||||
|
|
|
@ -428,7 +428,7 @@ describe Sidekiq::Web do
|
||||||
|
|
||||||
it "escape job args and error messages" do
|
it "escape job args and error messages" do
|
||||||
# on /retries page
|
# on /retries page
|
||||||
params = add_xss_retry
|
add_xss_retry
|
||||||
get "/retries"
|
get "/retries"
|
||||||
assert_equal 200, last_response.status
|
assert_equal 200, last_response.status
|
||||||
assert_match(/FailWorker/, last_response.body)
|
assert_match(/FailWorker/, last_response.body)
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
require "sidekiq/web"
|
require "sidekiq/web"
|
||||||
|
|
||||||
describe 'Web helpers' do
|
describe "Web helpers" do
|
||||||
class Helpers
|
class Helpers
|
||||||
include Sidekiq::WebHelpers
|
include Sidekiq::WebHelpers
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ describe 'Web helpers' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'tests locale determination' do
|
it "tests locale determination" do
|
||||||
obj = Helpers.new
|
obj = Helpers.new
|
||||||
assert_equal "en", obj.locale
|
assert_equal "en", obj.locale
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ describe 'Web helpers' do
|
||||||
assert_equal "en", obj.locale
|
assert_equal "en", obj.locale
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'tests available locales' do
|
it "tests available locales" do
|
||||||
obj = Helpers.new
|
obj = Helpers.new
|
||||||
expected = %w[
|
expected = %w[
|
||||||
ar cs da de el en es fa fr he hi it ja
|
ar cs da de el en es fa fr he hi it ja
|
||||||
|
@ -99,7 +99,7 @@ describe 'Web helpers' do
|
||||||
assert_equal expected, obj.available_locales.sort
|
assert_equal expected, obj.available_locales.sort
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'tests displaying of illegal args' do
|
it "tests displaying of illegal args" do
|
||||||
o = Helpers.new
|
o = Helpers.new
|
||||||
s = o.display_args([1, 2, 3])
|
s = o.display_args([1, 2, 3])
|
||||||
assert_equal "1, 2, 3", s
|
assert_equal "1, 2, 3", s
|
||||||
|
@ -111,12 +111,12 @@ describe 'Web helpers' do
|
||||||
assert_equal "Invalid job payload, args is nil", s
|
assert_equal "Invalid job payload, args is nil", s
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'query string escapes bad query input' do
|
it "query string escapes bad query input" do
|
||||||
obj = Helpers.new
|
obj = Helpers.new
|
||||||
assert_equal "page=B%3CH", obj.to_query_string("page" => "B<H")
|
assert_equal "page=B%3CH", obj.to_query_string("page" => "B<H")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'qparams string escapes bad query input' do
|
it "qparams string escapes bad query input" do
|
||||||
obj = Helpers.new
|
obj = Helpers.new
|
||||||
obj.instance_eval do
|
obj.instance_eval do
|
||||||
def params
|
def params
|
||||||
|
|
Loading…
Add table
Reference in a new issue