Skip to content

fix: use dynamic ports in tests to avoid port conflicts#21

Merged
LuigimonSoft merged 2 commits intomasterfrom
codex/add-static-file-server-support-h89jsl
Aug 18, 2025
Merged

fix: use dynamic ports in tests to avoid port conflicts#21
LuigimonSoft merged 2 commits intomasterfrom
codex/add-static-file-server-support-h89jsl

Conversation

@LuigimonSoft
Copy link
Owner

Summary

  • bind server to an ephemeral port and expose the actual address
  • spawn servers on port 0 in integration tests and build URLs from the returned base
  • drop swagger-ui archive from source control and ignore it going forward
  • document that Swagger UI assets are downloaded during build and may be overridden via SWAGGER_UI_DOWNLOAD_URL

Testing

  • cargo test

https://chatgpt.com/codex/tasks/task_e_68a15462425883209ee6af91b9702e42

Copilot AI review requested due to automatic review settings August 18, 2025 04:16
Copy link

Copilot AI left a 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 fixes port conflicts in tests by implementing dynamic port allocation. The server now binds to an ephemeral port (port 0) and returns the actual assigned address, allowing tests to run concurrently without port conflicts.

Key changes:

  • Modified server to bind to port 0 and return the actual assigned address
  • Refactored integration tests to use dynamic ports instead of a shared server instance
  • Added static file serving capability with corresponding tests

Reviewed Changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/server.rs Updated to bind on ephemeral port and return actual address
src/test/integration_test.rs Refactored to spawn individual servers per test with dynamic ports
src/test/static_files_test.rs Added new test file for static file serving functionality
src/config.rs Added static_dir configuration field
src/controllers/mod.rs Updated error handling to use Rejection instead of Infallible
src/router.rs Moved error recovery to server level
public/index.html Added test HTML file for static file serving
README.md Updated documentation about Swagger UI asset downloads

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

.clone()
.and(warp::path("api-doc.json"))
.and(warp::get())
.and_then(|| async { Ok::<_, Rejection>(warp::reply::json(&swagger::ApiDoc::openapi())) });
Copy link

Copilot AI Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The closure is unnecessarily complex. Since warp::reply::json() already returns a valid reply, you can simplify this to .map(|| warp::reply::json(&swagger::ApiDoc::openapi()))

Suggested change
.and_then(|| async { Ok::<_, Rejection>(warp::reply::json(&swagger::ApiDoc::openapi())) });
.map(|| warp::reply::json(&swagger::ApiDoc::openapi()));

Copilot uses AI. Check for mistakes.

async fn spawn_server() -> (oneshot::Sender<()>, String) {
std::env::set_var("PORT", "0");
let (shutdown, base) = run_server().await;
Copy link

Copilot AI Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting environment variables in tests can cause race conditions when tests run in parallel. Consider passing port 0 directly to the server configuration instead of relying on environment variables.

Suggested change
let (shutdown, base) = run_server().await;
// Pass port 0 directly to run_server to avoid race conditions.
let (shutdown, base) = run_server(0).await;

Copilot uses AI. Check for mistakes.
@LuigimonSoft LuigimonSoft merged commit 01a80e1 into master Aug 18, 2025
1 check passed
@LuigimonSoft LuigimonSoft deleted the codex/add-static-file-server-support-h89jsl branch August 19, 2025 01:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants