Skip to content

Commit 024df91

Browse files
committed
Add Env prefix befor Config in envconfig c-bridge structs. Run envconfig test using system env vars in separate process
1 parent b550109 commit 024df91

3 files changed

Lines changed: 64 additions & 54 deletions

File tree

core-api/src/envconfig.rs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,15 +1592,31 @@ address = "some-address"
15921592

15931593
#[test]
15941594
fn test_load_client_config_profile_from_system_env() {
1595-
// WARNING: This test modifies system environment variables which can cause
1596-
// test pollution if tests run in parallel.
1595+
let cargo = std::env::var("CARGO").unwrap_or_else(|_| "cargo".to_string());
1596+
let output = std::process::Command::new(cargo)
1597+
.arg("test")
1598+
.arg("-F")
1599+
.arg("envconfig")
1600+
.arg("envconfig::tests::test_load_client_config_profile_from_system_env_impl")
1601+
.arg("--")
1602+
.arg("--exact")
1603+
.arg("--ignored")
1604+
.env("TEMPORAL_ADDRESS", "system-address")
1605+
.env("TEMPORAL_NAMESPACE", "system-namespace")
1606+
.output()
1607+
.expect("Failed to execute subprocess test");
15971608

1598-
// Set up system env vars. These tests can't be run in parallel.
1599-
unsafe {
1600-
std::env::set_var("TEMPORAL_ADDRESS", "system-address");
1601-
std::env::set_var("TEMPORAL_NAMESPACE", "system-namespace");
1602-
}
1609+
assert!(
1610+
output.status.success(),
1611+
"Subprocess test failed:\nstdout: {}\nstderr: {}",
1612+
String::from_utf8_lossy(&output.stdout),
1613+
String::from_utf8_lossy(&output.stderr),
1614+
);
1615+
}
16031616

1617+
#[test]
1618+
#[ignore] // Only run when explicitly called
1619+
fn test_load_client_config_profile_from_system_env_impl() {
16041620
let options = LoadClientConfigProfileOptions {
16051621
disable_file: true, // Don't load from any files
16061622
..Default::default()
@@ -1610,12 +1626,6 @@ address = "some-address"
16101626
let profile = load_client_config_profile(options, None).unwrap();
16111627
assert_eq!(profile.address.as_ref().unwrap(), "system-address");
16121628
assert_eq!(profile.namespace.as_ref().unwrap(), "system-namespace");
1613-
1614-
// Clean up
1615-
unsafe {
1616-
std::env::remove_var("TEMPORAL_ADDRESS");
1617-
std::env::remove_var("TEMPORAL_NAMESPACE");
1618-
}
16191629
}
16201630

16211631
#[test]

core-c-bridge/include/temporal-sdk-core-c-bridge.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -247,20 +247,20 @@ typedef void (*TemporalCoreClientRpcCallCallback)(void *user_data,
247247
* If fail is not null, it contains UTF-8 encoded error message.
248248
* The returned ByteArrays must be freed by the caller.
249249
*/
250-
typedef struct TemporalCoreClientConfigOrFail {
250+
typedef struct TemporalCoreClientEnvConfigOrFail {
251251
const struct TemporalCoreByteArray *success;
252252
const struct TemporalCoreByteArray *fail;
253-
} TemporalCoreClientConfigOrFail;
253+
} TemporalCoreClientEnvConfigOrFail;
254254

255255
/**
256256
* Options for loading client configuration.
257257
*/
258-
typedef struct TemporalCoreClientConfigLoadOptions {
258+
typedef struct TemporalCoreClientEnvConfigLoadOptions {
259259
struct TemporalCoreByteArrayRef path;
260260
struct TemporalCoreByteArrayRef data;
261261
bool config_file_strict;
262262
struct TemporalCoreByteArrayRef env_vars;
263-
} TemporalCoreClientConfigLoadOptions;
263+
} TemporalCoreClientEnvConfigLoadOptions;
264264

265265
/**
266266
* OrFail result for client config profile loading operations.
@@ -269,23 +269,23 @@ typedef struct TemporalCoreClientConfigLoadOptions {
269269
* If fail is not null, it contains UTF-8 encoded error message.
270270
* The returned ByteArrays must be freed by the caller.
271271
*/
272-
typedef struct TemporalCoreClientConfigProfileOrFail {
272+
typedef struct TemporalCoreClientEnvConfigProfileOrFail {
273273
const struct TemporalCoreByteArray *success;
274274
const struct TemporalCoreByteArray *fail;
275-
} TemporalCoreClientConfigProfileOrFail;
275+
} TemporalCoreClientEnvConfigProfileOrFail;
276276

277277
/**
278278
* Options for loading a specific client configuration profile.
279279
*/
280-
typedef struct TemporalCoreClientConfigProfileLoadOptions {
280+
typedef struct TemporalCoreClientEnvConfigProfileLoadOptions {
281281
struct TemporalCoreByteArrayRef profile;
282282
struct TemporalCoreByteArrayRef path;
283283
struct TemporalCoreByteArrayRef data;
284284
bool disable_file;
285285
bool disable_env;
286286
bool config_file_strict;
287287
struct TemporalCoreByteArrayRef env_vars;
288-
} TemporalCoreClientConfigProfileLoadOptions;
288+
} TemporalCoreClientEnvConfigProfileLoadOptions;
289289

290290
typedef union TemporalCoreMetricAttributeValue {
291291
struct TemporalCoreByteArrayRef string_value;
@@ -823,14 +823,14 @@ void temporal_core_client_rpc_call(struct TemporalCoreClient *client,
823823
* Returns ClientConfigOrFail with either success JSON or error message.
824824
* The returned ByteArrays must be freed by the caller.
825825
*/
826-
struct TemporalCoreClientConfigOrFail temporal_core_client_config_load(const struct TemporalCoreClientConfigLoadOptions *options);
826+
struct TemporalCoreClientEnvConfigOrFail temporal_core_client_env_config_load(const struct TemporalCoreClientEnvConfigLoadOptions *options);
827827

828828
/**
829829
* Load a single client profile from given sources with env overrides.
830830
* Returns ClientConfigProfileOrFail with either success JSON or error message.
831831
* The returned ByteArrays must be freed by the caller.
832832
*/
833-
struct TemporalCoreClientConfigProfileOrFail temporal_core_client_config_profile_load(const struct TemporalCoreClientConfigProfileLoadOptions *options);
833+
struct TemporalCoreClientEnvConfigProfileOrFail temporal_core_client_env_config_profile_load(const struct TemporalCoreClientEnvConfigProfileLoadOptions *options);
834834

835835
struct TemporalCoreMetricMeter *temporal_core_metric_meter_new(struct TemporalCoreRuntime *runtime);
836836

core-c-bridge/src/envconfig.rs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use temporal_sdk_core_api::envconfig::{
1313
/// If fail is not null, it contains UTF-8 encoded error message.
1414
/// The returned ByteArrays must be freed by the caller.
1515
#[repr(C)]
16-
pub struct ClientConfigOrFail {
16+
pub struct ClientEnvConfigOrFail {
1717
pub success: *const ByteArray,
1818
pub fail: *const ByteArray,
1919
}
@@ -24,14 +24,14 @@ pub struct ClientConfigOrFail {
2424
/// If fail is not null, it contains UTF-8 encoded error message.
2525
/// The returned ByteArrays must be freed by the caller.
2626
#[repr(C)]
27-
pub struct ClientConfigProfileOrFail {
27+
pub struct ClientEnvConfigProfileOrFail {
2828
pub success: *const ByteArray,
2929
pub fail: *const ByteArray,
3030
}
3131

3232
/// Options for loading client configuration.
3333
#[repr(C)]
34-
pub struct ClientConfigLoadOptions {
34+
pub struct ClientEnvConfigLoadOptions {
3535
pub path: ByteArrayRef,
3636
pub data: ByteArrayRef,
3737
pub config_file_strict: bool,
@@ -40,7 +40,7 @@ pub struct ClientConfigLoadOptions {
4040

4141
/// Options for loading a specific client configuration profile.
4242
#[repr(C)]
43-
pub struct ClientConfigProfileLoadOptions {
43+
pub struct ClientEnvConfigProfileLoadOptions {
4444
pub profile: ByteArrayRef,
4545
pub path: ByteArrayRef,
4646
pub data: ByteArrayRef,
@@ -52,11 +52,11 @@ pub struct ClientConfigProfileLoadOptions {
5252

5353
// Wrapper types for JSON serialization
5454
#[derive(Serialize)]
55-
struct ClientConfig {
56-
profiles: HashMap<String, ClientConfigProfile>,
55+
struct ClientEnvConfig {
56+
profiles: HashMap<String, ClientEnvConfigProfile>,
5757
}
5858

59-
impl From<CoreClientConfig> for ClientConfig {
59+
impl From<CoreClientConfig> for ClientEnvConfig {
6060
fn from(c: CoreClientConfig) -> Self {
6161
Self {
6262
profiles: c.profiles.into_iter().map(|(k, v)| (k, v.into())).collect(),
@@ -65,22 +65,22 @@ impl From<CoreClientConfig> for ClientConfig {
6565
}
6666

6767
#[derive(Serialize)]
68-
struct ClientConfigProfile {
68+
struct ClientEnvConfigProfile {
6969
#[serde(skip_serializing_if = "Option::is_none")]
7070
address: Option<String>,
7171
#[serde(skip_serializing_if = "Option::is_none")]
7272
namespace: Option<String>,
7373
#[serde(skip_serializing_if = "Option::is_none")]
7474
api_key: Option<String>,
7575
#[serde(skip_serializing_if = "Option::is_none")]
76-
tls: Option<ClientConfigTLS>,
76+
tls: Option<ClientEnvConfigTLS>,
7777
#[serde(skip_serializing_if = "Option::is_none")]
78-
codec: Option<ClientConfigCodec>,
78+
codec: Option<ClientEnvConfigCodec>,
7979
#[serde(skip_serializing_if = "HashMap::is_empty")]
8080
grpc_meta: HashMap<String, String>,
8181
}
8282

83-
impl From<CoreClientConfigProfile> for ClientConfigProfile {
83+
impl From<CoreClientConfigProfile> for ClientEnvConfigProfile {
8484
fn from(c: CoreClientConfigProfile) -> Self {
8585
Self {
8686
address: c.address,
@@ -94,7 +94,7 @@ impl From<CoreClientConfigProfile> for ClientConfigProfile {
9494
}
9595

9696
#[derive(Serialize)]
97-
struct ClientConfigTLS {
97+
struct ClientEnvConfigTLS {
9898
#[serde(skip_serializing_if = "Option::is_none")]
9999
disabled: Option<bool>,
100100
#[serde(skip_serializing_if = "Option::is_none")]
@@ -107,7 +107,7 @@ struct ClientConfigTLS {
107107
client_key: Option<DataSource>,
108108
}
109109

110-
impl From<CoreClientConfigTLS> for ClientConfigTLS {
110+
impl From<CoreClientConfigTLS> for ClientEnvConfigTLS {
111111
fn from(c: CoreClientConfigTLS) -> Self {
112112
Self {
113113
disabled: c.disabled,
@@ -120,14 +120,14 @@ impl From<CoreClientConfigTLS> for ClientConfigTLS {
120120
}
121121

122122
#[derive(Serialize)]
123-
struct ClientConfigCodec {
123+
struct ClientEnvConfigCodec {
124124
#[serde(skip_serializing_if = "Option::is_none")]
125125
endpoint: Option<String>,
126126
#[serde(skip_serializing_if = "Option::is_none")]
127127
auth: Option<String>,
128128
}
129129

130-
impl From<CoreClientConfigCodec> for ClientConfigCodec {
130+
impl From<CoreClientConfigCodec> for ClientEnvConfigCodec {
131131
fn from(c: CoreClientConfigCodec) -> Self {
132132
Self {
133133
endpoint: c.endpoint,
@@ -204,18 +204,18 @@ fn serialize_or_error<T: Serialize>(data: T) -> Result<*const ByteArray, *const
204204
/// Returns ClientConfigOrFail with either success JSON or error message.
205205
/// The returned ByteArrays must be freed by the caller.
206206
#[unsafe(no_mangle)]
207-
pub extern "C" fn temporal_core_client_config_load(
208-
options: *const ClientConfigLoadOptions,
209-
) -> ClientConfigOrFail {
207+
pub extern "C" fn temporal_core_client_env_config_load(
208+
options: *const ClientEnvConfigLoadOptions,
209+
) -> ClientEnvConfigOrFail {
210210
if options.is_null() {
211211
let err = ByteArray::from_utf8("Options cannot be null".to_string());
212-
return ClientConfigOrFail {
212+
return ClientEnvConfigOrFail {
213213
success: std::ptr::null(),
214214
fail: err.into_raw(),
215215
};
216216
}
217217

218-
let result = || -> Result<ClientConfig, String> {
218+
let result = || -> Result<ClientEnvConfig, String> {
219219
let opts = unsafe { &*options };
220220
let env_vars_map = parse_env_vars(&opts.env_vars)?;
221221

@@ -232,18 +232,18 @@ pub extern "C" fn temporal_core_client_config_load(
232232

233233
match result() {
234234
Ok(data) => match serialize_or_error(data) {
235-
Ok(success) => ClientConfigOrFail {
235+
Ok(success) => ClientEnvConfigOrFail {
236236
success,
237237
fail: std::ptr::null(),
238238
},
239-
Err(fail) => ClientConfigOrFail {
239+
Err(fail) => ClientEnvConfigOrFail {
240240
success: std::ptr::null(),
241241
fail,
242242
},
243243
},
244244
Err(e) => {
245245
let err = ByteArray::from_utf8(e);
246-
ClientConfigOrFail {
246+
ClientEnvConfigOrFail {
247247
success: std::ptr::null(),
248248
fail: err.into_raw(),
249249
}
@@ -255,18 +255,18 @@ pub extern "C" fn temporal_core_client_config_load(
255255
/// Returns ClientConfigProfileOrFail with either success JSON or error message.
256256
/// The returned ByteArrays must be freed by the caller.
257257
#[unsafe(no_mangle)]
258-
pub extern "C" fn temporal_core_client_config_profile_load(
259-
options: *const ClientConfigProfileLoadOptions,
260-
) -> ClientConfigProfileOrFail {
258+
pub extern "C" fn temporal_core_client_env_config_profile_load(
259+
options: *const ClientEnvConfigProfileLoadOptions,
260+
) -> ClientEnvConfigProfileOrFail {
261261
if options.is_null() {
262262
let err = ByteArray::from_utf8("Options cannot be null".to_string());
263-
return ClientConfigProfileOrFail {
263+
return ClientEnvConfigProfileOrFail {
264264
success: std::ptr::null(),
265265
fail: err.into_raw(),
266266
};
267267
}
268268

269-
let result = || -> Result<ClientConfigProfile, String> {
269+
let result = || -> Result<ClientEnvConfigProfile, String> {
270270
let opts = unsafe { &*options };
271271

272272
let profile_name = if !opts.profile.data.is_null() && opts.profile.size > 0 {
@@ -294,18 +294,18 @@ pub extern "C" fn temporal_core_client_config_profile_load(
294294

295295
match result() {
296296
Ok(data) => match serialize_or_error(data) {
297-
Ok(success) => ClientConfigProfileOrFail {
297+
Ok(success) => ClientEnvConfigProfileOrFail {
298298
success,
299299
fail: std::ptr::null(),
300300
},
301-
Err(fail) => ClientConfigProfileOrFail {
301+
Err(fail) => ClientEnvConfigProfileOrFail {
302302
success: std::ptr::null(),
303303
fail,
304304
},
305305
},
306306
Err(e) => {
307307
let err = ByteArray::from_utf8(e);
308-
ClientConfigProfileOrFail {
308+
ClientEnvConfigProfileOrFail {
309309
success: std::ptr::null(),
310310
fail: err.into_raw(),
311311
}

0 commit comments

Comments
 (0)