Skip to content

Commit

Permalink
chore: support ruby 2.4 and use redis in test
Browse files Browse the repository at this point in the history
  • Loading branch information
TamarinEA committed Aug 6, 2021
1 parent 09ddb3e commit 09ed078
Show file tree
Hide file tree
Showing 13 changed files with 159 additions and 86 deletions.
98 changes: 79 additions & 19 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,82 @@
build:
test:
image: abakpress/dind-testing
pull: true
privileged: true
volumes:
- /home/data/drone/images:/images
- /home/data/drone/gems:/bundle
name: build

kind: pipeline
type: docker

volumes:
- name: rubygems
host:
path: /home/data/drone/rubygems
- name: images
host:
path: /home/data/drone/images
- name: bundle
host:
path: /home/data/drone/gems
- name: keys
host:
path: /home/data/drone/key_cache

spec_step_common: &spec_step_common
image: abakpress/dind-testing:1.0.3
pull: if-not-exists
privileged: true
volumes:
- name: images
path: /images
- name: bundle
path: /bundle
- name: keys
path: /ssh_keys
commands:
- prepare-build

- fetch-images
--image whilp/ssh-agent
--image abakpress/ruby-app:$RUBY_IMAGE_TAG
--image redis:$REDIS_IMAGE_TAG

- dip ssh add -T -v /ssh_keys -k /ssh_keys/id_rsa
- dip provision
- dip rspec

steps:
- name: Tests Ruby 2.2
environment:
- COMPOSE_FILE_EXT=drone
- POSTGRES_IMAGE_TAG=9.3-latest
- SPHINX_IMAGE_TAG=2.2-latest
commands:
- wrapdocker docker -v
COMPOSE_FILE_EXT: drone
DOCKER_RUBY_VERSION: 2.2
RUBY_IMAGE_TAG: 2.2-latest
REDIS_IMAGE_TAG: 4-alpine
RAILS_ENV: test
<<: *spec_step_common

- name: Tests Ruby 2.3
environment:
COMPOSE_FILE_EXT: drone
DOCKER_RUBY_VERSION: 2.3
RUBY_IMAGE_TAG: 2.3-latest
REDIS_IMAGE_TAG: 4-alpine
RAILS_ENV: test
<<: *spec_step_common

- fetch-images
--image abakpress/ruby-app:$RUBY_IMAGE_TAG
--image abakpress/postgres-db:$POSTGRES_IMAGE_TAG
--image abakpress/sphinx-index:$SPHINX_IMAGE_TAG
- name: Tests Ruby 2.4
environment:
COMPOSE_FILE_EXT: drone
DOCKER_RUBY_VERSION: 2.4
RUBY_IMAGE_TAG: 2.4-latest
REDIS_IMAGE_TAG: 4-alpine
RAILS_ENV: test
<<: *spec_step_common

- dip provision
- dip rspec
- name: release
image: abakpress/gem-publication:latest
pull: if-not-exists
when:
event: push
branch: master
status: success
volumes:
- name: rubygems
path: /root/.gem
commands:
- release-gem --public
9 changes: 9 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
if RUBY_VERSION < '2.4'
appraise 'rails4.0' do
gem 'activesupport', '~> 4.0.0'
end
end

appraise 'rails4.2' do
gem 'activesupport', '~> 4.2.0'
end
1 change: 1 addition & 0 deletions dip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ version: '1'
environment:
DOCKER_RUBY_VERSION: 2.2
RUBY_IMAGE_TAG: 2.2-latest
REDIS_IMAGE_TAG: 4-alpine
COMPOSE_FILE_EXT: development
RAILS_ENV: test

Expand Down
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ services:
environment:
- BUNDLE_PATH=/bundle/$DOCKER_RUBY_VERSION
- BUNDLE_CONFIG=/app/.bundle/config
- TEST_REDIS_HOST=redis
command: bash
depends_on:
- redis

redis:
image: redis:$REDIS_IMAGE_TAG
command: 'redis-server --bind 0.0.0.0'
6 changes: 3 additions & 3 deletions redis_counters.gemspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'redis_counters/version'
Expand All @@ -16,12 +15,13 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']

spec.add_dependency 'activesupport', '>= 3.0', '< 5'
spec.add_runtime_dependency 'activesupport', '>= 4.0', '< 5'

spec.add_development_dependency 'bundler'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rspec', '~> 2.14.0'
spec.add_development_dependency 'mock_redis'
spec.add_development_dependency 'redis', '>= 3.0'
spec.add_development_dependency 'appraisal', '>= 1.0.2'
spec.add_development_dependency 'timecop'
spec.add_development_dependency 'codeclimate-test-reporter', '>= 0.4.1'
spec.add_development_dependency 'simplecov'
Expand Down
4 changes: 2 additions & 2 deletions spec/redis_counters/base_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe RedisCounters::BaseCounter do
let(:redis) { MockRedis.new }
let(:redis) { Redis.current }

let(:options) { {
:counter_class => RedisCounters::HashCounter,
Expand All @@ -26,4 +26,4 @@

it { expect { counter }.to raise_error KeyError }
end
end
end
66 changes: 31 additions & 35 deletions spec/redis_counters/hash_counter_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe RedisCounters::HashCounter do
let(:redis) { MockRedis.new }
let(:redis) { Redis.current }
let(:value) { rand(10) + 1 }
let(:options) { { :counter_name => :test_counter, :field_name => :test_field } }
let(:counter) { described_class.new(redis, options) }
Expand Down Expand Up @@ -89,8 +89,7 @@
before { 3.times { counter.process(:param1 => 21, :param2 => 22, :param3 => 33) } }

it { expect(redis.keys('*')).to have(2).key }
it { expect(redis.keys('*').first).to eq 'test_counter:11:22' }
it { expect(redis.keys('*').last).to eq 'test_counter:21:22' }
it { expect(redis.keys('*')).to match_array ['test_counter:11:22', 'test_counter:21:22'] }
it { expect(redis.hexists('test_counter:11:22', 'test_field')).to be_true }
it { expect(redis.hget('test_counter:11:22', 'test_field')).to eq value.to_s }
it { expect(redis.hexists('test_counter:21:22', 'test_field')).to be_true }
Expand All @@ -108,8 +107,7 @@
before { 3.times { counter.process(:param1 => 2, :param2 => 2) } }

it { expect(redis.keys('*')).to have(2).key }
it { expect(redis.keys('*').first).to eq 'test_counter:true' }
it { expect(redis.keys('*').last).to eq 'test_counter:false' }
it { expect(redis.keys('*')).to match_array ['test_counter:true', 'test_counter:false'] }
it { expect(redis.hexists('test_counter:true', 'test_field')).to be_true }
it { expect(redis.hget('test_counter:true', 'test_field')).to eq 2.to_s }
it { expect(redis.hexists('test_counter:false', 'test_field')).to be_true }
Expand All @@ -129,9 +127,7 @@
before { 1.times { counter.process(:param1 => 21, :param2 => '', :param3 => 33) } }

it { expect(redis.keys('*')).to have(3).key }
it { expect(redis.keys('*').first).to eq 'test_counter:11:22' }
it { expect(redis.keys('*').second).to eq 'test_counter:21:22' }
it { expect(redis.keys('*').third).to eq 'test_counter:21:' }
it { expect(redis.keys('*')).to match_array ['test_counter:11:22', 'test_counter:21:22', 'test_counter:21:'] }
it { expect(redis.hexists('test_counter:11:22', 'test_field')).to be_true }
it { expect(redis.hget('test_counter:11:22', 'test_field')).to eq value.to_s }
it { expect(redis.hexists('test_counter:21:22', 'test_field')).to be_true }
Expand All @@ -153,9 +149,13 @@
before { 1.times { counter.process(:param1 => 2, :param2 => 2, :date => '2013-04-28') } }

it { expect(redis.keys('*')).to have(3).key }
it { expect(redis.keys('*').first).to eq 'test_counter:2013-04-27:true' }
it { expect(redis.keys('*').second).to eq 'test_counter:2013-04-27:false' }
it { expect(redis.keys('*').third).to eq 'test_counter:2013-04-28:false' }
it do
expect(redis.keys('*')).to match_array [
'test_counter:2013-04-27:true',
'test_counter:2013-04-27:false',
'test_counter:2013-04-28:false'
]
end
it { expect(redis.hexists('test_counter:2013-04-27:true', 'test_field')).to be_true }
it { expect(redis.hget('test_counter:2013-04-27:true', 'test_field')).to eq 3.to_s }
it { expect(redis.hexists('test_counter:2013-04-27:false', 'test_field')).to be_true }
Expand All @@ -182,17 +182,14 @@

context 'when no partition params given' do
it { expect(counter.partitions).to have(3).partition }
it { expect(counter.partitions.first).to eq partition_1 }
it { expect(counter.partitions.second).to eq partition_2 }
it { expect(counter.partitions.third).to eq partition_3 }
it { expect(counter.partitions).to match_array [partition_1, partition_2, partition_3] }
end

context 'when one partition param given' do
it { expect(counter.partitions(:param1 => 11)).to have(1).partition }
it { expect(counter.partitions(:param1 => 11).first).to eq partition_1 }
it { expect(counter.partitions(:param1 => 21)).to have(2).partition }
it { expect(counter.partitions(:param1 => 21).first).to eq partition_2 }
it { expect(counter.partitions('param1' => 21).second).to eq partition_3 }
it { expect(counter.partitions(:param1 => 21)).to match_array [partition_2, partition_3] }
end

context 'when two partition params given' do
Expand Down Expand Up @@ -231,9 +228,7 @@
before { 4.times { counter.process(:param1 => 21, :param2 => '', :param3 => 31) } }

it { expect(counter.data(partitions)).to have(3).row }
it { expect(counter.data(partitions).first[:value]).to eq 3 }
it { expect(counter.data(partitions).second[:value]).to eq 2 }
it { expect(counter.data(partitions).third[:value]).to eq 5 }
it { expect(counter.data(partitions)).to match_array [{'value' => 3}, {'value' => 2}, {'value' => 5}] }
end

context 'when group_keys and one group key is nil' do
Expand Down Expand Up @@ -375,8 +370,7 @@
before { counter.delete_partitions!(partition_2) }

it { expect(counter.partitions).to have(2).row }
it { expect(counter.partitions.first).to eq partition_1 }
it { expect(counter.partitions.last).to eq partition_3 }
it { expect(counter.partitions).to match_array [partition_1, partition_3] }
end

context 'when not leaf partition given' do
Expand All @@ -396,9 +390,7 @@
before { counter.delete_partitions!(:param1 => 21, &error_proc) rescue nil }

it { expect(counter.partitions).to have(3).row }
it { expect(counter.partitions.first).to eq partition_1 }
it { expect(counter.partitions.second).to eq partition_2 }
it { expect(counter.partitions.last).to eq partition_3 }
it { expect(counter.partitions).to match_array [partition_1, partition_2, partition_3] }
end
end

Expand All @@ -407,8 +399,7 @@
before { counter.delete_partitions!(partition_2) }

it { expect(counter.partitions).to have(2).row }
it { expect(counter.partitions.first).to eq partition_1 }
it { expect(counter.partitions.last).to eq partition_3 }
it { expect(counter.partitions).to match_array [partition_1, partition_3] }
end

context 'when not leaf partition given' do
Expand All @@ -434,16 +425,21 @@
before { 2.times { counter.process(partition_2) } }
before { 3.times { counter.process(partition_3) } }

it { expect(counter.partitions.first[:param2]).to eq '22:35' }
it { expect(counter.partitions.second[:param2]).to eq '23:26' }
it { expect(counter.partitions.third[:param2]).to eq '24:26' }
it do
expect(counter.partitions).to match_array [
{'param1' => '11', 'param2' => '22:35'},
{'param1' => '11', 'param2' => '23:26'},
{'param1' => '11', 'param2' => '24:26'}
]
end

it { expect(counter.data.first[:param3]).to eq '11:64' }
it { expect(counter.data.first[:value]).to eq 1 }
it { expect(counter.data.second[:param3]).to eq '11:36' }
it { expect(counter.data.second[:value]).to eq 2 }
it { expect(counter.data.third[:param3]).to eq '21:54' }
it { expect(counter.data.third[:value]).to eq 3 }
it do
expect(counter.data).to match_array [
{'value' => 1, 'param3' => '11:64'},
{'value' => 2, 'param3' => '11:36'},
{'value' => 3, 'param3' => '21:54'}
]
end
end

context 'two delimiters' do
Expand Down
10 changes: 5 additions & 5 deletions spec/redis_counters/unique_hash_counter_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe RedisCounters::UniqueHashCounter do
let(:redis) { MockRedis.new }
let(:redis) { Redis.current }
let(:unique_list_postfix) { described_class.const_get(:UNIQUE_LIST_POSTFIX) }

let(:options) { {
Expand Down Expand Up @@ -76,8 +76,8 @@

it { expect(redis.lrange('test_counter_uq:1:partitions', 0, -1)).to eq ['2013-04-28', '2013-04-27'] }
it { expect(redis.lrange('test_counter_uq:2:partitions', 0, -1)).to eq ['2013-04-27'] }
it { expect(redis.smembers('test_counter_uq:1:2013-04-27')).to eq ['4'] }
it { expect(redis.smembers('test_counter_uq:2:2013-04-27')).to eq ['3', '2', '1'] }
it { expect(redis.smembers('test_counter_uq:1:2013-04-28')).to eq ['5', '1'] }
it { expect(redis.smembers('test_counter_uq:1:2013-04-27')).to match_array ['4'] }
it { expect(redis.smembers('test_counter_uq:2:2013-04-27')).to match_array ['3', '2', '1'] }
it { expect(redis.smembers('test_counter_uq:1:2013-04-28')).to match_array ['5', '1'] }
end
end
end
4 changes: 2 additions & 2 deletions spec/redis_counters/unique_values_lists/blocking_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
it_behaves_like 'unique_values_lists/set'

context 'when check partitions list' do
let(:redis) { MockRedis.new }
let(:redis) { Redis.current }
let(:values) { rand(10) + 1 }
let(:partitions_list_postfix) { described_class.const_get(:PARTITIONS_LIST_POSTFIX) }

Expand Down Expand Up @@ -91,4 +91,4 @@
end
end
end
end
end
5 changes: 4 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'bundler/setup'
require 'rspec'
require 'mock_redis'
require 'timecop'
require 'codeclimate-test-reporter'
require 'simplecov'
Expand All @@ -9,11 +8,15 @@
SimpleCov.start('test_frameworks')

require 'redis_counters'
require 'redis'

Redis.current = Redis.new(host: ENV['TEST_REDIS_HOST'])

# require helpers
support_dir = File.expand_path(File.join('..', 'support'), __FILE__)
Dir[File.join(support_dir, '**', '*.rb')].each { |f| require f }

RSpec.configure do |config|
config.backtrace_exclusion_patterns = [/lib\/rspec\/(core|expectations|matchers|mocks)/]
config.before { Redis.current.flushdb }
end
Loading

0 comments on commit 09ed078

Please sign in to comment.