Skip to content

Commit 9244ab7

Browse files
committed
Refactor testing part 2
1 parent cc04cd0 commit 9244ab7

File tree

6 files changed

+99
-547
lines changed

6 files changed

+99
-547
lines changed

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use std::ffi::{c_char, c_void};
33
use ngx::core;
44
use ngx::ffi::{
55
ngx_array_push, ngx_command_t, ngx_conf_t, ngx_http_add_variable, ngx_http_handler_pt,
6-
ngx_http_module_t, ngx_http_phases_NGX_HTTP_PREACCESS_PHASE, ngx_int_t, ngx_module_t,
7-
ngx_str_t, ngx_uint_t, NGX_CONF_TAKE1, NGX_HTTP_LOC_CONF, NGX_HTTP_LOC_CONF_OFFSET,
8-
NGX_HTTP_MAIN_CONF, NGX_HTTP_MODULE, NGX_HTTP_SRV_CONF, NGX_LOG_EMERG,
6+
ngx_http_module_t, ngx_http_phases_NGX_HTTP_ACCESS_PHASE, ngx_int_t, ngx_module_t, ngx_str_t,
7+
ngx_uint_t, NGX_CONF_TAKE1, NGX_HTTP_LOC_CONF, NGX_HTTP_LOC_CONF_OFFSET, NGX_HTTP_MAIN_CONF,
8+
NGX_HTTP_MODULE, NGX_HTTP_SRV_CONF, NGX_LOG_EMERG,
99
};
1010
use ngx::http::{self, HttpModule};
1111
use ngx::http::{HttpModuleLocationConf, HttpModuleMainConf, NgxHttpCoreModule};

src/modules/bbr.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ use std::ffi::{c_char, c_void};
77

88
// Helper macro for info-level logging in BBR
99
macro_rules! ngx_log_info_http {
10-
($request:expr, $($arg:tt)*) => {
10+
($request:expr, $($arg:tt)*) => {{
11+
#[allow(unused_unsafe)]
1112
unsafe {
1213
let msg = format!($($arg)*);
1314
let c_msg = std::ffi::CString::new(msg).unwrap();
@@ -18,7 +19,7 @@ macro_rules! ngx_log_info_http {
1819
c_msg.as_ptr(),
1920
);
2021
}
21-
};
22+
}};
2223
}
2324

2425
// Platform-conditional string pointer casting for nginx FFI
@@ -280,21 +281,23 @@ pub unsafe extern "C" fn bbr_body_read_handler(r: *mut ngx::ffi::ngx_http_reques
280281

281282
// Body processing complete - resume phases from where we left off
282283
// We must call ngx_http_core_run_phases to continue through content/proxy phase
283-
if (*r).write_event_handler == Some(ngx::ffi::ngx_http_core_run_phases) {
284-
let request: &mut http::Request = ngx::http::Request::from_ngx_http_request(r);
285-
ngx_log_debug_http!(
286-
request,
287-
"ngx-inference: BBR callback complete, resuming phases (async mode)"
288-
);
284+
unsafe {
285+
if (*r).write_event_handler == Some(ngx::ffi::ngx_http_core_run_phases) {
286+
let request: &mut http::Request = ngx::http::Request::from_ngx_http_request(r);
287+
ngx_log_debug_http!(
288+
request,
289+
"ngx-inference: BBR callback complete, resuming phases (async mode)"
290+
);
289291

290-
// Resume phases - this will continue through content phase (proxy) and eventually log phase
291-
ngx::ffi::ngx_http_core_run_phases(r);
292-
} else {
293-
let request: &mut http::Request = ngx::http::Request::from_ngx_http_request(r);
294-
ngx_log_info_http!(
295-
request,
296-
"ngx-inference: BBR callback complete (sync mode, no resume needed)"
297-
);
292+
// Resume phases - this will continue through content phase (proxy) and eventually log phase
293+
ngx::ffi::ngx_http_core_run_phases(r);
294+
} else {
295+
let request: &mut http::Request = ngx::http::Request::from_ngx_http_request(r);
296+
ngx_log_info_http!(
297+
request,
298+
"ngx-inference: BBR callback complete (sync mode, no resume needed)"
299+
);
300+
}
298301
}
299302
}
300303

tests/kind-ngf/cluster/kind-config.yaml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,8 @@ apiVersion: kind.x-k8s.io/v1alpha4
55
name: ngx-inference-test
66
nodes:
77
- role: control-plane
8-
kubeadmConfigPatches:
9-
- |
10-
kind: InitConfiguration
11-
nodeRegistration:
12-
taints: []
138
extraPortMappings:
149
# Map host port 30080 to NodePort 30080 for direct NodePort access
1510
- containerPort: 30080
1611
hostPort: 30080
1712
protocol: TCP
18-
- role: control-plane
19-
kubeadmConfigPatches:
20-
- |
21-
kind: JoinConfiguration
22-
nodeRegistration:
23-
taints: []
24-
- role: control-plane
25-
kubeadmConfigPatches:
26-
- |
27-
kind: JoinConfiguration
28-
nodeRegistration:
29-
taints: []

tests/kind-ngf/scripts/test-kind.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,6 @@ run_test_for_scenario() {
205205
# Note: BBR functionality is validated through the /v1/chat/completions endpoint tests below
206206
# The BBR module extracts model names from request bodies regardless of the specific endpoint
207207

208-
# Show logs before test
209-
display_logs
210-
211208
# Test EPP if enabled, or test expected failure if disabled
212209
if [ "$expected_epp" = "enabled" ]; then
213210
echo " Testing EPP endpoint (/v1/chat/completions)..."

tests/setup-local-dev.sh

Lines changed: 77 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -88,40 +88,36 @@ is_rhel_family() {
8888

8989
detect_os
9090

91-
# Common tools check
92-
echo -e "${YELLOW}Checking common tools...${NC}"
9391
tools_missing=0
9492

95-
# Check curl
96-
if command -v curl >/dev/null 2>&1; then
97-
echo -e "${GREEN} curl found: $(curl --version | head -n1)${NC}"
98-
else
99-
echo -e "${RED} curl not found - please install curl${NC}"
100-
if [[ "$OS" == "macos" ]]; then
101-
echo " brew install curl"
102-
elif [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
103-
echo " sudo apt-get install curl"
104-
fi
105-
tools_missing=1
106-
fi
93+
if [[ "$ENVIRONMENT" == "local" ]]; then
94+
echo -e "${YELLOW}Checking local development requirements...${NC}"
10795

108-
# Check jq
109-
if command -v jq >/dev/null 2>&1; then
110-
echo -e "${GREEN} jq found: $(jq --version)${NC}"
111-
else
112-
echo -e "${RED} jq not found - please install jq for JSON parsing${NC}"
113-
if [[ "$OS" == "macos" ]]; then
114-
echo " brew install jq"
115-
elif [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
116-
echo " sudo apt-get install jq"
96+
# Check curl
97+
if command -v curl >/dev/null 2>&1; then
98+
echo -e "${GREEN} curl found${NC}"
99+
else
100+
echo -e "${RED} curl not found - please install curl${NC}"
101+
if [[ "$OS" == "macos" ]]; then
102+
echo " brew install curl"
103+
elif [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
104+
echo " sudo apt-get install curl"
105+
fi
106+
tools_missing=1
117107
fi
118-
tools_missing=1
119-
fi
120-
121-
echo ""
122108

123-
if [[ "$ENVIRONMENT" == "local" ]]; then
124-
echo -e "${YELLOW}Checking local development requirements...${NC}"
109+
# Check jq
110+
if command -v jq >/dev/null 2>&1; then
111+
echo -e "${GREEN} jq found${NC}"
112+
else
113+
echo -e "${RED} jq not found - please install jq for JSON parsing${NC}"
114+
if [[ "$OS" == "macos" ]]; then
115+
echo " brew install jq"
116+
elif [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
117+
echo " sudo apt-get install jq"
118+
fi
119+
tools_missing=1
120+
fi
125121

126122
# Check nginx
127123
if command -v nginx >/dev/null 2>&1; then
@@ -309,6 +305,32 @@ if [[ "$ENVIRONMENT" == "local" ]]; then
309305
elif [[ "$ENVIRONMENT" == "docker" ]]; then
310306
echo -e "${YELLOW}Checking Docker development requirements...${NC}"
311307

308+
# Check curl
309+
if command -v curl >/dev/null 2>&1; then
310+
echo -e "${GREEN} curl found${NC}"
311+
else
312+
echo -e "${RED} curl not found - please install curl${NC}"
313+
if [[ "$OS" == "macos" ]]; then
314+
echo " brew install curl"
315+
elif [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
316+
echo " sudo apt-get install curl"
317+
fi
318+
tools_missing=1
319+
fi
320+
321+
# Check jq
322+
if command -v jq >/dev/null 2>&1; then
323+
echo -e "${GREEN} jq found${NC}"
324+
else
325+
echo -e "${RED} jq not found - please install jq for JSON parsing${NC}"
326+
if [[ "$OS" == "macos" ]]; then
327+
echo " brew install jq"
328+
elif [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
329+
echo " sudo apt-get install jq"
330+
fi
331+
tools_missing=1
332+
fi
333+
312334
# Check docker
313335
if command -v docker >/dev/null 2>&1; then
314336
echo -e "${GREEN} docker found: $(docker --version)${NC}"
@@ -336,6 +358,32 @@ elif [[ "$ENVIRONMENT" == "docker" ]]; then
336358
elif [[ "$ENVIRONMENT" == "kind" ]]; then
337359
echo -e "${YELLOW}Checking KIND development requirements...${NC}"
338360

361+
# Check curl
362+
if command -v curl >/dev/null 2>&1; then
363+
echo -e "${GREEN} curl found${NC}"
364+
else
365+
echo -e "${RED} curl not found - please install curl${NC}"
366+
if [[ "$OS" == "macos" ]]; then
367+
echo " brew install curl"
368+
elif [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
369+
echo " sudo apt-get install curl"
370+
fi
371+
tools_missing=1
372+
fi
373+
374+
# Check jq
375+
if command -v jq >/dev/null 2>&1; then
376+
echo -e "${GREEN} jq found${NC}"
377+
else
378+
echo -e "${RED} jq not found - please install jq for JSON parsing${NC}"
379+
if [[ "$OS" == "macos" ]]; then
380+
echo " brew install jq"
381+
elif [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
382+
echo " sudo apt-get install jq"
383+
fi
384+
tools_missing=1
385+
fi
386+
339387
# Check kind
340388
if command -v kind >/dev/null 2>&1; then
341389
echo -e "${GREEN} kind found${NC}"

0 commit comments

Comments
 (0)