-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: provider switching should be threadsafe
Signed-off-by: Manuel Schönlaub <[email protected]>
- Loading branch information
1 parent
341f069
commit f5dc47d
Showing
4 changed files
with
57 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
module BackgroundHelper | ||
attr_writer :threads | ||
|
||
private | ||
|
||
def background(&) | ||
thread = Thread.new(&) | ||
thread.report_on_exception = false | ||
threads << thread | ||
thread.join(0.1) | ||
thread | ||
end | ||
|
||
def threads | ||
@threads ||= [] | ||
end | ||
|
||
def yield_to_background | ||
threads.each(&:join) | ||
end | ||
end | ||
|
||
RSpec.configure do |config| | ||
config.after do | ||
threads.each(&:kill) | ||
self.threads = [] | ||
end | ||
config.include(BackgroundHelper) | ||
end |