Skip to content

Commit 68ec687

Browse files
feat: parameterize delay in use plugin method
1 parent 0c8187d commit 68ec687

1 file changed

Lines changed: 34 additions & 2 deletions

File tree

  • rust/pact_ffi/src/plugins

rust/pact_ffi/src/plugins/mod.rs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ ffi_fn! {
3636
///
3737
/// * `plugin_name` is the name of the plugin to load.
3838
/// * `plugin_version` is the version of the plugin to load. It is optional, and can be NULL.
39+
/// * `completion_delay` is an arbitrary delay specified in milliseconds to add before the
40+
/// function returns to allow asynchronous tasks to complete.
3941
///
4042
/// Returns zero on success, and a positive integer value on failure.
4143
///
@@ -55,7 +57,7 @@ ffi_fn! {
5557
/// * `3` - Pact Handle is not valid.
5658
///
5759
/// When an error errors, LAST_ERROR will contain the error message.
58-
fn pactffi_using_plugin(pact: PactHandle, plugin_name: *const c_char, plugin_version: *const c_char) -> c_uint {
60+
fn pactffi_using_plugin_with_delay(pact: PactHandle, plugin_name: *const c_char, plugin_version: *const c_char, completion_delay: u64) -> c_uint {
5961
let plugin_name = safe_str!(plugin_name);
6062
let plugin_version = if_null(plugin_version, "");
6163

@@ -78,7 +80,7 @@ ffi_fn! {
7880
let result = load_plugin(&dependency).await;
7981

8082
// Add a small delay to let asynchronous tasks to complete
81-
sleep(Duration::from_millis(500)).await;
83+
sleep(Duration::from_millis(completion_delay)).await;
8284

8385
result
8486
});
@@ -103,6 +105,36 @@ ffi_fn! {
103105
}
104106
}
105107

108+
/// Add a plugin to be used by the test. The plugin needs to be installed correctly for this
109+
/// function to work.
110+
///
111+
/// * `plugin_name` is the name of the plugin to load.
112+
/// * `plugin_version` is the version of the plugin to load. It is optional, and can be NULL.
113+
///
114+
/// Returns zero on success, and a positive integer value on failure.
115+
///
116+
/// Note that plugins run as separate processes, so will need to be cleaned up afterwards by
117+
/// calling `pactffi_cleanup_plugins` otherwise you will have plugin processes left running.
118+
///
119+
/// # Safety
120+
///
121+
/// `plugin_name` must be a valid pointer to a NULL terminated string. `plugin_version` may be null,
122+
/// and if not NULL must also be a valid pointer to a NULL terminated string. Invalid
123+
/// pointers will result in undefined behaviour.
124+
///
125+
/// # Errors
126+
///
127+
/// * `1` - A general panic was caught.
128+
/// * `2` - Failed to load the plugin.
129+
/// * `3` - Pact Handle is not valid.
130+
///
131+
/// When an error errors, LAST_ERROR will contain the error message.
132+
#[no_mangle]
133+
pub extern fn pactffi_using_plugin(pact: PactHandle, plugin_name: *const c_char, plugin_version: *const c_char) -> c_uint {
134+
let result = pactffi_using_plugin_with_delay(pact, plugin_name, plugin_version, 500);
135+
result
136+
}
137+
106138
ffi_fn! {
107139
/// Decrement the access count on any plugins that are loaded for the Pact. This will shutdown
108140
/// any plugins that are no longer required (access count is zero).

0 commit comments

Comments
 (0)