Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for revise #233

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

@eval Main module Revise
#=
Need to support the following in this mock:

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
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 Main.Revise.revise_called_count == 1
# Caveat: We have put the Revise mock in Main, but now can't delete it.
# Hopefully this doesn't affect any other tests.
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
Loading