Skip to content

Commit

Permalink
add GoAWSConfig constructor, improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ericphanson committed Nov 15, 2023
1 parent 751cd20 commit bf0649c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GoAWS"
uuid = "00b10cec-568b-4d01-83ea-8604cd7f25ae"
authors = ["Beacon Biosignals", "Inc."]
version = "1.0.0"
version = "1.1.0"

[deps]
AWS = "fbe9abb3-538b-5e4e-ba9e-bc94f4f92ebc"
Expand Down
5 changes: 4 additions & 1 deletion src/server.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,13 @@ function with_go_aws(f; address=DEFAULT_ADDRESS, region="us-east-2", kw...)
try
run(server; wait=false)
sleep(0.5) # give the server just a bit of time, though it is very fast to start
config = GoAWSConfig(address, region)
config = GoAWSConfig(server)
f(config)
finally
# Make sure we kill the server even if a test failed.
kill(server)
end
end

# Helper to create a config from a server directly
GoAWSConfig(s::Server) = GoAWSConfig(; endpoint=s.address, s.region)
16 changes: 13 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,31 @@ using URIs
Aqua.test_all(GoAWS; ambiguities=false)
end

port = 41231
@testset "GoAWS.jl" begin
@testset "Server" begin
server = GoAWS.Server(; address="localhost:4103")
@test sprint(show, server) == "GoAWS.Server(\"http://localhost:4103\", unstarted)"
server = GoAWS.Server(; address="localhost:$port")
@test sprint(show, server) == "GoAWS.Server(\"http://localhost:$port\", unstarted)"

config = GoAWSConfig(server) # test constructing config from server object
@test config.endpoint == server.address
@test config.region == server.region

@test_throws ErrorException kill(server)
@test_throws ErrorException process_running(server)
@test_throws ErrorException process_exited(server)
@test_throws ErrorException getpid(server)
@test isnothing(server.config_path)
run(server; wait=false)
sleep(0.5)
try
@test sprint(show, server) ==
"GoAWS.Server(\"http://localhost:$port\", running)"
@test getpid(server) isa Number
@test process_running(server)
@test !isnothing(server.config_path)
# While the port is occupied, test we can load another server on another port
server2 = GoAWS.Server(; address="localhost:4104")
server2 = GoAWS.Server(; address="localhost:$(port+1)")
run(server2; wait=false)
sleep(1) # let it startup before we kill it, so we get a 0 exitcode
kill(server2)
Expand All @@ -37,6 +45,8 @@ end
kill(server)
sleep(1)
end
@test sprint(show, server) ==
"GoAWS.Server(\"http://localhost:$port\", exited successfully)"
@test process_exited(server)
@test server.process.exitcode == 0
@test isnothing(server.config_path)
Expand Down

0 comments on commit bf0649c

Please sign in to comment.