web/backend: use multiprocessing instead of threads; improve logging

This commit is contained in:
2025-11-12 11:52:30 -06:00
parent 117bf478f4
commit c9e18d4fe4
9 changed files with 102 additions and 32 deletions

View File

@@ -4,6 +4,8 @@
module BackendT
using Distributed
using Test
using HTTP
using JSON
@@ -22,6 +24,7 @@ function fixture(path::String)::String
end
function runtests()
Backend.setup_logger()
@testset "UCJL Backend" begin
server_test_usage()
jobs_test_usage()

View File

@@ -7,10 +7,14 @@ using Test
function jobs_test_usage()
@testset "JobProcessor" begin
# Define dummy work function
received_job_id = []
# Create a temporary directory for test output
test_dir = mktempdir()
# Define dummy work function that writes to a file
# Note: This function will be executed on a worker process
function work_fn(job_id)
push!(received_job_id, job_id)
output_file = joinpath(test_dir, job_id * ".txt")
write(output_file, job_id)
return
end
@@ -24,10 +28,16 @@ function jobs_test_usage()
put!(processor, "test")
# Wait for job to complete
sleep(0.1)
# Increased timeout to account for worker process startup
sleep(2)
stop(processor)
# Check that the work function was called with correct job_id
@test received_job_id[1] == "test"
output_file = joinpath(test_dir, "test.txt")
@test isfile(output_file)
@test read(output_file, String) == "test"
# Clean up
rm(test_dir; recursive = true)
end
end

View File

@@ -13,7 +13,7 @@ function server_test_usage()
# Submit test case
response = HTTP.post(
"http://$HOST:$PORT/submit",
"http://$HOST:$PORT/api/submit",
["Content-Type" => "application/gzip"],
compressed_data,
)
@@ -26,7 +26,7 @@ function server_test_usage()
@test length(job_id) == 16
# Wait for jobs to finish
sleep(0.1)
sleep(5)
while isbusy(server.processor)
sleep(0.1)
end
@@ -43,7 +43,7 @@ function server_test_usage()
@test saved_data == compressed_data
# Query job information
view_response = HTTP.get("http://$HOST:$PORT/jobs/$job_id/view")
view_response = HTTP.get("http://$HOST:$PORT/api/jobs/$job_id/view")
@test view_response.status == 200
# Check response