Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run lsof after bundling for more info #58341

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.DotNet.CoreSetup.Test;
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.NET.HostModel.Bundle;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -162,6 +163,9 @@ public static string GenerateBundle(Bundler bundler, string sourceDir, string ou

var singleFile = bundler.GenerateBundle(fileSpecs);

// Verify no one has an open handle to the bundle
VerifyNoOpenHandles(singleFile);

if (copyExludedFiles)
{
foreach (var spec in fileSpecs)
Expand All @@ -178,10 +182,26 @@ public static string GenerateBundle(Bundler bundler, string sourceDir, string ou
return singleFile;
}

private static void VerifyNoOpenHandles(string path)
{
if (Environment.OSVersion.Platform == PlatformID.Unix)
{
var result = Command.Create("lsof", $"-f -- \"{path}\"")
.CaptureStdOut()
.CaptureStdErr()
.Execute();
if (result.StdOut.Length > 0)
{
// If anything has a handle to this file, there should be text in the stdout
throw new InvalidOperationException("Path: " + path + "\n" + result.StdOut);
}
}
}

// Bundle to a single-file
// In several tests, the single-file bundle is created explicitly using Bundle API
// instead of the SDK via /p:PublishSingleFile=true.
// This is necessary when the test needs the latest changes in the AppHost,
// This is necessary when the test needs the latest changes in the AppHost,
// which may not (yet) be available in the SDK.
public static Bundler BundleApp(TestProjectFixture fixture,
out string singleFile,
Expand Down