Skip to content

Instantly share code, notes, and snippets.

@cgunther

cgunther/bug.rb Secret

Created February 14, 2022 23:11
Show Gist options
  • Save cgunther/718379c4786e445e75a4e62ce612a9ee to your computer and use it in GitHub Desktop.
Save cgunther/718379c4786e445e75a4e62ce612a9ee to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Activate the gem you are reporting the issue against.
gem "toxiproxy", "~> 2.0.0"
gem "sidekiq-unique-jobs", "7.1.12"
gem "minitest"
end
require "toxiproxy"
Toxiproxy.populate([
{
name: :redis,
listen: "localhost:21212",
upstream: "localhost:6379",
},
])
require "sidekiq-unique-jobs"
require "sidekiq/testing"
require "sidekiq_unique_jobs/testing"
require "minitest/autorun"
redis_opts = { port: 21212, db: 15 }
Sidekiq.configure_server do |config|
config.redis = redis_opts
config.server_middleware do |chain|
chain.add SidekiqUniqueJobs::Middleware::Server
end
config.client_middleware do |chain|
chain.add SidekiqUniqueJobs::Middleware::Client
end
SidekiqUniqueJobs::Server.configure(config)
end
Sidekiq.configure_client do |config|
config.redis = redis_opts
config.client_middleware do |chain|
chain.add SidekiqUniqueJobs::Middleware::Client
end
end
Sidekiq::Testing.server_middleware do |chain|
chain.add SidekiqUniqueJobs::Middleware::Server
end
Sidekiq::Testing.inline!
class MyWorker
include Sidekiq::Worker
sidekiq_options lock: :until_and_while_executing,
on_conflict: { client: :log, server: :raise }
def perform
end
end
class BugTest < Minitest::Test
def test_stuff
SidekiqUniqueJobs::Digests.new.delete_by_pattern("*")
Toxiproxy[:redis].toxic(:latency, latency: 20).apply do
MyWorker.perform_async
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment