-
Notifications
You must be signed in to change notification settings - Fork 76
test: Link unit tests with nginx library. #204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Some unit tests may use C functions from nginx. To support this scenario, special static library is built. Necessary linker flags are also added. Since these changes are needed for specific unit tests only, new feature "unittest" is defined.
ecb0d92
to
05a67cb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for linking unit tests with nginx library by introducing a new "unittest" feature flag and building a static nginx library. The changes enable unit tests to use C functions from nginx by creating a special static library (libnginx) and adding necessary linker flags when the unittest feature is enabled.
- Introduces a new "unittest" feature flag for nginx-sys and nginx-src crates
- Creates a libnginx module with helper functions for nginx initialization in tests
- Adds build configuration to generate static nginx library and parse linker flags
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.
Show a summary per file
File | Description |
---|---|
src/core/pool.rs | Adds comprehensive unit tests for Pool functionality using nginx C functions |
nginx-sys/build/main.rs | Extends makefile parsing to extract library flags and adds unittest feature support |
nginx-sys/Cargo.toml | Defines unittest feature dependency on vendored nginx-src |
nginx-src/src/lib.rs | Configures nginx build to include libnginx module when unittest feature is enabled |
nginx-src/libnginx/ | New module providing C wrapper functions for nginx initialization in tests |
Cargo.toml | Adds nginx-sys with unittest feature as dev dependency |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
#[test] | ||
fn test_pool_resize() { | ||
unsafe { | ||
libngx_init("prefix".as_ptr() as *mut nginx_sys::u_char); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hardcoded string "prefix" lacks explanation. Consider using a constant or adding a comment explaining why this specific prefix is used for test initialization.
libngx_init("prefix".as_ptr() as *mut nginx_sys::u_char); | |
libngx_init(TEST_NGINX_PREFIX.as_ptr() as *mut nginx_sys::u_char); |
Copilot uses AI. Check for mistakes.
ngx_cycle_t * | ||
libngx_init(u_char *prefix) | ||
{ | ||
static ngx_cycle_t *cycle = NGX_CONF_UNSET_PTR, init_cycle; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The static variable 'cycle' is not thread-safe. Multiple threads calling libngx_init() concurrently could cause race conditions during initialization.
Copilot uses AI. Check for mistakes.
if (ngx_create_dir(path->name.data, ngx_dir_access(tf.access)) | ||
== NGX_FILE_ERROR) | ||
{ | ||
return ngx_errno; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error check for ngx_create_dir is incomplete. When the function returns NGX_FILE_ERROR, returning ngx_errno directly may not be appropriate as it's not guaranteed to be a valid ngx_int_t return code.
if (ngx_create_dir(path->name.data, ngx_dir_access(tf.access)) | |
== NGX_FILE_ERROR) | |
{ | |
return ngx_errno; | |
ngx_log_error(NGX_LOG_ERR, cycle->log, ngx_errno, | |
"failed to create directory \"%s\"", path->name.data); | |
return NGX_ERROR; |
Copilot uses AI. Check for mistakes.
while let Some(word) = words.next() { | ||
if let Some(lib_dir) = word.strip_prefix("-L") { | ||
let value = if lib_dir.is_empty() { | ||
words.next().expect("-L argument") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The panic message "-L argument" is unclear. Consider a more descriptive message like "Missing argument for -L flag" to help with debugging.
words.next().expect("-L argument") | |
words.next().expect("Missing argument for -L flag") |
Copilot uses AI. Check for mistakes.
libs.push(LibOption::LibPath(value)); | ||
} else if let Some(lib) = word.strip_prefix("-l") { | ||
let value = if lib.is_empty() { | ||
words.next().expect("-l argument") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The panic message "-l argument" is unclear. Consider a more descriptive message like "Missing argument for -l flag" to help with debugging.
words.next().expect("-l argument") | |
words.next().expect("Missing argument for -l flag") |
Copilot uses AI. Check for mistakes.
Proposed changes
Some unit tests may use C functions from nginx. To support this scenario, special static library is built. Necessary linker flags are also added. Since these changes are needed for specific unit tests only, new feature "unittest" is defined in
nginx-sys
andnginx-src
crates.Checklist
Before creating a PR, run through this checklist and mark each as complete.