Skip to content

Commit

Permalink
[types] totally refactored type definitions (#8)
Browse files Browse the repository at this point in the history
* [types] totally refactored type definitions

* [types/ci] simplecov + rspec-retry

* [types/ci] ruby31 + ruby32 + rbs_collection step

* [types/ci] clarifications about rspec-retry

* [types/simplecov] doc updates

* [types] codestyle

* [test-coverage] clarifications
  • Loading branch information
0exp authored Dec 2, 2024
1 parent 86ba8c4 commit 46eb5e6
Show file tree
Hide file tree
Showing 88 changed files with 1,153 additions and 895 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
- name: (Linter) Rubocop
run: bundle exec rake rubocop
- name: (TypeCheck) Steep
run: bundle exec steep check --jobs 10
run: bundle exec rbs collection install && bundle exec steep check --jobs 10
continue-on-error: true
- name: (Test) RSpec
run: bundle exec rake rspec
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
/tmp/
.rspec_status
*.gem
/.gem_rbs_collection/
17 changes: 12 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
## [Unreleased]

## Changed
### Changed
- Updated development dependencies (`armitage-rubocop`);
- CI is splitted to "mainstream ruby version" and "previous actually maintaned ruby versions";
- `Acquier` -> `Acquirer`, `Acquierment` -> `Acquirement` (typos):
Expand All @@ -9,9 +8,17 @@
- [**Breaking**] Logs: all `acquier` text parts of each log message type were renamed to `acquirer`;
- [**Breaking**] Instrumentation: all `acquier` text parts of each event name were renamed to `acquirer`;
- [**Breaking**] Exceptions: all `Acquierment` exception constant name parts were renamed to `Acquirement`;
## Added
- Type signatures (`RBS`, see the `sig` directory) + `Steep` integration (see `Steepfile` for details);
- CI: added `TypeCheck` step;
- [**Breaking**] `RedisQueuedLocks::Data` is not used (**temporary**) as result type of some APIs.
This type is inherited from Hash and can not be used as a record type in `steep`/`rbs` (working on it);
### Added
- **Type Checking**:
- the code is fully typed;
- (steep + rbs) officialy supported `RBS` with a `Steep` integration that works
in **strict mode** (see `sig` directory, `Steepfile` config, `sig/manifest.yml` and `rbs_collection.yml` for dependencies);
- Added `TypeCheck` step to CI/CD;
- Test coverage checks (via `simplecov` with `html` and `lcov` formats).
Temporary locked on `~95%` and without CI integration cuz we need to refactor tests in first;
- CI: `rspec-retry` is temporary added until the tests are fully refactored;

## [1.12.1]
### Changed
Expand Down
19 changes: 11 additions & 8 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ source 'https://rubygems.org'

gemspec

gem 'activesupport'
gem 'armitage-rubocop'
gem 'bundler'
gem 'pry'
gem 'rake'
gem 'rbs'
gem 'rspec'
gem 'steep'
gem 'activesupport', require: false
gem 'armitage-rubocop', require: false
gem 'bundler', require: false
gem 'pry', require: false
gem 'rake', require: false
gem 'rbs', require: false
gem 'rspec', require: false
gem 'rspec-retry', require: false # NOTE: temporary decision for non-refactored tests
gem 'simplecov', require: false
gem 'simplecov-lcov', require: false
gem 'steep', require: false
21 changes: 17 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ GEM
connection_pool (2.4.1)
csv (3.3.0)
diff-lcs (1.5.1)
docile (1.4.1)
drb (2.2.1)
ffi (1.17.0)
ffi (1.17.0-aarch64-linux-gnu)
Expand All @@ -59,7 +60,7 @@ GEM
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
logger (1.6.1)
logger (1.6.2)
method_source (1.1.0)
minitest (5.25.2)
parallel (1.26.3)
Expand All @@ -81,7 +82,7 @@ GEM
logger
redis-client (0.22.2)
connection_pool
regexp_parser (2.9.2)
regexp_parser (2.9.3)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
Expand All @@ -94,6 +95,8 @@ GEM
rspec-mocks (3.13.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-retry (0.6.2)
rspec-core (> 3.3)
rspec-support (3.13.1)
rubocop (1.68.0)
json (~> 2.3)
Expand All @@ -105,7 +108,7 @@ GEM
rubocop-ast (>= 1.32.2, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.36.1)
rubocop-ast (1.36.2)
parser (>= 3.3.1.0)
rubocop-capybara (2.21.0)
rubocop (~> 1.41)
Expand All @@ -127,7 +130,14 @@ GEM
rubocop (~> 1.61)
rubocop-rspec (~> 3, >= 3.0.1)
ruby-progressbar (1.13.0)
securerandom (0.3.2)
securerandom (0.4.0)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.13.1)
simplecov-lcov (0.8.0)
simplecov_json_formatter (0.1.4)
steep (1.8.3)
activesupport (>= 5.1)
concurrent-ruby (>= 1.1.10)
Expand Down Expand Up @@ -173,6 +183,9 @@ DEPENDENCIES
rbs
redis_queued_locks!
rspec
rspec-retry
simplecov
simplecov-lcov
steep

BUNDLED WITH
Expand Down
3 changes: 3 additions & 0 deletions github_ci/ruby3.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ gem 'pry'
gem 'rake'
gem 'rbs'
gem 'rspec'
gem 'rspec-retry' # NOTE: temporary decision for non-refactored tests
gem 'simplecov'
gem 'simplecov-lcov'
gem 'steep'
13 changes: 13 additions & 0 deletions github_ci/ruby3.1.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ GEM
connection_pool (2.4.1)
csv (3.3.0)
diff-lcs (1.5.1)
docile (1.4.1)
drb (2.2.1)
ffi (1.17.0)
ffi (1.17.0-aarch64-linux-gnu)
Expand Down Expand Up @@ -93,6 +94,8 @@ GEM
rspec-mocks (3.13.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-retry (0.6.2)
rspec-core (> 3.3)
rspec-support (3.13.1)
rubocop (1.59.0)
json (~> 2.3)
Expand Down Expand Up @@ -127,6 +130,13 @@ GEM
rubocop-factory_bot (~> 2.22)
ruby-progressbar (1.13.0)
securerandom (0.3.2)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.13.1)
simplecov-lcov (0.8.0)
simplecov_json_formatter (0.1.4)
steep (1.8.3)
activesupport (>= 5.1)
concurrent-ruby (>= 1.1.10)
Expand Down Expand Up @@ -171,6 +181,9 @@ DEPENDENCIES
rbs
redis_queued_locks!
rspec
rspec-retry
simplecov
simplecov-lcov
steep

BUNDLED WITH
Expand Down
3 changes: 3 additions & 0 deletions github_ci/ruby3.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ gem 'pry'
gem 'rake'
gem 'rbs'
gem 'rspec'
gem 'rspec-retry' # NOTE: temporary decision for non-refactored tests
gem 'simplecov'
gem 'simplecov-lcov'
gem 'steep'
13 changes: 13 additions & 0 deletions github_ci/ruby3.2.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ GEM
connection_pool (2.4.1)
csv (3.3.0)
diff-lcs (1.5.1)
docile (1.4.1)
drb (2.2.1)
ffi (1.17.0)
ffi (1.17.0-aarch64-linux-gnu)
Expand Down Expand Up @@ -93,6 +94,8 @@ GEM
rspec-mocks (3.13.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-retry (0.6.2)
rspec-core (> 3.3)
rspec-support (3.13.1)
rubocop (1.59.0)
json (~> 2.3)
Expand Down Expand Up @@ -127,6 +130,13 @@ GEM
rubocop-factory_bot (~> 2.22)
ruby-progressbar (1.13.0)
securerandom (0.3.2)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.13.1)
simplecov-lcov (0.8.0)
simplecov_json_formatter (0.1.4)
steep (1.8.3)
activesupport (>= 5.1)
concurrent-ruby (>= 1.1.10)
Expand Down Expand Up @@ -171,6 +181,9 @@ DEPENDENCIES
rbs
redis_queued_locks!
rspec
rspec-retry
simplecov
simplecov-lcov
steep

BUNDLED WITH
Expand Down
22 changes: 14 additions & 8 deletions lib/redis_queued_locks/acquirer/acquire_lock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class << self
# Lock's time to live (in milliseconds). Nil means "without timeout".
# @option queue_ttl [Integer]
# Lifetime of the acuier's lock request. In seconds.
# @option timeout [Integer]
# @option timeout [Integer,NilClass]
# Time period whe should try to acquire the lock (in seconds).
# @option timed [Boolean]
# Limit the invocation time period of the passed block of code by the lock's TTL.
Expand Down Expand Up @@ -148,7 +148,7 @@ class << self
# - makes sense when instrumentation sampling is enabled;
# @param [Block]
# A block of code that should be executed after the successfully acquired lock.
# @return [RedisQueuedLocks::Data,Hash<Symbol,Any>,yield]
# @return [Hash<Symbol,Any>,yield]
# - Format: { ok: true/false, result: Any }
# - If block is given the result of block's yeld will be returned.
#
Expand Down Expand Up @@ -256,7 +256,7 @@ def acquire_lock(
)

# Step X: intermediate result observer
# @type var acq_process: ::Hash[::Symbol,untyped]
# @type var acq_process: Hash[Symbol,untyped]
acq_process = {
lock_info: {},
should_try: true,
Expand Down Expand Up @@ -319,6 +319,8 @@ def acquire_lock(
)
end

# NOTE: (steep ignorance) pattern matching is not supported in steep
# steep:ignore:start
try_to_lock(
redis,
logger,
Expand All @@ -337,8 +339,10 @@ def acquire_lock(
log_sampled,
instr_sampled
) => { ok:, result: }
# steep:ignore:end

# @type var ok: bool
# @type var result: ::Symbol|::Hash[::Symbol,untyped]
# @type var result: Symbol|Hash[Symbol,untyped]

acq_end_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, :microsecond)
acq_time = ((acq_end_time - acq_start_time) / 1_000.0).ceil(2)
Expand All @@ -349,7 +353,7 @@ def acquire_lock(

# Step 2.1: analyze an acquirement attempt
if ok
# @type var result: ::Hash[::Symbol,untyped]
# @type var result: Hash[Symbol,untyped]

# Step X: (instrumentation)
if acq_process[:result][:process] == :extendable_conflict_work_through
Expand Down Expand Up @@ -402,7 +406,7 @@ def acquire_lock(
acq_process[:acq_time] = acq_time
acq_process[:acq_end_time] = acq_end_time
else
# @type var result: ::Symbol
# @type var result: Symbol

# Step 2.2: failed to acquire. anylize each case and act in accordance
if acq_process[:result] == :fail_fast_no_try # Step 2.2.a: fail without try
Expand Down Expand Up @@ -545,7 +549,9 @@ def acquire_lock(
end
end
else
RedisQueuedLocks::Data[ok: true, result: acq_process[:lock_info]] # steep:ignore
# rubocop:disable Layout/LineLength
{ ok: true, result: acq_process[:lock_info] } #: { ok: bool, result: Hash[Symbol,untyped] }
# rubocop:enable Layout/LineLength
end
else
if acq_process[:result] != :retry_limit_reached &&
Expand All @@ -559,7 +565,7 @@ def acquire_lock(
acq_process[:result] = :timeout_reached
end
# Step 3.b: lock is not acquired (acquirer is dequeued by timeout callback)
RedisQueuedLocks::Data[ok: false, result: acq_process[:result]] # steep:ignore
{ ok: false, result: acq_process[:result] } #: { ok: bool, result: Symbol }
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module RedisQueuedLocks::Acquirer::AcquireLock::DelayExecution
#
# @param retry_delay [Integer] In milliseconds
# @param retry_jitter [Integer] In milliseconds
# @return [void]
# @return [Integer] Slept seconds
#
# @api private
# @since 1.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module RedisQueuedLocks::Acquirer::AcquireLock::DequeueFromLockQueue
# @param access_strategy [Symbol]
# @param log_sampled [Boolean]
# @param instr_sampled [Boolean]
# @return [Hash<Symbol,Any>] Format: { ok: true/false, result: Any }
# @return [Hash<Symbol,Any>] Format: { ok: true/false, result: Integer }
#
# @api private
# @since 1.7.0
Expand All @@ -32,11 +32,14 @@ def dequeue_from_lock_queue(
log_sampled,
instr_sampled
)
# @type var result: Integer
result = redis.call('ZREM', lock_key_queue, acquirer_id)

LogVisitor.dequeue_from_lock_queue(
logger, log_sampled,
lock_key, queue_ttl, acquirer_id, host_id, access_strategy
)
RedisQueuedLocks::Data[ok: true, result: result] # steep:ignore

{ ok: true, result: result }
end
end
Loading

0 comments on commit 46eb5e6

Please sign in to comment.