-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature/middleware-cache-lock (#227)
* added middleware_cache_lock * used double-checked locking to reduce the overhead of acquiring a lock * added a new specific scenarios test sets
- Loading branch information
Showing
6 changed files
with
86 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
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,64 @@ | ||
module ThunderingHerdTest | ||
using Test | ||
using HTTP | ||
using ..Constants | ||
using Oxygen; @oxidise | ||
|
||
allowed_origins = [ "Access-Control-Allow-Origin" => "*" ] | ||
|
||
cors_headers = [ | ||
allowed_origins..., | ||
"Access-Control-Allow-Headers" => "*", | ||
"Access-Control-Allow-Methods" => "GET, POST" | ||
] | ||
|
||
function CorsHandler(handle) | ||
return function (req::HTTP.Request) | ||
# return headers on OPTIONS request | ||
if HTTP.method(req) == "OPTIONS" | ||
return HTTP.Response(200, cors_headers) | ||
else | ||
r = handle(req) | ||
append!(r.headers, allowed_origins) | ||
return r | ||
end | ||
end | ||
end | ||
|
||
index = router(middleware=[CorsHandler]) | ||
|
||
@get index("/") function(req) | ||
return "Hello World" | ||
end | ||
|
||
serve( | ||
port = PORT, | ||
host = HOST, | ||
async = true, | ||
show_errors = false, | ||
show_banner = false, | ||
access_log = nothing, | ||
parallel = Base.Threads.nthreads() > 1 | ||
) | ||
|
||
@testset "async spam requests" begin | ||
|
||
success = 0 | ||
failures = 0 | ||
|
||
@sync @async for x in 1:100 | ||
r = HTTP.request("GET", "$localhost/") | ||
if r.status == 200 && String(r.body) == "Hello World" | ||
success += 1 | ||
else | ||
failures += 1 | ||
end | ||
end | ||
|
||
@test success == 100 | ||
@test failures == 0 | ||
end | ||
|
||
terminate() | ||
|
||
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