Make thread count adjustable

This commit is contained in:
Hugo Mårdbrink 2025-11-13 16:40:18 +01:00
parent 0bf25b991f
commit 595872f81c
3 changed files with 26 additions and 17 deletions

View file

@ -20,7 +20,7 @@ first_handler :: proc(request: ^http.Request) -> (http.Response, Error) {
entity := request.path_variables["entity"]
body := strings.concatenate(
{"<div>Hello first", entity, "</div>"},
{"<div>Hello first ", entity, "</div>"},
context.temp_allocator,
)
response := http.make_response(
@ -37,7 +37,7 @@ second_handler :: proc(request: ^http.Request) -> (http.Response, Error) {
entity := request.path_variables["entity"]
body := strings.concatenate(
{"<div>Hello second", entity, "</div>"},
{"<div>Hello second ", entity, "</div>"},
context.temp_allocator,
)
response := http.make_response(
@ -55,7 +55,7 @@ third_handler :: proc(request: ^http.Request) -> (http.Response, Error) {
other_entity := request.path_variables["other_entity"]
body := strings.concatenate(
{"<div>Hello third", entity, "and", other_entity, "</div>"},
{"<div>Hello third ", entity, " and ", other_entity, "</div>"},
context.temp_allocator,
)
response := http.make_response(
@ -77,9 +77,10 @@ test_router_ok :: proc(t: ^testing.T) {
address = net.IP4_Address{127, 0, 0, 1},
port = 8080,
}
THREAD_COUNT :: 8
server: Server(Error)
server_init(&server, endpoint, context.allocator)
server_init(&server, endpoint, THREAD_COUNT, context.allocator)
defer server_destroy(&server)
server_add_route(&server, .GET, {"hello", ":entity"}, first_handler)
@ -153,7 +154,7 @@ start_concurrent_server :: proc(
}
// Give server some time to start
time.sleep(100 * time.Millisecond)
time.sleep(50 * time.Millisecond)
return d.thread
}
@ -210,9 +211,10 @@ test_server_general_ok :: proc(t: ^testing.T) {
address = net.IP4_Address{127, 0, 0, 1},
port = 8080,
}
THREAD_COUNT :: 8
server: Server(Error)
server_init(&server, endpoint, context.allocator)
server_init(&server, endpoint, THREAD_COUNT, context.allocator)
defer server_destroy(&server)
server_add_route(&server, .GET, {"hello", ":entity"}, first_handler)
@ -236,15 +238,15 @@ test_server_general_ok :: proc(t: ^testing.T) {
for i in 0 ..< ITERATIONS {
assert_endpoint_response(
"http://127.0.0.1:8080/hello/world",
"<div>Hello firstworld</div>",
"<div>Hello first world</div>",
)
assert_endpoint_response(
"http://127.0.0.1:8080/hello/lonely%20world/only",
"<div>Hello secondlonely%20world</div>",
"<div>Hello second lonely%20world</div>",
)
assert_endpoint_response(
"http://127.0.0.1:8080/hello/world/and/worlds%20friend",
"<div>Hello thirdworldandworlds%20friend</div>",
"<div>Hello third world and worlds%20friend</div>",
)
}