Files
runner/src/Test/L0/ProcessExtensionL0.cs
dependabot[bot] ce4d7be00f Bump xunit from 2.4.1 to 2.7.1 in /src (#3242)
* Bump xunit from 2.4.1 to 2.7.1 in /src

Bumps [xunit](https://github.com/xunit/xunit) from 2.4.1 to 2.7.1.
- [Commits](https://github.com/xunit/xunit/compare/2.4.1...2.7.1)

---
updated-dependencies:
- dependency-name: xunit
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Appease xunit warnings after upgrading to v2.7.1

* Appease the whitespace linter

* Appease the whitespace linter

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Patrick Ellis <319655+pje@users.noreply.github.com>
2024-05-21 10:47:43 -04:00

71 lines
2.3 KiB
C#

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(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\node16\bin\node");
#else
string node = Path.Combine(TestUtil.GetSrcPath(), @"../_layout/externals/node16/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.Fail("Failed to retrieve process environment variable.");
}
finally
{
sleep?.Kill();
}
}
}
}
}