-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Thread safety #1700
Comments
I don't think there are any places that modify values and everything should be deterministic. Can you point out some example on where the thread safety breaks down? |
@Zeragamba: I need to call Here's a reproduction script... expected_values = 2.times.map do |index|
Faker::Config.random = Random.new(index)
Faker::Number.digit
end
threads = expected_values.each_with_index.map do |expected_value, index|
Thread.new do
100000.times.each do |run_count|
Faker::Config.random = Random.new(index)
output = Faker::Number.digit
if output != expected_value
raise "Thread #{index} run occurrence #{run_count} expected #{expected_value} " +
"but got #{output}"
end
end
puts "Thread #{index} completed successfully"
end
end
threads.join And here's a run where it reproduced...
|
Just wanted to check in and see if any progress has been made on this issue. I also would like to be able to instantiate a |
Agree this is a big issue for me as well. Any pointers on how this change might be able to be made? Maybe just an option for |
I think probably for the same reasons |
Hey, folks. In an effort to lighten our load as maintainers and be able to serve you better in the future, the faker-ruby team is working on cleaning out the cobwebs in this repo by pruning the backlog. As there are few of us, there are a lot of items that will simply never earn our attention in a reasonable time frame, and rather than giving you an empty promise, we think it makes more sense to focus on more recent issues. That means, unfortunately, that we must close this issue. Don't take this the wrong way: our aim is not to diminish the effort people have made or dismiss problems that have been raised. If you feel that we should reopen this issue, then please let us know so that we can reprioritize it. Thanks! |
I was able to reproduce the issue based on this suggestion require 'faker'
expected_values = 2.times.map do |index|
Faker::Config.random = Random.new(index)
Faker::Number.digit
end
threads = expected_values.each_with_index.map do |expected_value, index|
Thread.new do
1_000_000.times.each do |run_count|
Faker::Config.random = Random.new(index)
output = Faker::Number.digit
if output != expected_value
raise "Thread #{index} run occurrence #{run_count} expected #{expected_value} " +
"but got #{output}"
end
end
puts "Thread #{index} completed successfully"
end
end
threads.each(&:join) Result:
|
fixed by #2520 |
It appears as though every method defined in this gem is intended to be called as a class method, not an instance method. Of course these class methods often modify class variables which makes it impossible to use this gem in a thread safe way without locking threads.
Was the decision made to sacrifice thread safety in order to call methods easily on classes? Were there any other reasons why thread safety wasn't considered?
I'd like to use this gem to generate deterministic fake data for a preproduction API that runs in Puma (threads instead of processes). Was hoping there was a way to use it without needing to lock.
The text was updated successfully, but these errors were encountered: