Skip to content

Commit 9600755

Browse files
author
Steve Lee (POWERSHELL HE/HIM) (from Dev Box)
committed
remove test tracing, expand tokio macro and use multithread
1 parent 81585e2 commit 9600755

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

dsc/tests/dsc_mcp.tests.ps1

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,13 @@ Describe 'Tests for MCP server' {
1717
$mcp.StandardInput.WriteLine($request)
1818
$mcp.StandardInput.Flush()
1919
if (!$notify) {
20-
write-verbose -verbose "peeking stdout"
2120
while ($mcp.StandardOutput.Peek() -eq -1) {
2221
Start-Sleep -Milliseconds 100
2322
}
24-
write-verbose -verbose "peeking stderr"
2523
while ($mcp.StandardError.Peek() -ne -1) {
2624
$stderr = $mcp.StandardError.ReadLine()
2725
Write-Verbose -Verbose "MCP STDERR: $stderr"
2826
}
29-
write-verbose -verbose "reading stdout"
3027
$stdout = $mcp.StandardOutput.ReadLine()
3128
return ($stdout | ConvertFrom-Json -Depth 30)
3229
}
@@ -170,9 +167,7 @@ Describe 'Tests for MCP server' {
170167
}
171168

172169
It 'Calling show_dsc_resource works' {
173-
write-verbose -verbose "Listing resources to get a resource type"
174-
$resource = (dsc resource list | Select-Object -First 1 | ConvertFrom-Json -Depth 20)
175-
write-verbose -verbose "Using resource type '$($resource.type)' for show_dsc_resource test"
170+
$resource = (dsc resource list | ConvertFrom-Json -Depth 20 | Select-Object -First 1)
176171

177172
$mcpRequest = @{
178173
jsonrpc = "2.0"

dsc_lib/src/dscresources/command_resource.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -745,22 +745,25 @@ async fn run_process_async(executable: &str, args: Option<Vec<String>>, input: O
745745
/// Will panic if tokio runtime can't be created.
746746
///
747747
#[allow(clippy::implicit_hasher)]
748-
#[tokio::main]
749-
pub async fn invoke_command(executable: &str, args: Option<Vec<String>>, input: Option<&str>, cwd: Option<&str>, env: Option<HashMap<String, String>>, exit_codes: Option<&HashMap<i32, String>>) -> Result<(i32, String, String), DscError> {
750-
trace!("{}", t!("dscresources.commandResource.commandInvoke", executable = executable, args = args : {:?}));
751-
if let Some(cwd) = cwd {
752-
trace!("{}", t!("dscresources.commandResource.commandCwd", cwd = cwd));
753-
}
748+
pub fn invoke_command(executable: &str, args: Option<Vec<String>>, input: Option<&str>, cwd: Option<&str>, env: Option<HashMap<String, String>>, exit_codes: Option<&HashMap<i32, String>>) -> Result<(i32, String, String), DscError> {
749+
tokio::runtime::Builder::new_multi_thread().enable_all().build().unwrap().block_on(
750+
async {
751+
trace!("{}", t!("dscresources.commandResource.commandInvoke", executable = executable, args = args : {:?}));
752+
if let Some(cwd) = cwd {
753+
trace!("{}", t!("dscresources.commandResource.commandCwd", cwd = cwd));
754+
}
754755

755-
match run_process_async(executable, args, input, cwd, env, exit_codes).await {
756-
Ok((code, stdout, stderr)) => {
757-
Ok((code, stdout, stderr))
758-
},
759-
Err(err) => {
760-
error!("{}", t!("dscresources.commandResource.runProcessError", executable = executable, error = err));
761-
Err(err)
756+
match run_process_async(executable, args, input, cwd, env, exit_codes).await {
757+
Ok((code, stdout, stderr)) => {
758+
Ok((code, stdout, stderr))
759+
},
760+
Err(err) => {
761+
error!("{}", t!("dscresources.commandResource.runProcessError", executable = executable, error = err));
762+
Err(err)
763+
}
764+
}
762765
}
763-
}
766+
)
764767
}
765768

766769
/// Process the arguments for a command resource.

0 commit comments

Comments
 (0)