Skip to content

Commit

Permalink
Add tests for revise argument to serve(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
frankier committed Nov 19, 2024
1 parent ede9d60 commit 83d5b9d
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
69 changes: 69 additions & 0 deletions test/revise.jl
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

1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ include("taskmanagement.jl")
include("cronmanagement.jl")
include("middlewaretests.jl")
include("originaltests.jl")
include("revise.jl")

#### Scenario Tests ####
include("./scenarios/thunderingherd.jl")
Expand Down

0 comments on commit 83d5b9d

Please sign in to comment.