Skip to content

Conversation

@NathanFlurry
Copy link
Member

Changes

Copy link
Member Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add the label merge-queue to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@cloudflare-workers-and-pages
Copy link

Deploying rivet with  Cloudflare Pages  Cloudflare Pages

Latest commit: b4f6e84
Status:🚫  Build failed.

View logs

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

These changes enhance the guard's WebSocket testing by validating echo functionality for text, binary, and ping/pong message types. Additionally, the TestServer utilities now support binding to a specific address via a new helper.

  • Updated /packages/edge/infra/guard/core/tests/websocket.rs to send and validate echo responses on text, binary, and ping messages.
  • Introduced with_handler_and_addr in /packages/edge/infra/guard/core/tests/common/mod.rs for binding TestServer to a specified address.

2 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +302 to +392
// Create a TestServer with a specific server address and custom handler
pub async fn with_handler_and_addr<F, Fut>(addr: SocketAddr, handler: F) -> Self
where
F: Fn(Request<hyper::body::Incoming>, Arc<Mutex<Vec<TestRequest>>>) -> Fut
+ Send
+ 'static
+ Clone,
Fut: Future<Output = Result<Response<Full<Bytes>>, std::convert::Infallible>> + Send,
{
// Create a server bound to the specific address
let listener = TcpListener::bind(addr).await.unwrap();
let request_log = Arc::new(Mutex::new(Vec::new()));
let request_log_clone = request_log.clone();

let (shutdown_tx, shutdown_rx) = oneshot::channel::<()>();

// Start the server with the custom handler
let handle = tokio::spawn(async move {
let mut shutdown_rx = shutdown_rx;

loop {
// Use select to check for shutdown signal
let accept_fut = listener.accept();
let accept_or_shutdown = tokio::select! {
result = accept_fut => Some(result),
_ = &mut shutdown_rx => None,
};

// Break the loop if shutdown was requested
let (stream, _) = match accept_or_shutdown {
Some(Ok(value)) => value,
Some(Err(_)) => break,
None => break,
};

let io = TokioIo::new(stream);
let request_log = request_log_clone.clone();
let handler = handler.clone();

tokio::spawn(async move {
// Create a service function for this connection
let service = service_fn(move |req: Request<hyper::body::Incoming>| {
// Clone these for the async move block
let request_log = request_log.clone();
let handler = handler.clone();

async move {
// Capture request details
let method = req.method().to_string();
let uri = req.uri().to_string();

// Extract headers
let mut headers = HashMap::new();
for (name, value) in req.headers() {
if let Ok(v) = value.to_str() {
headers.insert(name.to_string(), v.to_string());
}
}

// Store request for later inspection
let test_req = TestRequest {
method,
uri,
headers,
body: Vec::new(), // Body will be consumed by handler
};

request_log.lock().unwrap().push(test_req);

// Call the custom handler
handler(req, request_log.clone()).await
}
});

if let Err(err) = hyper::server::conn::http1::Builder::new()
.serve_connection(io, service)
.await
{
eprintln!("Error serving connection: {:?}", err);
}
});
}
});

Self {
addr,
request_log,
shutdown_tx: Some(shutdown_tx),
handle: Some(handle),
}
}
Copy link

Choose a reason for hiding this comment

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

style: Duplicate logic; similar to with_addr. Consider consolidating common parts for reuse.

@cloudflare-workers-and-pages
Copy link

Deploying rivet-studio with  Cloudflare Pages  Cloudflare Pages

Latest commit: b4f6e84
Status: ✅  Deploy successful!
Preview URL: https://d5c609ad.rivet-studio.pages.dev
Branch Preview URL: https://04-07-chore-udpate-guard-web.rivet-studio.pages.dev

View logs

@cloudflare-workers-and-pages
Copy link

Deploying rivet-hub with  Cloudflare Pages  Cloudflare Pages

Latest commit: b4f6e84
Status: ✅  Deploy successful!
Preview URL: https://88b34481.rivet-hub-7jb.pages.dev
Branch Preview URL: https://04-07-chore-udpate-guard-web.rivet-hub-7jb.pages.dev

View logs

@graphite-app
Copy link
Contributor

graphite-app bot commented Apr 7, 2025

Merge activity

  • Apr 7, 6:10 AM EDT: NathanFlurry added this pull request to the Graphite merge queue.
  • Apr 7, 6:11 AM EDT: CI is running for this pull request on a draft pull request (#2322) due to your merge queue CI optimization settings.
  • Apr 7, 6:12 AM EDT: Merged by the Graphite merge queue via draft PR: #2322.

graphite-app bot pushed a commit that referenced this pull request Apr 7, 2025
<!-- Please make sure there is an issue that this PR is correlated to. -->

## Changes

<!-- If there are frontend changes, please include screenshots. -->
@graphite-app graphite-app bot closed this Apr 7, 2025
@graphite-app graphite-app bot deleted the 04-07-chore_udpate_guard_websocket_tests_to_include_message_sending branch April 7, 2025 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants