Skip to content

Commit

Permalink
Fix coverage reporting and add coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mhenrixon committed Jan 20, 2021
1 parent 5a21816 commit b89cce6
Show file tree
Hide file tree
Showing 40 changed files with 459 additions and 246 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/lint.yml
Expand Up @@ -10,7 +10,9 @@ jobs:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
ruby-version: 2.7
bundler: 2.2.5
bundler-cache: true
- run: bin/bundle --jobs=$(nproc) --retry=$(nproc)
- run: bin/rubocop -P

Expand All @@ -23,6 +25,8 @@ jobs:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
ruby-version: 2.7
bundler: 2.2.5
bundler-cache: true
- run: bin/bundle --jobs=$(nproc) --retry=$(nproc)
- run: bin/reek .
35 changes: 21 additions & 14 deletions .github/workflows/rspec.yml
Expand Up @@ -14,20 +14,27 @@ jobs:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6.5
- run: bin/bundle --jobs=$(nproc) --retry=$(nproc)
- name: Coverage
uses: paambaati/codeclimate-action@v2.6.0
ruby-version: 2.7
bundler: 2.2.5
bundler-cache: true

- name: Install Code Climate reporter
run: |
sudo curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
sudo chmod +x ./cc-test-reporter
- name: Generate Coverage
env:
COV: true
CC_TEST_REPORTER_ID: 88e524e8f638efe690def7a6e2c72b1a9db5cdfa74548921b734d609a5858ee5
with:
coverageCommand: bin/rspec --require spec_helper --tag ~perf
debug: true
tests:
env:
COV: false
run: |
export GIT_BRANCH=${GITHUB_REF#refs/heads/}
export GIT_COMMIT_SHA=${GITHUB_SHA}
echo $GIT_BRANCH
echo $GIT_COMMIT_SHA
./cc-test-reporter before-build
COV=true bin/rspec --require spec_helper --tag ~perf
./cc-test-reporter after-build --coverage-input-type simplecov --exit-code $?
tests:
services:
redis:
image: redis:latest
Expand All @@ -39,14 +46,14 @@ jobs:
strategy:
fail-fast: true
matrix:
# ruby: [2.5, 2.6, 2.7, jruby, truffleruby]
ruby: [2.5, 2.6, 2.7]

steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
- run: bin/bundle --jobs=$(nproc) --retry=$(nproc)
- run: bin/appraisal install --jobs=$(nproc) --retry=$(nproc)
bundler: 2.2.5
bundler-cache: true
- run: bin/appraisal install --jobs=$(nproc) --retry=$(nproc)
- run: bin/appraisal rspec --require spec_helper --tag ~perf
1 change: 1 addition & 0 deletions .rubocop.yml
Expand Up @@ -87,6 +87,7 @@ RSpec/ContextWording:
- unless
- for
- that
- and

RSpec/DescribeClass:
Exclude:
Expand Down
33 changes: 27 additions & 6 deletions .simplecov
@@ -1,24 +1,45 @@
# frozen_string_literal: true

require "simplecov-oj"
require "simplecov_json_formatter"
require "simplecov-sublime"

SimpleCov.command_name "RSpec"
# SimpleCov.refuse_coverage_drop
SimpleCov.formatters = [
CI_FORMATTERS = [
SimpleCov::Formatter::SimpleFormatter,
SimpleCov::Formatter::JSONFormatter,
].freeze

LOCAL_FORMATTERS = [
SimpleCov::Formatter::JSONFormatter,
SimpleCov::Formatter::SublimeFormatter,
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::OjFormatter,
]
].freeze

SimpleCov.start do
add_filter "/spec/"
add_filter "/bin/"
add_filter "/gemfiles/"
add_filter "/lib/sidekiq/"
add_filter "/lib/sidekiq_unique_jobs/testing.rb"
add_filter "/myapp/"
add_filter "/lib/sidekiq_unique_jobs/core_ext.rb"

add_group "Locks", "lib/sidekiq_unique_jobs/lock"
add_group "Middelware", "lib/sidekiq_unique_jobs/middleware"
add_group "Redis", "lib/sidekiq_unique_jobs/redis"
add_group "Timeout", "lib/sidekiq_unique_jobs/timeout"

enable_coverage :branch
primary_coverage :branch

if ENV["CI"]
formatter SimpleCov::Formatter::MultiFormatter.new(CI_FORMATTERS)
else
formatter SimpleCov::Formatter::MultiFormatter.new(LOCAL_FORMATTERS)

refuse_coverage_drop
minimum_coverage line: 90, branch: 80
minimum_coverage_by_file line: 90, branch: 80
end

track_files "**/*.rb"
end
18 changes: 5 additions & 13 deletions Appraisals
Expand Up @@ -4,18 +4,6 @@ appraise "sidekiq-develop" do
gem "sidekiq", git: "https://github.com/mperham/sidekiq.git"
end

appraise "sidekiq-4.0" do
gem "sidekiq", "~> 4.0.0"
end

appraise "sidekiq-4.1" do
gem "sidekiq", "~> 4.1.0"
end

appraise "sidekiq-4.2" do
gem "sidekiq", "~> 4.2.0"
end

appraise "sidekiq-5.0" do
gem "sidekiq", "~> 5.0.0"
end
Expand All @@ -29,5 +17,9 @@ appraise "sidekiq-5.2" do
end

appraise "sidekiq-6.0" do
gem "sidekiq", ">= 6.0.pre", "< 6.1"
gem "sidekiq", "~> 6.0.0"
end

appraise "sidekiq-6.1" do
gem "sidekiq", "~> 6.1.0"
end
3 changes: 1 addition & 2 deletions Gemfile
Expand Up @@ -30,8 +30,7 @@ platforms :mri do
gem "reek", ">= 5.3"
gem "rspec-benchmark"
gem "rubocop-mhenrixon"
gem "simplecov", "< 0.18"
gem "simplecov-oj"
gem "simplecov-sublime", "0.21.0", require: false
gem "travis"
end

Expand Down
88 changes: 67 additions & 21 deletions README.md
Expand Up @@ -3,9 +3,11 @@
<!-- MarkdownTOC -->

- [Introduction](#introduction)
- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
- [Installation](#installation)
- [Your first worker](#your-first-worker)
- [Support Me](#support-me)
- [Requirements](#requirements)
- [General Information](#general-information)
- [Global Configuration](#global-configuration)
- [debug_lua](#debug_lua)
Expand All @@ -21,6 +23,8 @@
- [lock_prefix](#lock_prefix)
- [lock_info](#lock_info)
- [Worker Configuration](#worker-configuration)
- [lock_info](#lock_info-1)
- [lock_prefix](#lock_prefix-1)
- [lock_ttl](#lock_ttl-1)
- [lock_timeout](#lock_timeout-1)
- [unique_across_queues](#unique_across_queues)
Expand All @@ -39,7 +43,7 @@
- [replace](#replace)
- [Reschedule](#reschedule)
- [Custom Strategies](#custom-strategies)
- [Usage](#usage)
- [Usage](#usage-1)
- [Finer Control over Uniqueness](#finer-control-over-uniqueness)
- [After Unlock Callback](#after-unlock-callback)
- [Logging](#logging)
Expand All @@ -61,7 +65,7 @@

## Introduction

This gem adds unique constraints to the sidekiq queues. The uniqueness is achieved by acquiring locks for a hash of a queue name, a worker class, and job's arguments. Only one lock for a given hash can be acquired. What happens when a lock can't be acquired is governed by a chosen strategy.
This gem adds unique constraints to the sidekiq queues. The uniqueness is achieved by acquiring locks for a hash of a queue name, a worker class, and job's arguments. By default, only one lock for a given hash can be acquired. What happens when a lock can't be acquired is governed by a chosen `on_conflict`strategy.

This is the documentation for the master branch. You can find the documentation for each release by navigating to its tag.

Expand All @@ -71,20 +75,9 @@ Here are links to some of the old versions
- [v5.0.10](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v5.0.10)
- [v4.0.18](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v4.0.18)

## Requirements

- Sidekiq `>= 4.0` (`>= 5.2` recommended)
- Ruby:
- MRI `>= 2.3` (`>= 2.5` recommended)
- JRuby `>= 9.0` (`>= 9.2` recommended)
- Truffleruby
- Redis Server `>= 3.0.2` (`>= 3.2` recommended)
- [ActiveJob officially not supported][48]
- [redis-namespace officially not supported][49]

See [Sidekiq requirements][24] for detailed requirements of Sidekiq itself (be sure to check the right sidekiq version).
## Usage

## Installation
### Installation

Add this line to your application's Gemfile:

Expand All @@ -98,16 +91,51 @@ And then execute:
bundle
```

Or install it yourself as:
### Your first worker

```ruby
# frozen_string_literal: true

class UntilExecutedWorker
include Sidekiq::Worker

sidekiq_options queue: :special,
retry: false,
lock: :until_executed,
lock_info: true,
lock_timeout: 0,
lock_prefix: "special",
lock_ttl: 0,
lock_limit: 5

def perform
logger.info("cowboy")
sleep(1) # hardcore processing
logger.info("beebop")
end
end

```bash
gem install sidekiq-unique-jobs
```

You can read more about the worker configuration in [Worker Configuration](#worker-configuration) below.

## Support Me

Want to show me some ❤️ for the hard work I do on this gem? You can use the following PayPal link: [https://paypal.me/mhenrixon1](https://paypal.me/mhenrixon1). Any amount is welcome and let me tell you it feels good to be appreciated. Even a dollar makes me super excited about all of this.

## Requirements

- Sidekiq `>= 4.0` (`>= 5.2` recommended)
- Ruby:
- MRI `>= 2.5` (`>= 2.6` recommended)
- JRuby `>= 9.0` (`>= 9.2` recommended)
- Truffleruby
- Redis Server `>= 3.0.2` (`>= 3.2` recommended)
- [ActiveJob officially not supported][48]
- [redis-namespace officially not supported][49]

See [Sidekiq requirements][24] for detailed requirements of Sidekiq itself (be sure to check the right sidekiq version).

## General Information

See [Interaction w/ Sidekiq](https://github.com/mhenrixon/sidekiq-unique-jobs/wiki/How-this-gem-interacts-with-Sidekiq) on how the gem interacts with Sidekiq.
Expand Down Expand Up @@ -253,11 +281,27 @@ Using lock info will create an additional key for the lock with a json object co

## Worker Configuration

### lock_info

Lock info gathers information about a specific lock. It collects things like which `lock_args` where used to compute the `lock_digest` that is used for maintaining uniqueness.

```ruby
sidekiq_options lock_info: false # this is the default, set to true to turn on
```

### lock_prefix

Use if you want a different key prefix for the keys in redis.

```ruby
sidekiq_options lock_prefix: "uniquejobs" # this is the default value
```

### lock_ttl

Lock TTL decides how long to wait after the job has been successfully processed before making it possible to reuse that lock.

Since `v6.0.11` the other locks will expire after the server is done processing.
Starting from `v7` the expiration will take place when the job is pushed to the queue.

```ruby
sidekiq_options lock_ttl: nil # default - don't expire keys
Expand All @@ -278,6 +322,8 @@ sidekiq_options lock_timeout: nil # lock indefinitely, this process won't contin

This configuration option is slightly misleading. It doesn't disregard the queue on other jobs. Just on itself, this means that a worker that might schedule jobs into multiple queues will be able to have uniqueness enforced on all queues it is pushed to.

This is mainly intended for `Worker.set(queue: :another).perform_async`.

```ruby
class Worker
include Sidekiq::Worker
Expand Down
36 changes: 0 additions & 36 deletions gemfiles/sidekiq_4.1.gemfile

This file was deleted.

0 comments on commit b89cce6

Please sign in to comment.