Repository navigation
Squash fix for process name. - #36913
Conversation
|
|
||
| // Get long process name if possible, otherwise use a fall back method. | ||
| string procName = Path.GetFileName(Process.GetExePath(pid)); | ||
| if (String.IsNullOrEmpty(procName)) |
There was a problem hiding this comment.
Yes correct however functionality is the same here.
There was a problem hiding this comment.
There was a problem hiding this comment.
Yes normally I would use string I must of mistyped. Basic types vs complex, string is fine but DateTime is a complex type etc.
| Assert.True(p.HasExited); | ||
| } | ||
|
|
||
| [Fact] |
There was a problem hiding this comment.
This test is only meant to work on Linux, right? If so, can you please move it to the ProcessTests.Unix.cs file and also add a [PlatformSpecific(TestPlatforms.Linux)] attribute to the test?
There was a problem hiding this comment.
This test is only meant to work on Linux, right?
Actually should be for Linux/Mac, but it doesn't work for Mac.
If so, can you please move it to the ProcessTests.Unix.cs file and also add a [PlatformSpecific(TestPlatforms.Linux)] attribute to the test?
I did it, but after Dan's review I moved it #36880 (comment)
Maybe we could keep here with [PlatformSpecific(~TestPlatforms.OSX)]
There was a problem hiding this comment.
We should probably have
[PlatformSpecific(TestPlatforms.AnyUnix)]
[ActiveIssue(XXXX, TestPlatforms.OSX)]
where XXXX is some separately issue you open for someone to figure out how to make this work on Mac.
There was a problem hiding this comment.
thank's forgot that ActiveIssue exclude plat.
| } | ||
| } | ||
| px.Kill(); | ||
| px.WaitForExit(); |
There was a problem hiding this comment.
It'd be better to have these, in particular the Kill, in a finally block, so that if some unexpected error happens, we don't leave a process running on the machine. We can also utilize Assert.Contains to simplify this whole thing, e.g.
try
{
Assert.Contains(Process.GetProcesses(), p => p.ProcessName == longProcessName);
}
finally
{
px.Kill();
px.WaitForExit();
}| { | ||
| string commandName = "sleep"; | ||
|
|
||
| // sleep program doesn't exist on some flavor |
There was a problem hiding this comment.
Where does / doesn't it exist?
There was a problem hiding this comment.
It was a Dan suggestion https://github.com/dotnet/corefx/issues/34437#issuecomment-460097674 /cc @danmosemsft
I don't know all distros so well, I cannot answer.
There was a problem hiding this comment.
sleep is part of GNU coreutils. quite common on modern UNIX systems that support bash. However there maybe a different set of params for sleep on OSX.
|
Does Mac still have the original bug? If so it's fine to fix for Linux for now, but we should have a new issue for Mac |
|
|
||
| // Get long process name if possible, otherwise use a fall back method. | ||
| string procName = Path.GetFileName(Process.GetExePath(pid)); | ||
| if (String.IsNullOrEmpty(procName)) |
There was a problem hiding this comment.
under what conditions can this happen?
There was a problem hiding this comment.
I don't have the backgroud of investigation I think it's better left @2E0PGS to answer.
There was a problem hiding this comment.
If you see the issue for this PR there is some background for this solution: https://github.com/dotnet/corefx/issues/34437
|
@stephentoub @danmosemsft @krwq fails also on Alpine...but in previous CI I saw only OSX fail...is apline leg new? |
| { | ||
| try | ||
| { | ||
| Assert.Contains(Process.GetProcesses(), p => p.ProcessName == longProcessName); |
There was a problem hiding this comment.
sleep is available as a busybox command on Alpine. If we do sleep 30 &\ ; ps uax, we get sleep 30 job running in background (or run jobs after sleep 30 &). But if we follow the symlink (/bin/sleep), it points to /bin/busybox.
readlink $(command -v sleep) -> /bin/busybox
one of these busybox processes are sleep. We can assert with PID to confirm:
try
{
Assert.Contains(Process.GetProcesses(), p => p.ProcessName == longProcessName);
}
catch(ContainsException)
{
// on Alpine, sleep is a symlink which points to /bin/busybox
Assert.Contains(Process.GetProcesses(), p => p.ProcessName == "busybox" && p.ProcessId == px.ProcessId);
}or simply:
// on Alpine, sleep is a symlink which points to /bin/busybox
Assert.Contains(Process.GetProcesses(), p => p.ProcessName == longProcessName || ( p.ProcessName == "busybox" && p.ProcessId == px.ProcessId));There was a problem hiding this comment.
BTW I wonder why first time I ran CI all works well(except OSX), maybe is a new CI leg.
There was a problem hiding this comment.
It still failed with same error. Maybe we can try adding some temporary debug info in catch to find out some details:
var runninProcesses = Process.GetProcesses();
try
{
Assert.Contains(runninProcesses, ...
}
catch(ContainsException)
{
Assert.False(true, $"Expected ID {px.Id} in collection: [" + string.Join(" ,", runninProcesses.Select(p => $"{p.Name}({p.Id})")) + "]");
}There was a problem hiding this comment.
tried to setup an Alpine image but I've got some issue with packages...try with CI
There was a problem hiding this comment.
I think it would be fine to open a separate issue to add a test for Alpine. Maybe using a custom library like NativeLibrary tests.
There was a problem hiding this comment.
@MarcoRossignoli, based on @danmosemsft's suggestion, we can revert changes made in 0c53c36, c8e1287 and cb11900 (or simply git reset --hard 790de76) and apply something like the following:
// sleep program doesn't exist on some flavor
+ // in flavors such as Alpine, sleep is a busybox command which cannot be renamed
+ // TODO (##github-issue##): build a custom long-running executable for this test instead of sleep
- if (!IsProgramInstalled(commandName))
+ if (!IsProgramInstalled(commandName) || IsProgramInstalled("busybox"))There was a problem hiding this comment.
perhaps ping 127.0.0.1 can act as your long running command?
There was a problem hiding this comment.
@krwq good thinking, but ping is busybox too, unfortunately:
DESKTOP-CJJBOPC:~# readlink $(command -v sleep)
/bin/busybox
DESKTOP-CJJBOPC:~# readlink $(command -v ping)
/bin/busybox
There was a problem hiding this comment.
Ok will do with revert and skip on busybox system
|
It seems it passed this time - which seems a bit random. I don't see why we got a different result. Could it be that the "sleep" is returning almost instantly on Alpine? But what are you hoping the test will do on Alpine? The purpose of the test is to verify that p.ProcessName returns the 30 character name. If we know on Alpine that it will return "busybox" then the test has no value anyway. You either have to copy "busybox" itself and then invoke it like sleep, or (if it's not important) make this test skip on Alpine. [edit, I see comment above now.] |
This reverts commit 8b515ad.
Handle long process names on Linux See: https://github.com/2E0PGS/corefx/commit/dotnet/corefx@56e73858adb046b57165eae44af111d64e2fcd98 * add test * update test * update test * address PR feedback * fix alpine ci * fix compilation * add some log for alpine fail * address PR feedback Commit migrated from dotnet/corefx@8b515ad
…orefx#37113) This reverts commit dotnet/corefx@8b515ad. Commit migrated from dotnet/corefx@9b71f88

See: 2E0PGS@56e7385