Skip to content

Commit

Permalink
Merge pull request #33 from ohbarye/drop-experimental_ractor_rspec_in…
Browse files Browse the repository at this point in the history
…tegration

Drop experimental_ractor_rspec_integration
  • Loading branch information
ohbarye authored Dec 30, 2024
2 parents 72daf47 + 3bc7511 commit 734e2bb
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 293 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## [Unreleased]

- Drop `:process` and `:thread` workers since there are no concrete use cases.
- Drop `:experimental_ractor_rspec_integration` option since there are no concrete use cases.

## [0.4.2] - 2024-05-23

Expand Down
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ gemspec
gem "rake"
gem "rspec"
gem "standard"
gem "prism"
gem "benchmark-ips"
21 changes: 1 addition & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,6 @@ Pbt.configure do |config|
# Whether to report exceptions in threads.
# It's useful to suppress error logs on Ractor that reports many errors. Default is `false`.
config.thread_report_on_exception = false
# Whether to allow RSpec expectation and matchers in Ractor. It's quite experimental! Default is `false`.
config.experimental_ractor_rspec_integration = false
end
```

Expand Down Expand Up @@ -295,22 +292,6 @@ it do
end
```

If you're a challenger, you can enable the experimental feature to allow using RSpec expectations and matchers in Ractor. It works but it's quite experimental and could cause unexpected behaviors.

Please note that this feature depends on [prism](https://ruby.github.io/prism/) gem. If you use Ruby 3.2 or prior, you need to install the gem by yourself.

```ruby
it do
Pbt.assert(worker: :ractor, experimental_ractor_rspec_integration: true) do
Pbt.property(Pbt.integer) do |n|
# Some RSpec expectations and matchers are available in Ractor by hack.
# Other features like `let`, `subject`, `before`, `after` that access out of block are still not available.
expect(n).to be_an(Integer)
end
end
end
```

### None

For most cases, `:none` is the best choice. It runs tests sequentially but most test cases finishes within a reasonable time.
Expand Down Expand Up @@ -341,7 +322,7 @@ Once this project finishes the following, we will release v1.0.0.
- [x] Configuration
- [x] Benchmark
- [x] Rich report by verbose mode
- [x] (Partially) Allow to use expectations and matchers provided by test framework in Ractor if possible.
- [x] (Partially) Allow to use expectations and matchers provided by test framework in Ractor. (dropped)
- It'd be so hard to pass assertions like `expect`, `assert` to a Ractor.
- [ ] Implement frequency arbitrary
- [ ] Statistics feature to aggregate generated values
Expand Down
5 changes: 1 addition & 4 deletions lib/pbt/check/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,19 @@ module Check
:num_runs,
:seed,
:thread_report_on_exception,
:experimental_ractor_rspec_integration,
keyword_init: true
) do
# @param verbose [Boolean] Whether to print verbose output. Default is `false`.
# @param worker [Symbol] The concurrency method to use. :ractor` and `:none` are supported. Default is `:none`.
# @param num_runs [Integer] The number of runs to perform. Default is `100`.
# @param seed [Integer] The seed to use for random number generation. It's useful to reproduce failed test with the seed you'd pick up from failure messages. Default is a random seed.
# @param thread_report_on_exception [Boolean] Whether to report exceptions in threads. It's useful to suppress error logs on Ractor that reports many errors. Default is `false`.
# @param experimental_ractor_rspec_integration [Boolean] Whether to allow RSpec expectation and matchers in Ractor. It's quite experimental! Default is `false`.
def initialize(
verbose: false,
worker: :none,
num_runs: 100,
seed: Random.new_seed,
thread_report_on_exception: false,
experimental_ractor_rspec_integration: false
thread_report_on_exception: false
)
super
end
Expand Down
64 changes: 0 additions & 64 deletions lib/pbt/check/rspec_adapter/integration.rb

This file was deleted.

47 changes: 0 additions & 47 deletions lib/pbt/check/rspec_adapter/predicate_block_inspector.rb

This file was deleted.

74 changes: 0 additions & 74 deletions lib/pbt/check/rspec_adapter/property_extension.rb

This file was deleted.

28 changes: 1 addition & 27 deletions lib/pbt/check/runner_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ def check(**options, &property)
#
# - `:thread_report_on_exception`
# So many exception reports happen in Ractor and a console gets too messy. Suppress them to avoid that.
# - `:experimental_ractor_rspec_integration`
# Allow to use Ractor with RSpec. This is an experimental feature and it's not stable.
#
# @param config [Hash] Configuration parameters.
# @param property [Property]
Expand All @@ -64,21 +62,12 @@ def setup_for_ractor(config, property, &block)
if config[:worker] == :ractor
original_report_on_exception = Thread.report_on_exception
Thread.report_on_exception = config[:thread_report_on_exception]

if config[:experimental_ractor_rspec_integration]
require "pbt/check/rspec_adapter/integration"
class << property
include Pbt::Check::RSpecAdapter::PropertyExtension
end
property.setup_rspec_integration
end
end

yield
ensure
if config[:worker] == :ractor
Thread.report_on_exception = original_report_on_exception
property.teardown_rspec_integration if config[:experimental_ractor_rspec_integration]
end
end

Expand Down Expand Up @@ -129,26 +118,11 @@ def run_it_in_ractors(property, runner)
c.ractor.take
runner.handle_result(c)
rescue => e
handle_ractor_error(e.cause, c)
c.exception = e.cause # Ractor error is wrapped in a Ractor::RemoteError. We need to get the cause.
runner.handle_result(c)
break # Ignore the rest of the cases. Just pick up the first failure.
end
end

def handle_ractor_error(cause, c)
# Ractor error is wrapped in a Ractor::RemoteError. We need to get the cause.
unless defined?(Pbt::Check::RSpecAdapter) && cause.is_a?(Pbt::Check::RSpecAdapter::ExpectationNotMet) # Unknown error.
c.exception = cause
return
end

# Convert Pbt's custom error to RSpec's error.
begin
RSpec::Expectations::ExpectationHelper.handle_failure(cause.matcher, cause.custom_message, cause.failure_message_method)
rescue RSpec::Expectations::ExpectationNotMetError => e # The class inherits Exception, not StandardError.
c.exception = e
end
end
end
end
end
Loading

0 comments on commit 734e2bb

Please sign in to comment.