Skip to content

Commit d108d4d

Browse files
committed
Add z_open peer establishment tests
1 parent b75b1d3 commit d108d4d

5 files changed

Lines changed: 733 additions & 3 deletions

File tree

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,7 @@ if(UNIX OR MSVC)
656656
add_executable(z_sync_group_test ${PROJECT_SOURCE_DIR}/tests/z_sync_group_test.c)
657657
add_executable(z_cancellation_token_test ${PROJECT_SOURCE_DIR}/tests/z_cancellation_token_test.c)
658658
add_executable(z_local_loopback_test ${PROJECT_SOURCE_DIR}/tests/z_local_loopback_test.c)
659+
add_executable(z_open_test ${PROJECT_SOURCE_DIR}/tests/z_open_test.c)
659660
add_executable(z_json_encoder_test ${PROJECT_SOURCE_DIR}/tests/z_json_encoder_test.c)
660661
add_executable(z_executor_test ${PROJECT_SOURCE_DIR}/tests/z_executor_test.c)
661662
add_executable(z_background_executor_test ${PROJECT_SOURCE_DIR}/tests/z_background_executor_test.c)
@@ -690,6 +691,10 @@ if(UNIX OR MSVC)
690691
target_link_libraries(z_sync_group_test zenohpico::lib)
691692
target_link_libraries(z_cancellation_token_test zenohpico::lib)
692693
target_link_libraries(z_local_loopback_test zenohpico::lib)
694+
target_link_libraries(z_open_test zenohpico::lib)
695+
if(CHECK_THREADS)
696+
target_link_libraries(z_open_test Threads::Threads)
697+
endif()
693698
target_include_directories(z_local_loopback_test PRIVATE ${PROJECT_SOURCE_DIR}/include)
694699
target_compile_definitions(z_local_loopback_test PRIVATE Z_TEST_HOOKS=1)
695700
if(PICO_SHARED)
@@ -740,6 +745,7 @@ if(UNIX OR MSVC)
740745
add_test(z_sync_group_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/z_sync_group_test)
741746
add_test(z_cancellation_token_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/z_cancellation_token_test)
742747
add_test(z_local_loopback_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/z_local_loopback_test)
748+
add_test(z_open_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/z_open_test)
743749
add_test(z_json_encoder_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/z_json_encoder_test)
744750
add_test(z_executor_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/z_executor_test)
745751
add_test(z_background_executor_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/z_background_executor_test)

include/zenoh-pico.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
#ifndef ZENOH_PICO_H
1818
#define ZENOH_PICO_H
1919

20-
#define ZENOH_PICO "1.5.0"
20+
#define ZENOH_PICO "1.8.0"
2121
#define ZENOH_PICO_MAJOR 1
22-
#define ZENOH_PICO_MINOR 5
22+
#define ZENOH_PICO_MINOR 8
2323
#define ZENOH_PICO_PATCH 0
2424
#define ZENOH_PICO_TWEAK
2525

26+
#include "zenoh-pico/api/admin_space.h"
2627
#include "zenoh-pico/api/advanced_publisher.h"
2728
#include "zenoh-pico/api/advanced_subscriber.h"
2829
#include "zenoh-pico/api/constants.h"

include/zenoh-pico/config.h

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
#define Z_FEATURE_UNICAST_PEER 1
6868
#define Z_FEATURE_AUTO_RECONNECT 1
6969
#define Z_FEATURE_MULTICAST_DECLARATIONS 0
70-
#define Z_FEATURE_PERIODIC_TASKS 0
7170
#define Z_FEATURE_ADMIN_SPACE 0
7271

7372
// End of CMake generation
@@ -175,6 +174,82 @@
175174
#define Z_CONFIG_TLS_CONNECT_CERTIFICATE_BASE64_KEY 0x55
176175
#define Z_CONFIG_TLS_VERIFY_NAME_ON_CONNECT_KEY 0x56
177176

177+
/*------------------ Connect behaviour properties ------------------*/
178+
179+
/**
180+
* The timeout dedicated to establishing connections to configured
181+
* connect locators.
182+
*
183+
* Accepted values : `<int in milliseconds>`.
184+
* - `0` : no retry, try each locator once
185+
* - `>0` : retry retryable locators until timeout expires
186+
* - `-1` : retry indefinitely until a connection is established
187+
*
188+
* In client mode, this applies to the initial connection attempt and
189+
* requires at least one locator to succeed.
190+
*
191+
* In peer mode, this applies to the initial connection phase for
192+
* configured locators.
193+
*
194+
* Default value : `"0"` in client mode, `"-1"` in peer mode.
195+
*/
196+
#define Z_CONFIG_CONNECT_TIMEOUT_KEY 0x57
197+
#define Z_CONFIG_CONNECT_TIMEOUT_CLIENT_DEFAULT "0"
198+
#define Z_CONFIG_CONNECT_TIMEOUT_PEER_DEFAULT "-1"
199+
200+
/**
201+
* Indicates whether the application should fail if connection attempts
202+
* to configured connect locators do not succeed.
203+
*
204+
* Accepted values : `false`, `true`.
205+
* - `true` : fail if the connection phase does not establish the required connectivity
206+
* - `false` : allow the session to continue even if some connections fail
207+
*
208+
* In client mode, this requires at least one locator to be successfully connected.
209+
*
210+
* In peer mode, this applies to the initial connection phase for
211+
* configured locators.
212+
*
213+
* Default value : `"true"` in client mode, `"false"` in peer mode.
214+
*/
215+
#define Z_CONFIG_CONNECT_EXIT_ON_FAILURE_KEY 0x58
216+
#define Z_CONFIG_CONNECT_EXIT_ON_FAILURE_CLIENT_DEFAULT "true"
217+
#define Z_CONFIG_CONNECT_EXIT_ON_FAILURE_PEER_DEFAULT "false"
218+
219+
/*------------------ Listen behaviour properties ------------------*/
220+
221+
/**
222+
* The timeout dedicated to opening configured listen locators.
223+
*
224+
* Accepted values : `<int in milliseconds>`.
225+
* - `0` : no retry, try each locator once
226+
* - `>0` : retry retryable locators until timeout expires
227+
* - `-1` : retry indefinitely until a listener is established
228+
*
229+
* In peer mode, this applies to the initial listen phase for
230+
* configured locators.
231+
*
232+
* Default value : `"0"`.
233+
*/
234+
#define Z_CONFIG_LISTEN_TIMEOUT_KEY 0x59
235+
#define Z_CONFIG_LISTEN_TIMEOUT_DEFAULT "0"
236+
237+
/**
238+
* Indicates whether the application should fail if configured listen
239+
* locators cannot be opened.
240+
*
241+
* Accepted values : `false`, `true`.
242+
* - `true` : fail if the listen phase does not establish the required listeners
243+
* - `false` : allow the session to continue even if listen attempts fail
244+
*
245+
* In peer mode, this applies to the initial listen phase for
246+
* configured locators.
247+
*
248+
* Default value : `"true"`.
249+
*/
250+
#define Z_CONFIG_LISTEN_EXIT_ON_FAILURE_KEY 0x5A
251+
#define Z_CONFIG_LISTEN_EXIT_ON_FAILURE_DEFAULT "true"
252+
178253
/*------------------ Compile-time configuration properties ------------------*/
179254
/**
180255
* Default length for Zenoh ID. Maximum size is 16 bytes.

src/net/session.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,11 @@ z_result_t _z_open_locators_peer(_z_session_rc_t *zn, _z_string_t *listen_locato
394394
return _Z_RES_OK;
395395
}
396396

397+
static inline z_result_t _z_validate_open_timeout(int32_t timeout_ms) {
398+
_Z_ERROR("Invalid timeout value: %d", timeout_ms);
399+
return (timeout_ms >= -1) ? _Z_RES_OK : _Z_ERR_CONFIG_INVALID_VALUE;
400+
}
401+
397402
z_result_t _z_open_locators(_z_session_rc_t *zn, const _z_string_svec_t *listen_locators,
398403
const _z_string_svec_t *connect_locators, const _z_id_t *zid, _z_config_t *config,
399404
z_whatami_t mode) {
@@ -418,6 +423,7 @@ z_result_t _z_open_locators(_z_session_rc_t *zn, const _z_string_svec_t *listen_
418423
int32_t listen_timeout_ms;
419424
_Z_RETURN_IF_ERR(_z_config_get_i32_default(config, Z_CONFIG_LISTEN_TIMEOUT_KEY, Z_CONFIG_LISTEN_TIMEOUT_DEFAULT,
420425
&listen_timeout_ms));
426+
_Z_RETURN_IF_ERR(_z_validate_open_timeout(listen_timeout_ms));
421427

422428
bool listen_exit_on_failure;
423429
_Z_RETURN_IF_ERR(_z_config_get_bool_default(config, Z_CONFIG_LISTEN_EXIT_ON_FAILURE_KEY,
@@ -428,6 +434,7 @@ z_result_t _z_open_locators(_z_session_rc_t *zn, const _z_string_svec_t *listen_
428434
int32_t connect_timeout_ms;
429435
_Z_RETURN_IF_ERR(
430436
_z_config_get_i32_default(config, Z_CONFIG_CONNECT_TIMEOUT_KEY, connect_timeout_default, &connect_timeout_ms));
437+
_Z_RETURN_IF_ERR(_z_validate_open_timeout(connect_timeout_ms));
431438

432439
const char *connect_exit_default = (mode == Z_WHATAMI_CLIENT) ? Z_CONFIG_CONNECT_EXIT_ON_FAILURE_CLIENT_DEFAULT
433440
: Z_CONFIG_CONNECT_EXIT_ON_FAILURE_PEER_DEFAULT;

0 commit comments

Comments
 (0)