mirror of
https://github.com/actions/runner.git
synced 2025-12-14 22:24:11 +00:00
GitHub Actions Runner
This commit is contained in:
70
src/Test/L0/ProcessExtensionL0.cs
Normal file
70
src/Test/L0/ProcessExtensionL0.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace GitHub.Runner.Common.Tests
|
||||
{
|
||||
public sealed class ProcessExtensionL0
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Level", "L0")]
|
||||
[Trait("Category", "Common")]
|
||||
public async Task SuccessReadProcessEnv()
|
||||
{
|
||||
using (TestHostContext hc = new TestHostContext(this))
|
||||
{
|
||||
Tracing trace = hc.GetTrace();
|
||||
|
||||
string envName = Guid.NewGuid().ToString();
|
||||
string envValue = Guid.NewGuid().ToString();
|
||||
|
||||
Process sleep = null;
|
||||
try
|
||||
{
|
||||
#if OS_WINDOWS
|
||||
string node = Path.Combine(TestUtil.GetSrcPath(), @"..\_layout\externals\node12\bin\node");
|
||||
#else
|
||||
string node = Path.Combine(TestUtil.GetSrcPath(), @"../_layout/externals/node12/bin/node");
|
||||
hc.EnqueueInstance<IProcessInvoker>(new ProcessInvokerWrapper());
|
||||
#endif
|
||||
var startInfo = new ProcessStartInfo(node, "-e \"setTimeout(function(){{}}, 15 * 1000);\"");
|
||||
startInfo.Environment[envName] = envValue;
|
||||
sleep = Process.Start(startInfo);
|
||||
|
||||
var timeout = Process.GetProcessById(sleep.Id);
|
||||
while (timeout == null)
|
||||
{
|
||||
await Task.Delay(500);
|
||||
timeout = Process.GetProcessById(sleep.Id);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
trace.Info($"Read env from {timeout.Id}");
|
||||
var value = timeout.GetEnvironmentVariable(hc, envName);
|
||||
if (string.Equals(value, envValue, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
trace.Info($"Find the env.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
trace.Error(ex);
|
||||
}
|
||||
|
||||
Assert.True(false, "Fail to retrive process environment variable.");
|
||||
}
|
||||
finally
|
||||
{
|
||||
sleep?.Kill();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user