-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce support for fiber-per-request.
This enables the correct scope of `Fiber.storage` per request. - Unify `clean_thread_locals` and `fiber_per_request` configuration options.
- Loading branch information
Showing
7 changed files
with
97 additions
and
37 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
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,38 @@ | ||
# frozen_string_literal: true | ||
|
||
# Released under the MIT License. | ||
# Copyright, 2023, by Samuel Williams. | ||
|
||
require_relative "helper" | ||
|
||
require "puma/server" | ||
|
||
class FiberLocalApplication | ||
def call(env) | ||
# Just in case you didn't know, this is fiber local... | ||
count = (Thread.current[:request_count] ||= 0) | ||
Thread.current[:request_count] += 1 | ||
[200, {"Content-Type" => "text/plain"}, [count.to_s]] | ||
end | ||
end | ||
|
||
class FiberLocalApplicationTest < Minitest::Test | ||
parallelize_me! | ||
|
||
def setup | ||
@tester = FiberLocalApplication.new | ||
@server = Puma::Server.new @tester, nil, {log_writer: Puma::LogWriter.strings, fiber_per_request: true} | ||
@port = (@server.add_tcp_listener "127.0.0.1", 0).addr[1] | ||
@tcp = "http://127.0.0.1:#{@port}" | ||
@server.run | ||
end | ||
|
||
def teardown | ||
@server.stop(true) | ||
end | ||
|
||
def test_empty_locals | ||
response = hit(["#{@tcp}/test"] * 3) | ||
assert_equal ["0", "0", "0"], response | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# frozen_string_literal: true | ||
|
||
# Released under the MIT License. | ||
# Copyright, 2023, by Samuel Williams. | ||
|
||
require_relative "helper" | ||
|
||
require "puma/server" | ||
|
||
class FiberStorageApplication | ||
def call(env) | ||
count = (Fiber[:request_count] ||= 0) | ||
Fiber[:request_count] += 1 | ||
[200, {"Content-Type" => "text/plain"}, [count.to_s]] | ||
end | ||
end | ||
|
||
class FiberStorageApplicationTest < Minitest::Test | ||
parallelize_me! | ||
|
||
def setup | ||
skip "Fiber Storage is not supported on this Ruby" unless Fiber.respond_to?(:[]) | ||
|
||
@tester = FiberStorageApplication.new | ||
@server = Puma::Server.new @tester, nil, {log_writer: Puma::LogWriter.strings, fiber_per_request: true} | ||
@port = (@server.add_tcp_listener "127.0.0.1", 0).addr[1] | ||
@tcp = "http://127.0.0.1:#{@port}" | ||
@server.run | ||
end | ||
|
||
def teardown | ||
@server.stop(true) | ||
end | ||
|
||
def test_empty_storage | ||
response = hit(["#{@tcp}/test"] * 3) | ||
assert_equal ["0", "0", "0"], response | ||
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