web: backend: Implement view endpoint

This commit is contained in:
2025-11-07 11:32:14 -06:00
parent ad8ee6fe6b
commit 1254780e42
4 changed files with 104 additions and 68 deletions

View File

@@ -6,39 +6,55 @@ const PORT = 32617
function server_test_usage()
server = Backend.start_server(PORT; optimizer = HiGHS.Optimizer)
try
# Read the compressed fixture file
compressed_data = read(fixture("case14.json.gz"))
# Read the compressed fixture file
compressed_data = read(fixture("case14.json.gz"))
# Submit test case
response = HTTP.post(
"http://localhost:$PORT/submit",
["Content-Type" => "application/gzip"],
compressed_data,
)
@test response.status == 200
# Submit test case
response = HTTP.post(
"http://localhost:$PORT/submit",
["Content-Type" => "application/gzip"],
compressed_data,
)
@test response.status == 200
# Check response
response_data = JSON.parse(String(response.body))
@test haskey(response_data, "job_id")
job_id = response_data["job_id"]
@test length(job_id) == 16
# Check response
response_data = JSON.parse(String(response.body))
@test haskey(response_data, "job_id")
job_id = response_data["job_id"]
@test length(job_id) == 16
# Wait for jobs to finish
sleep(0.1)
while isbusy(server.processor)
sleep(0.1)
end
# Wait for jobs to finish and stop server
sleep(0.1)
stop(server)
# Verify the compressed file was saved correctly
job_dir = joinpath(Backend.basedir, "jobs", job_id)
saved_input_path = joinpath(job_dir, "input.json.gz")
saved_log_path = joinpath(job_dir, "output.log")
saved_output_path = joinpath(job_dir, "output.json")
@test isfile(saved_input_path)
@test isfile(saved_log_path)
@test isfile(saved_output_path)
saved_data = read(saved_input_path)
@test saved_data == compressed_data
# Verify the compressed file was saved correctly
job_dir = joinpath(Backend.basedir, "jobs", job_id)
saved_input_path = joinpath(job_dir, "input.json.gz")
saved_log_path = joinpath(job_dir, "output.log")
saved_output_path = joinpath(job_dir, "output.json")
@test isfile(saved_input_path)
@test isfile(saved_log_path)
@test isfile(saved_output_path)
saved_data = read(saved_input_path)
@test saved_data == compressed_data
# Query job information
view_response = HTTP.get("http://localhost:$PORT/jobs/$job_id/view")
@test view_response.status == 200
# Clean up: remove the job directory
rm(job_dir, recursive=true)
# Check response
view_data = JSON.parse(String(view_response.body))
@test haskey(view_data, "log")
@test haskey(view_data, "solution")
@test view_data["log"] !== nothing
@test view_data["solution"] !== nothing
# Clean up
rm(job_dir, recursive=true)
finally
stop(server)
end
end