Skip to content

Commit 684644f

Browse files
cottsayahcorde
andauthored
Restore ZENOH_CONFIG_OVERRIDE after isolation is finished (#855)
Rather than clearing the ZENOH_CONFIG_OVERRIDE environment variable after we stop RMW communication isolation, set it back to whatever it was before isolation was started. Signed-off-by: Scott K Logan <[email protected]> Signed-off-by: Alejandro Hernandez Cordero <[email protected]> Co-authored-by: Alejandro Hernandez Cordero <[email protected]>
1 parent 15915cb commit 684644f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

rmw_zenoh_cpp/src/rmw_test_fixture.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <cstdlib>
1818
#include <iostream>
1919
#include <memory>
20+
#include <optional>
2021
#include <sstream>
2122
#include <string>
2223
#include <utility>
@@ -30,6 +31,8 @@
3031

3132
static std::unique_ptr<zenoh::Session> g_session = nullptr;
3233

34+
static std::optional<std::string> g_restore_config = {};
35+
3336
static
3437
std::optional<std::string>
3538
get_endpoints(zenoh::Session & session)
@@ -128,6 +131,8 @@ rmw_test_isolation_start()
128131
return RMW_RET_ERROR;
129132
}
130133

134+
g_restore_config = rcpputils::get_env_var("ZENOH_CONFIG_OVERRIDE");
135+
131136
std::string config_override = "connect/endpoints=" + endpoints.value();
132137
if (!rcpputils::set_env_var(
133138
"ZENOH_CONFIG_OVERRIDE",
@@ -145,7 +150,9 @@ rmw_test_isolation_start()
145150
rmw_ret_t
146151
rmw_test_isolation_stop()
147152
{
148-
rcpputils::set_env_var("ZENOH_CONFIG_OVERRIDE", nullptr);
153+
if(g_restore_config) {
154+
rcpputils::set_env_var("ZENOH_CONFIG_OVERRIDE", g_restore_config->c_str());
155+
}
149156

150157
if(g_session) {
151158
g_session->close();

0 commit comments

Comments
 (0)