From 0e863e265c07c6bc8691930c240f19a92d863f36 Mon Sep 17 00:00:00 2001 From: Oussama Teffahi Date: Thu, 5 Dec 2024 12:46:51 +0100 Subject: [PATCH] Add TCP buffer sizes config tests --- zenoh/tests/tcp_buffers.rs | 89 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 zenoh/tests/tcp_buffers.rs diff --git a/zenoh/tests/tcp_buffers.rs b/zenoh/tests/tcp_buffers.rs new file mode 100644 index 000000000..22c7e40f0 --- /dev/null +++ b/zenoh/tests/tcp_buffers.rs @@ -0,0 +1,89 @@ +// +// Copyright (c) 2024 ZettaScale Technology +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// +// Contributors: +// ZettaScale Zenoh Team, +// + +use zenoh::{Config, Wait}; + +#[test] +fn buffer_size_config() { + let mut config = Config::default(); + config + .insert_json5( + "transport/link", + r#" + { + tcp_tx_buffer: 65000, + tcp_rx_buffer: 65000, + } + "#, + ) + .unwrap(); + + config + .insert_json5("listen/endpoints", r#"["tcp/[::]:0"]"#) + .unwrap(); + + zenoh::open(config).wait().unwrap(); +} + +#[test] +fn buffer_size_endpoint() { + let mut config = Config::default(); + config + .insert_json5( + "listen/endpoints", + r#"["tcp/[::]:0#tcp_tx_buffer=65000;tcp_rx_buffer=65000"]"#, + ) + .unwrap(); + + zenoh::open(config).wait().unwrap(); +} + +#[test] +#[should_panic(expected = "Can not create a new TCP listener")] +fn buffer_size_config_override() { + let mut config = Config::default(); + config + .insert_json5( + "transport/link", + r#" + { + tcp_tx_buffer: 0, + tcp_rx_buffer: 0, + } + "#, + ) + .unwrap(); + + config + .insert_json5( + "listen/endpoints", + r#"["tcp/[::]:0#tcp_tx_buffer=65000;tcp_rx_buffer=65000"]"#, + ) + .unwrap(); + + zenoh::open(config).wait().unwrap(); +} + +#[test] +#[should_panic(expected = "Can not create a new TCP listener")] +fn listen_zero_buffers() { + let mut config = Config::default(); + config + .insert_json5( + "listen/endpoints", + r#"["tcp/[::]:0#tcp_tx_buffer=0;tcp_rx_buffer=0"]"#, + ) + .unwrap(); + zenoh::open(config).wait().unwrap(); +}