-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0cdb94e
commit 915df22
Showing
5 changed files
with
74 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ gemspec | |
gem "rails", ">= 7.0.1" | ||
gem "rake" | ||
gem "debug" | ||
gem "puma" |
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,36 @@ | ||
begin | ||
require "puma" | ||
require "puma/configuration" | ||
rescue LoadError | ||
end | ||
|
||
class Propshaft::PumaConfig | ||
def initialize | ||
if defined?(Puma) | ||
@resolved_config = Puma::Configuration.new.load.final_options | ||
end | ||
end | ||
|
||
def multiple_workers? | ||
return false unless @resolved_config | ||
@resolved_config[:workers] > 1 | ||
end | ||
|
||
def self.perform_dev_check! | ||
return true unless new.multiple_workers? | ||
|
||
message = "#" * 80 + "\n" | ||
message += "# " + " " * 76 + " #\n" | ||
message += "# " + "WARNING!!".center(76) + " #\n" | ||
message += "# " + " " * 76 + " #\n" | ||
message += "# Running multiple Puma workers in development is not supported with Propshaft #\n" | ||
message += "# " + " " * 76 + " #\n" | ||
message += "# " + "Make sure WEB_CONCURRENCY is not set or ensure".center(76) + " #\n" | ||
message += "# " + "workers is not set for development in config/puma.rb.".center(76) + " #\n" | ||
message += "# " + " " * 76 + " #\n" | ||
message += "#" * 80 + "\n" | ||
|
||
puts message | ||
false | ||
end | ||
end |
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,29 @@ | ||
require "test_helper" | ||
require "puma" | ||
require "propshaft/puma_config" | ||
require "minitest/mock" | ||
|
||
class Propshaft::PumaConfigTest < ActiveSupport::TestCase | ||
class PumaConfigurationStub | ||
def initialize(workers) | ||
@workers = workers | ||
end | ||
|
||
def load | ||
OpenStruct.new(final_options: { workers: @workers }) | ||
end | ||
end | ||
|
||
{ | ||
0 => false, | ||
1 => false, | ||
2 => true | ||
}.each_pair do |workers, expected| | ||
test "multiple_workers? is #{expected} when config resolves to #{workers}" do | ||
mock = PumaConfigurationStub.new(workers) | ||
Puma::Configuration.stub :new, mock do | ||
assert Propshaft::PumaConfig.new.multiple_workers? == expected | ||
end | ||
end | ||
end | ||
end |