sidekiq-unique-jobs 4.0.17 → 4.0.18

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sidekiq-unique-jobs might be problematic. Click here for more details.

Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.dockerignore +4 -0
  3. data/.gitignore +1 -0
  4. data/.travis.yml +3 -3
  5. data/CHANGELOG.md +9 -0
  6. data/Gemfile +1 -0
  7. data/README.md +6 -3
  8. data/circle.yml +3 -6
  9. data/lib/sidekiq-unique-jobs.rb +4 -0
  10. data/lib/sidekiq_unique_jobs/cli.rb +2 -2
  11. data/lib/sidekiq_unique_jobs/lock/until_executed.rb +5 -1
  12. data/lib/sidekiq_unique_jobs/lock/while_executing.rb +3 -1
  13. data/lib/sidekiq_unique_jobs/script_mock.rb +68 -0
  14. data/lib/sidekiq_unique_jobs/scripts.rb +8 -5
  15. data/lib/sidekiq_unique_jobs/testing.rb +36 -0
  16. data/lib/sidekiq_unique_jobs/testing/sidekiq_overrides.rb +1 -1
  17. data/lib/sidekiq_unique_jobs/version.rb +1 -1
  18. data/rails_example/.env +12 -0
  19. data/rails_example/.rspec +2 -0
  20. data/rails_example/Gemfile +21 -7
  21. data/rails_example/app/channels/appearance_channel.rb +17 -0
  22. data/rails_example/app/channels/application_cable/channel.rb +4 -0
  23. data/rails_example/app/channels/application_cable/connection.rb +9 -0
  24. data/rails_example/app/channels/post_channel.rb +5 -0
  25. data/rails_example/app/controllers/work_controller.rb +8 -5
  26. data/rails_example/app/models/application_record.rb +3 -0
  27. data/rails_example/app/models/guest.rb +21 -0
  28. data/rails_example/app/models/post.rb +1 -1
  29. data/rails_example/app/workers/simple_worker.rb +5 -4
  30. data/rails_example/bin/check_or_setup_db +57 -0
  31. data/rails_example/bin/docker-setup +20 -0
  32. data/rails_example/bin/rails +1 -1
  33. data/rails_example/bin/setup +15 -10
  34. data/rails_example/bin/update +29 -0
  35. data/rails_example/cable.ru +6 -0
  36. data/rails_example/common-services.yml +50 -0
  37. data/rails_example/config/application.rb +5 -4
  38. data/rails_example/config/boot.rb +1 -1
  39. data/rails_example/config/cable.yml +9 -0
  40. data/rails_example/config/database.docker.yml +12 -0
  41. data/rails_example/config/database.yml +15 -22
  42. data/rails_example/config/environment.rb +1 -1
  43. data/rails_example/config/environments/development.rb +24 -11
  44. data/rails_example/config/environments/production.rb +24 -17
  45. data/rails_example/config/environments/test.rb +6 -6
  46. data/rails_example/config/initializers/application_controller_renderer.rb +6 -0
  47. data/rails_example/config/initializers/backtrace_silencers.rb +3 -2
  48. data/rails_example/config/initializers/cookies_serializer.rb +2 -0
  49. data/rails_example/config/initializers/new_framework_defaults.rb +23 -0
  50. data/rails_example/config/initializers/session_store.rb +1 -1
  51. data/rails_example/config/initializers/sidekiq.rb +2 -2
  52. data/rails_example/config/initializers/wrap_parameters.rb +2 -2
  53. data/rails_example/config/puma.rb +38 -0
  54. data/rails_example/config/routes.rb +2 -1
  55. data/rails_example/config/secrets.yml +3 -3
  56. data/rails_example/config/spring.rb +6 -0
  57. data/rails_example/db/migrate/20160724111322_create_posts.rb +12 -0
  58. data/rails_example/db/schema.rb +8 -4
  59. data/rails_example/dev-entrypoint.sh +55 -0
  60. data/rails_example/dev.env +12 -0
  61. data/rails_example/docker-compose.yml +90 -0
  62. data/rails_example/docker/rails.Dockerfile +27 -0
  63. data/rails_example/spec/controllers/work_controller_spec.rb +172 -0
  64. data/rails_example/spec/factories/posts.rb +8 -0
  65. data/rails_example/spec/models/post_spec.rb +4 -0
  66. data/rails_example/spec/rails_helper.rb +21 -0
  67. data/rails_example/spec/spec_helper.rb +20 -0
  68. data/rails_example/spec/support/sidekiq_meta.rb +12 -0
  69. data/rails_example/spec/workers/simple_worker_spec.rb +4 -0
  70. data/spec/jobs/my_unique_job.rb +7 -2
  71. data/spec/jobs/my_unique_job_with_filter_method.rb +17 -0
  72. data/spec/jobs/my_unique_job_with_filter_proc.rb +15 -0
  73. data/spec/jobs/notify_worker.rb +1 -1
  74. data/spec/lib/sidekiq_unique_jobs/client/middleware_spec.rb +34 -0
  75. data/spec/lib/sidekiq_unique_jobs/lock/until_and_while_executing_spec.rb +5 -1
  76. data/spec/lib/sidekiq_unique_jobs/lock/until_executed_spec.rb +5 -8
  77. data/spec/lib/sidekiq_unique_jobs/options_with_fallback_spec.rb +2 -1
  78. data/spec/lib/sidekiq_unique_jobs/script_mock_spec.rb +84 -0
  79. data/spec/lib/sidekiq_unique_jobs/scripts_spec.rb +4 -0
  80. data/spec/lib/sidekiq_unique_jobs/sidekiq_testing_enabled_spec.rb +7 -11
  81. data/spec/lib/sidekiq_unique_jobs/sidekiq_unique_ext_spec.rb +2 -1
  82. data/spec/spec_helper.rb +1 -2
  83. data/spec/support/sidekiq_meta.rb +16 -11
  84. metadata +39 -7
  85. data/rails_example/db/development.sqlite3 +0 -0
  86. data/rails_example/db/migrate/20151107231835_create_posts.rb +0 -10
  87. data/rails_example/db/test.sqlite3 +0 -0
@@ -12,9 +12,11 @@ Rails.application.configure do
12
12
  # preloads Rails for running tests, you may have to set it to true.
13
13
  config.eager_load = false
14
14
 
15
- # Configure static file server for tests with Cache-Control for performance.
16
- config.serve_static_files = true
17
- config.static_cache_control = 'public, max-age=3600'
15
+ # Configure public file server for tests with Cache-Control for performance.
16
+ config.public_file_server.enabled = true
17
+ config.public_file_server.headers = {
18
+ 'Cache-Control' => 'public, max-age=3600'
19
+ }
18
20
 
19
21
  # Show full error reports and disable caching.
20
22
  config.consider_all_requests_local = true
@@ -25,15 +27,13 @@ Rails.application.configure do
25
27
 
26
28
  # Disable request forgery protection in test environment.
27
29
  config.action_controller.allow_forgery_protection = false
30
+ config.action_mailer.perform_caching = false
28
31
 
29
32
  # Tell Action Mailer not to deliver emails to the real world.
30
33
  # The :test delivery method accumulates sent emails in the
31
34
  # ActionMailer::Base.deliveries array.
32
35
  config.action_mailer.delivery_method = :test
33
36
 
34
- # Randomize the order test cases are executed.
35
- config.active_support.test_order = :random
36
-
37
37
  # Print deprecation notices to the stderr.
38
38
  config.active_support.deprecation = :stderr
39
39
 
@@ -0,0 +1,6 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # ApplicationController.renderer.defaults.merge!(
4
+ # http_host: 'example.org',
5
+ # https: false
6
+ # )
@@ -3,6 +3,7 @@
3
3
  # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
4
  # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
5
 
6
- # You can also remove all the silencers if you're trying to debug a problem that might
7
- # stem from framework code.
6
+ # You can also remove all the silencers
7
+ # if you're trying to debug a problem that might stem
8
+ # from framework code.
8
9
  # Rails.backtrace_cleaner.remove_silencers!
@@ -1,3 +1,5 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
+ # Specify a serializer for the signed and encrypted cookie jars.
4
+ # Valid options are :json, :marshal, and :hybrid.
3
5
  Rails.application.config.action_dispatch.cookies_serializer = :json
@@ -0,0 +1,23 @@
1
+ # Be sure to restart your server when you modify this file.
2
+ #
3
+ # This file contains migration options to ease your Rails 5.0 upgrade.
4
+ #
5
+ # Once upgraded flip defaults one by one to migrate to the new default.
6
+ #
7
+ # Read the Rails 5.0 release notes for more info on each option.
8
+
9
+ # Enable per-form CSRF tokens. Previous versions had false.
10
+ Rails.application.config.action_controller.per_form_csrf_tokens = false
11
+
12
+ # Enable origin-checking CSRF mitigation. Previous versions had false.
13
+ Rails.application.config.action_controller.forgery_protection_origin_check = false
14
+
15
+ # Make Ruby 2.4 preserve the timezone of the receiver when calling `to_time`.
16
+ # Previous versions had false.
17
+ ActiveSupport.to_time_preserves_timezone = false
18
+
19
+ # Require `belongs_to` associations by default. Previous versions had false.
20
+ Rails.application.config.active_record.belongs_to_required_by_default = false
21
+
22
+ # Do not halt callback chains when a callback returns false. Previous versions had true.
23
+ ActiveSupport.halt_callback_chains_on_return_false = true
@@ -1,3 +1,3 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
- Rails.application.config.session_store :cookie_store, key: '_sidekiq-unique-job-app_session'
3
+ Rails.application.config.session_store :cookie_store, key: '_rails_example_session'
@@ -4,10 +4,10 @@ Sidekiq.default_worker_options = {
4
4
  }
5
5
 
6
6
  Sidekiq.configure_server do |config|
7
- config.redis = { url: ENV['REDIS_URL'], namespace: "rails_example_#{Rails.env}" }
7
+ config.redis = { url: ENV['REDIS_URL'] }
8
8
  # config.error_handlers << Proc.new { |ex, context| Airbrake.notify_or_ignore(ex, parameters: context) }
9
9
  end
10
10
 
11
11
  Sidekiq.configure_client do |config|
12
- config.redis = { url: ENV['REDIS_URL'], namespace: "rails_example_#{Rails.env}" }
12
+ config.redis = { url: ENV['REDIS_URL'] }
13
13
  end
@@ -5,10 +5,10 @@
5
5
 
6
6
  # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
7
  ActiveSupport.on_load(:action_controller) do
8
- wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
8
+ wrap_parameters format: [:json]
9
9
  end
10
10
 
11
11
  # To enable root element in JSON for ActiveRecord objects.
12
12
  # ActiveSupport.on_load(:active_record) do
13
- # self.include_root_in_json = true
13
+ # self.include_root_in_json = true
14
14
  # end
@@ -0,0 +1,38 @@
1
+ threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 }.to_i
2
+ threads threads_count, threads_count
3
+ port ENV.fetch('PORT') { 3000 }
4
+ environment ENV.fetch('RAILS_ENV') { 'development' }
5
+ # daemonize false
6
+
7
+ # Store the pid of the server in the file at "path".
8
+ #
9
+ # pidfile '/u/apps/lolcat/tmp/pids/puma.pid'
10
+
11
+ # Use "path" as the file to store the server info state. This is
12
+ # used by "pumactl" to query and control the server.
13
+ #
14
+ # state_path '/u/apps/lolcat/tmp/pids/puma.state'
15
+
16
+ # Use the `preload_app!` method when specifying a `workers` number.
17
+ # This directive tells Puma to first boot the application and load code
18
+ # before forking the application. This takes advantage of Copy On Write
19
+ # process behavior so workers use less memory. If you use this option
20
+ # you need to make sure to reconnect any threads in the `on_worker_boot`
21
+ # block.
22
+ #
23
+ # workers ENV.fetch("WEB_CONCURRENCY") { 2 }
24
+ # preload_app!
25
+
26
+ # The code in the `on_worker_boot` will be called if you are using
27
+ # clustered mode by specifying a number of `workers`. After each worker
28
+ # process is booted this block will be run, if you are using `preload_app!`
29
+ # option you will want to use this block to reconnect to any threads
30
+ # or connections that may have been created at application boot, Ruby
31
+ # cannot share connections between processes.
32
+ #
33
+ # on_worker_boot do
34
+ # ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
35
+ # end
36
+
37
+ # Allow puma to be restarted by `rails restart` command.
38
+ # plugin :tmp_restart
@@ -1,5 +1,6 @@
1
1
  Rails.application.routes.draw do
2
2
  require 'sidekiq/web'
3
3
  mount Sidekiq::Web, at: '/sidekiq'
4
- get 'work/duplicate' => 'work#duplicate'
4
+ get 'work/duplicate_simple' => 'work#duplicate_simple'
5
+ get 'work/duplicate_nested' => 'work#duplicate_nested'
5
6
  end
@@ -5,16 +5,16 @@
5
5
 
6
6
  # Make sure the secret is at least 30 characters and all random,
7
7
  # no regular words or you'll be exposed to dictionary attacks.
8
- # You can use `rake secret` to generate a secure secret key.
8
+ # You can use `rails secret` to generate a secure secret key.
9
9
 
10
10
  # Make sure the secrets in this file are kept private
11
11
  # if you're sharing your code publicly.
12
12
 
13
13
  development:
14
- secret_key_base: 90a782880015a9365614d023fd9a63939efe09ee0655897998847938e08f800685ed8da5aa230f45452387369300f31da50527728bbeba12d2d01f209d83621b
14
+ secret_key_base: f5771482e38ac985be78a1668b8a155f3be99b707cea923e7f0e55a649f78bb2e9debd08f49f57ba2f3da4ffcfc73a18bd43054e0f704c2513735e57cf612cf0
15
15
 
16
16
  test:
17
- secret_key_base: 9a7b9f197e9c309c5f34669b6c829ca8b22d9e738499852ee0dad7f20becb23cb095eff5a8eb7c955ed182be5626e67de7e1aa1007c40eba55ebd30b61c78388
17
+ secret_key_base: cb65c5fd20b500e74f0971e1f2eb440c9965e16ff469542ed2077b523c4eeb2fd890a5aae8dc063fba7ef97c5a5a65fdfa5fddea5b8f650916719abcd83861e0
18
18
 
19
19
  # Do not keep production secrets in the repository,
20
20
  # instead read values from the environment.
@@ -0,0 +1,6 @@
1
+ %w(
2
+ .ruby-version
3
+ .rbenv-vars
4
+ tmp/restart.txt
5
+ tmp/caching-dev.txt
6
+ ).each { |path| Spring.watch(path) }
@@ -0,0 +1,12 @@
1
+ class CreatePosts < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :posts do |t|
4
+ t.string :title
5
+ t.text :body
6
+ t.string :excerpt
7
+ t.integer :read_count
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  # This file is auto-generated from the current state of the database. Instead
3
2
  # of editing this file, please use the migrations feature of Active Record to
4
3
  # incrementally modify your database, and then regenerate this schema definition.
@@ -11,10 +10,15 @@
11
10
  #
12
11
  # It's strongly recommended that you check this file into your version control system.
13
12
 
14
- ActiveRecord::Schema.define(version: 20_151_107_231_835) do
13
+ ActiveRecord::Schema.define(version: 20_160_724_111_322) do
14
+ # These are extensions that must be enabled in order to support this database
15
+ enable_extension 'plpgsql'
16
+
15
17
  create_table 'posts', force: :cascade do |t|
16
- t.string 'title'
17
- t.text 'body'
18
+ t.string 'title'
19
+ t.text 'body'
20
+ t.string 'excerpt'
21
+ t.integer 'read_count'
18
22
  t.datetime 'created_at', null: false
19
23
  t.datetime 'updated_at', null: false
20
24
  end
@@ -0,0 +1,55 @@
1
+ #! /bin/bash
2
+
3
+ # The Docker App Container's development entrypoint.
4
+ # This is a script used by the project's Docker development environment to
5
+ # setup the app containers and databases upon runnning.
6
+ set -e
7
+
8
+ : ${APP_PATH:="/usr/src/app"}
9
+ : ${APP_TEMP_PATH:="$APP_PATH/tmp"}
10
+ : ${APP_SETUP_LOCK:="$APP_TEMP_PATH/setup.lock"}
11
+ : ${APP_SETUP_WAIT:="5"}
12
+
13
+ # 1: Define the functions lock and unlock our app containers setup processes:
14
+ function lock_setup { mkdir -p $APP_TEMP_PATH && touch $APP_SETUP_LOCK; }
15
+ function unlock_setup { rm -rf $APP_SETUP_LOCK; }
16
+ function wait_setup { echo "Waiting for app setup to finish..."; sleep $APP_SETUP_WAIT; }
17
+
18
+ # 2: 'Unlock' the setup process if the script exits prematurely:
19
+ trap unlock_setup HUP INT QUIT KILL TERM EXIT
20
+
21
+ # 3: Wait until the setup 'lock' file no longer exists:
22
+ while [ -f $APP_SETUP_LOCK ]; do wait_setup; done
23
+
24
+ # 4: 'Lock' the setup process, to prevent a race condition when the project's
25
+ # app containers will try to install gems and setup the database concurrently:
26
+ lock_setup
27
+
28
+ # 5: Check or install the app dependencies via Bundler:
29
+ bundle check || bundle install --jobs 8 --retry 5
30
+
31
+ # 6: Check if the database exists, or setup the database if it doesn't, as it is
32
+ # the case when the project runs for the first time.
33
+ #
34
+ # We'll use a custom script `check-or-setup-db` (inside our app's `bin` folder),
35
+ # instead of running `rake db:version || rake db:setup`, as running that command
36
+ # (at least on rails 4.2.4) will leave a couple of small ruby zombie processes
37
+ # running in the container:
38
+ # check_or_setup_db
39
+ bin/rails db:version || bin/rails db:setup
40
+ bin/rails db:migrate
41
+
42
+ # 7: 'Unlock' the setup process:
43
+ unlock_setup
44
+
45
+ # 8: Specify a default command, in case it wasn't issued:
46
+ # if [ -z "$1" ]; then set -- rails server -p 3000 -b 0.0.0.0 "$@"; fi
47
+
48
+ # 9: If the command to execute is 'rails server', then force it to write the
49
+ # pid file into a non-shared container directory. Suddenly killing and removing
50
+ # app containers without this would leave a pidfile in the project's tmp dir,
51
+ # preventing the app container from starting up on further attempts:
52
+ # if [[ "$1" = "rails" && ("$2" = "s" || "$2" = "server") ]]; then set -- "$@" -P $PID_FILE; fi
53
+
54
+ # 10: Execute the given or default command:
55
+ exec "$@"
@@ -0,0 +1,12 @@
1
+ SECRET_KEY_BASE=10167c7f7654ed02b3557b05b88ece1866a9748a2e8e064016f76cb74ddae38264f7403ba65f301d63c21d770e0ee2ac6906f245e904b3b140d12297f67e0db1
2
+ APP_DOMAIN=localhost
3
+ APP_WEB_URL=http://localhost:3000
4
+ APP_CABLE_URL=ws://localhost:28080
5
+ WEB_CONSOLE_WHITELISTED_IPS=127.0.0.1 ::1 127.0.0.0/8 ::1
6
+ DB_HOST=postgres
7
+ DB_PORT=5432
8
+ DB_USERNAME=postgres
9
+ DB_PASSWORD=3x4mpl3
10
+ DB_POOL=25
11
+ DB_TIMEOUT=5000
12
+ DB_REAPING_FREQUENCY=10
@@ -0,0 +1,90 @@
1
+ version: '2'
2
+ volumes:
3
+ postgres-data:
4
+ driver: local
5
+ redis-data:
6
+ driver: local
7
+ gems:
8
+ driver: local
9
+
10
+ networks:
11
+ front-tier:
12
+ driver: bridge
13
+ back-tier:
14
+ driver: bridge
15
+
16
+ services:
17
+ jobs: &app
18
+ extends:
19
+ file: common-services.yml
20
+ service: rails
21
+ entrypoint: /usr/src/app/dev-entrypoint.sh
22
+ command: bundle exec sidekiq -c 25
23
+ networks:
24
+ - back-tier
25
+ depends_on:
26
+ - postgres
27
+ - redis
28
+
29
+ web:
30
+ extends:
31
+ file: common-services.yml
32
+ service: rails
33
+ entrypoint: /usr/src/app/dev-entrypoint.sh
34
+ command: bundle exec puma --bind tcp://0.0.0.0:3000
35
+ ports:
36
+ - 3000:3000
37
+ networks:
38
+ - front-tier
39
+ - back-tier
40
+ depends_on:
41
+ - postgres
42
+ - redis
43
+
44
+ cable:
45
+ extends:
46
+ file: common-services.yml
47
+ service: rails
48
+ entrypoint: /usr/src/app/dev-entrypoint.sh
49
+ command: bundle exec puma --bind tcp://0.0.0.0:28080 cable.ru
50
+ ports:
51
+ - 28080:28080
52
+ networks:
53
+ - front-tier
54
+ - back-tier
55
+ depends_on:
56
+ - postgres
57
+ - redis
58
+
59
+ redis:
60
+ image: redis
61
+ ports:
62
+ # We'll bind our host's port 6379 to redis's port 6379, so we can use
63
+ # Redis Desktop Manager (or other tools) with it:
64
+ - 6379:6379
65
+ volumes:
66
+ # We'll store the redis data in the 'redis-data' volume we defined:
67
+ - redis-data:/var/lib/redis
68
+ command: redis-server --appendonly yes
69
+ # Make the redis service available only on the "back-tier" network:
70
+ # NOTE: See networks comment on the postgres service above.
71
+ networks: [ "back-tier" ]
72
+
73
+
74
+ postgres:
75
+ image: postgres
76
+ ports:
77
+ # We'll bind our host's port 5432 to postgres's port 5432, so we can use
78
+ # our database IDEs with it:
79
+ - 5432:5432
80
+ volumes:
81
+ # We'll store the postgres data in the 'postgres-data' volume we defined:
82
+ - postgres-data:/var/lib/postgresql/data
83
+ networks:
84
+ # Make the database service available only on the "back-tier" network:
85
+ # NOTE: Although the service is available only on the "back-tier" network,
86
+ # the host-to-container port binding we've defined for development
87
+ # purposes will allow connection from the development host.
88
+ - back-tier
89
+ environment:
90
+ POSTGRES_PASSWORD: 3x4mpl3
@@ -0,0 +1,27 @@
1
+ FROM ruby:2.3
2
+ MAINTAINER Mika Hel <mikael@zoolutions.se>
3
+
4
+ # ENV BUILD_PACKAGES bash curl-dev ruby-dev build-base git libc-dev linux-headers
5
+ # ENV RUBY_PACKAGES ruby ruby-io-console openssl-dev postgresql-dev ruby-bundler libxml2-dev libxslt-dev
6
+
7
+ # RUN apk update \
8
+ # && apk upgrade \
9
+ # && apk add $BUILD_PACKAGES \
10
+ # && apk add $RUBY_PACKAGES \
11
+ # && rm -rf /var/cache/apk/* \
12
+ # && mkdir -p /usr/src/app \
13
+ # && bundle config --global jobs 8
14
+
15
+ # WORKDIR /usr/src/app
16
+
17
+ # COPY Gemfile /usr/src/app/
18
+ # COPY Gemfile.lock /usr/src/app/
19
+
20
+ # ENV BUNDLE_GEMFILE /usr/src/app/Gemfile
21
+ # ENV BUNDLE_JOBS 8
22
+ # ENV BUNDLE_RETRY 5
23
+ # ENV BUNDLE_PATH /usr/local/bundle
24
+
25
+ # RUN bundle install --jobs 8 --retry 5
26
+
27
+ # COPY . /usr/src/app
@@ -0,0 +1,172 @@
1
+ require 'rails_helper'
2
+
3
+ describe WorkController do
4
+ context 'with real redis' do
5
+ before(:each) do
6
+ SidekiqUniqueJobs.configure do |config|
7
+ config.redis_test_mode = :redis
8
+ end
9
+
10
+ Sidekiq::Queues.clear_all
11
+ Sidekiq.redis(&:flushdb)
12
+ Sidekiq.redis do |c|
13
+ c.keys.each do |key|
14
+ c.del(key)
15
+ end
16
+ end
17
+ end
18
+
19
+ describe 'GET /work/duplicate_simple' do
20
+ context 'when test mode is fake', sidekiq: :fake do
21
+ specify do
22
+ expect { get :duplicate_simple }
23
+ .to change { SimpleWorker.jobs.size }
24
+ .from(0)
25
+ .to(1)
26
+ end
27
+ end
28
+
29
+ context 'when test mode is disabled', sidekiq: :disable do
30
+ specify do
31
+ get :duplicate_simple
32
+ Sidekiq.redis do |c|
33
+ expect(c.llen('queue:default')).to eq(1)
34
+ expect(c.keys).to include('uniquejobs:83bda9f47b05071ffcb35cbb59e1fada')
35
+ end
36
+ end
37
+ end
38
+
39
+ context 'when test mode is inline', sidekiq: :inline do
40
+ specify do
41
+ get :duplicate_simple
42
+ Sidekiq.redis do |c|
43
+ expect(c.llen('queue:default')).to eq(0)
44
+ expect(c.keys).not_to include('uniquejobs:83bda9f47b05071ffcb35cbb59e1fada')
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ describe 'GET /work/duplicate_nested' do
51
+ context 'when test mode is fake', sidekiq: :fake do
52
+ specify do
53
+ expect { get :duplicate_nested }
54
+ .to change { SpawnSimpleWorker.jobs.size }
55
+ .from(0)
56
+ .to(4)
57
+
58
+ SpawnSimpleWorker.perform_one
59
+ SpawnSimpleWorker.perform_one
60
+ expect(SpawnSimpleWorker.jobs.size).to eq(2)
61
+ expect(SimpleWorker.jobs.size).to eq(1)
62
+ end
63
+ end
64
+
65
+ context 'when test mode is disabled', sidekiq: :disable do
66
+ specify do
67
+ get :duplicate_nested
68
+
69
+ Sidekiq.redis do |c|
70
+ expect(c.llen('queue:default')).to eq(4)
71
+ expect(c.keys).not_to include('uniquejobs:83bda9f47b05071ffcb35cbb59e1fada')
72
+ end
73
+ end
74
+ end
75
+
76
+ context 'when test mode is inline', sidekiq: :inline do
77
+ specify do
78
+ get :duplicate_nested
79
+
80
+ Sidekiq.redis do |c|
81
+ expect(c.llen('queue:default')).to eq(0)
82
+ expect(c.keys).not_to include('uniquejobs:83bda9f47b05071ffcb35cbb59e1fada')
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+
89
+ context 'with mock_redis' do
90
+ before do
91
+ SidekiqUniqueJobs.configure do |config|
92
+ config.redis_test_mode = :mock
93
+ end
94
+ Sidekiq::Queues.clear_all
95
+ Sidekiq::Worker.clear_all
96
+
97
+ MOCK_REDIS.keys.each do |key|
98
+ MOCK_REDIS.del(key)
99
+ end
100
+ allow(Redis).to receive(:new).and_return(MOCK_REDIS)
101
+ end
102
+
103
+ describe 'GET /work/duplicate_simple' do
104
+ context 'when test mode is fake', sidekiq: :fake do
105
+ specify do
106
+ expect { get :duplicate_simple }
107
+ .to change { SimpleWorker.jobs.size }
108
+ .from(0)
109
+ .to(1)
110
+ end
111
+ end
112
+
113
+ context 'when test mode is disabled', sidekiq: :disable do
114
+ specify do
115
+ get :duplicate_simple
116
+ Sidekiq.redis do |c|
117
+ expect(c.llen('queue:default')).to eq(1)
118
+ expect(c.keys).to include('uniquejobs:83bda9f47b05071ffcb35cbb59e1fada')
119
+ end
120
+ end
121
+ end
122
+
123
+ context 'when test mode is inline', sidekiq: :inline do
124
+ specify do
125
+ get :duplicate_simple
126
+ Sidekiq.redis do |c|
127
+ expect(c.llen('queue:default')).to eq(0)
128
+ expect(c.keys).not_to include('uniquejobs:83bda9f47b05071ffcb35cbb59e1fada')
129
+ end
130
+ end
131
+ end
132
+ end
133
+
134
+ describe 'GET /work/duplicate_nested' do
135
+ context 'when test mode is fake', sidekiq: :fake do
136
+ specify do
137
+ expect { get :duplicate_nested }
138
+ .to change { SpawnSimpleWorker.jobs.size }
139
+ .from(0)
140
+ .to(4)
141
+
142
+ SpawnSimpleWorker.perform_one
143
+ SpawnSimpleWorker.perform_one
144
+ expect(SpawnSimpleWorker.jobs.size).to eq(2)
145
+ expect(SimpleWorker.jobs.size).to eq(1)
146
+ end
147
+ end
148
+
149
+ context 'when test mode is disabled', sidekiq: :disable do
150
+ specify do
151
+ get :duplicate_nested
152
+
153
+ Sidekiq.redis do |c|
154
+ expect(c.llen('queue:default')).to eq(4)
155
+ expect(c.keys).not_to include('uniquejobs:83bda9f47b05071ffcb35cbb59e1fada')
156
+ end
157
+ end
158
+ end
159
+
160
+ context 'when test mode is inline', sidekiq: :inline do
161
+ specify do
162
+ get :duplicate_nested
163
+
164
+ Sidekiq.redis do |c|
165
+ expect(c.llen('queue:default')).to eq(0)
166
+ expect(c.keys).not_to include('uniquejobs:83bda9f47b05071ffcb35cbb59e1fada')
167
+ end
168
+ end
169
+ end
170
+ end
171
+ end
172
+ end