-
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.
Add tests for revise argument to serve(...)
- Loading branch information
Showing
2 changed files
with
70 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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
module ReviseTest | ||
|
||
using Test | ||
using Oxygen; @oxidise | ||
using ..Constants | ||
using HTTP | ||
|
||
@get "/" function() | ||
return text("Ok") | ||
end | ||
|
||
# Test error message when Revise not used | ||
|
||
error_task = @async begin | ||
for revise in (:lazy, :eager) | ||
@test_throws "You must load Revise.jl before Oxygen.jl" serve(port=PORT, host=HOST, show_errors=false, show_banner=false, access_log=nothing, revise=revise) | ||
end | ||
end | ||
|
||
if timedwait(()->istaskdone(error_task), 60) == :timed_out | ||
error("Timed out waiting for Revise usage error") | ||
end | ||
|
||
# Test usage with user provided middleware | ||
|
||
module ReviseMock | ||
#= | ||
Need to support the following: | ||
Revise = Main.Revise | ||
isempty(Revise.revision_queue) | ||
wait(Revise.revision_event) | ||
Revise.revise() | ||
=# | ||
|
||
revision_queue = [nothing] # non-empty | ||
revision_event = Base.Event() | ||
notify(revision_event) # wait(...) always returns immediately | ||
revise_called_count = 0 | ||
|
||
function revise() | ||
global revise_called_count | ||
revise_called_count += 1 | ||
end | ||
end | ||
|
||
invocation = [] | ||
|
||
function handler1(handler) | ||
return function(req::HTTP.Request) | ||
push!(invocation, 1) | ||
handler(req) | ||
end | ||
end | ||
|
||
Oxygen.WAS_LOADED_AFTER_REVISE[] = true | ||
@eval Main Revise = ReviseMock | ||
serve(port=PORT, host=HOST, show_errors=false, show_banner=false, access_log=nothing, revise=:lazy, middleware=[handler1], async=true) | ||
@test String(HTTP.get("$localhost/").body) == "Ok" | ||
@test invocation == [1] | ||
@test ReviseMock.revise_called_count == 1 | ||
Main.Revise = nothing | ||
Oxygen.WAS_LOADED_AFTER_REVISE[] = false | ||
|
||
terminate() | ||
println() | ||
|
||
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