public async Task ProcessApiTests() { string appName = "ProcessApiTests"; await ApplicationManager.RunAsync(appName, async appManager => { // Test current process var process = await appManager.ProcessManager.GetCurrentProcessAsync(); int currentId = process.Id; DateTime startTime = process.StartTime; Assert.NotNull(process); Assert.Contains("w3wp", process.Name); Assert.Contains("/diagnostics/processes/" + currentId, process.Href.AbsoluteUri); // Test get process by id process = await appManager.ProcessManager.GetProcessAsync(currentId); Assert.NotNull(process); Assert.Contains("w3wp", process.Name); Assert.Contains("/diagnostics/processes/" + currentId, process.Href.AbsoluteUri); // Test get not running process id var notfound = await KuduAssert.ThrowsUnwrappedAsync <HttpUnsuccessfulRequestException>(() => appManager.ProcessManager.GetProcessAsync(99999)); Assert.Equal(HttpStatusCode.NotFound, notfound.ResponseMessage.StatusCode); Assert.Contains("is not running", notfound.ResponseMessage.ExceptionMessage); // Test process list var processes = await appManager.ProcessManager.GetProcessesAsync(); Assert.True(processes.Count() >= 1); Assert.True(processes.Any(p => p.Id == currentId)); // Test minidump var stream = new MemoryStream(); using (var minidump = await appManager.ProcessManager.MiniDump()) { Assert.NotNull(minidump); await minidump.CopyToAsync(stream); } Assert.True(stream.Length > 0); // Test kill process await KuduAssert.ThrowsUnwrappedAsync <HttpRequestException>(() => appManager.ProcessManager.KillProcessAsync(currentId)); HttpUtils.WaitForSite(appManager.SiteUrl, delayBeforeRetry: 10000); process = await appManager.ProcessManager.GetCurrentProcessAsync(); Assert.NotEqual(startTime, process.StartTime); }); }
[InlineData("https://api.nuget.org/v3/index.json", "filecounter")] // v3 endpoint public async Task SiteExtensionInstallUninstallAsyncTest(string feedEndpoint, string testPackageId) { TestTracer.Trace("Testing against feed: '{0}'", feedEndpoint); const string appName = "SiteExtensionInstallUninstallAsyncTest"; await ApplicationManager.RunAsync(appName, async appManager => { var manager = appManager.SiteExtensionManager; await CleanSiteExtensions(manager); // Get the latest package, make sure that call will return right away when we try to update TestTracer.Trace("Get latest package '{0}' from '{1}'", testPackageId, feedEndpoint); SiteExtensionInfo latestPackage = await(await manager.GetRemoteExtension(testPackageId, feedUrl: feedEndpoint)).Content.ReadAsAsync <SiteExtensionInfo>(); Assert.Equal(testPackageId, latestPackage.Id); // install from non-default endpoint UpdateHeaderIfGoingToBeArmRequest(manager.Client, true); TestTracer.Trace("Install package '{0}'-'{1}' fresh from '{2}' async", testPackageId, latestPackage.Version, feedEndpoint); HttpResponseMessage responseMessage = await manager.InstallExtension(id: testPackageId, version: latestPackage.Version, feedUrl: feedEndpoint); ArmEntry <SiteExtensionInfo> armResult = await responseMessage.Content.ReadAsAsync <ArmEntry <SiteExtensionInfo> >(); Assert.Equal(string.Empty, armResult.Location); // test "x-ms-geo-location" header is empty, same value should be assign to "Location" Assert.Equal(HttpStatusCode.Created, responseMessage.StatusCode); Assert.True(responseMessage.Headers.Contains(Constants.RequestIdHeader)); TestTracer.Trace("Poll for status. Expecting 200 response eventually with site operation header."); responseMessage = await PollAndVerifyAfterArmInstallation(manager, testPackageId); armResult = await responseMessage.Content.ReadAsAsync <ArmEntry <SiteExtensionInfo> >(); // after successfully installed, should return SiteOperationHeader to notify GEO to restart website Assert.True(responseMessage.Headers.Contains(Constants.SiteOperationHeaderKey)); Assert.Equal(feedEndpoint, armResult.Properties.FeedUrl); Assert.Equal(latestPackage.Version, armResult.Properties.Version); Assert.Equal(HttpStatusCode.OK, responseMessage.StatusCode); Assert.True(responseMessage.Headers.Contains(Constants.RequestIdHeader)); TestTracer.Trace("Get '{0}' again. Expecting 200 response without site operation header", testPackageId); responseMessage = await manager.GetLocalExtension(testPackageId); armResult = await responseMessage.Content.ReadAsAsync <ArmEntry <SiteExtensionInfo> >(); // get again shouldn`t see SiteOperationHeader anymore Assert.False(responseMessage.Headers.Contains(Constants.SiteOperationHeaderKey)); Assert.Equal(feedEndpoint, armResult.Properties.FeedUrl); Assert.Equal(latestPackage.Version, armResult.Properties.Version); Assert.Equal(HttpStatusCode.OK, responseMessage.StatusCode); Assert.True(responseMessage.Headers.Contains(Constants.RequestIdHeader)); TestTracer.Trace("Try to update package '{0}' without given a feed", testPackageId); // Not passing feed endpoint will default to feed endpoint from installed package // Update should return right away, expecting code to look up from feed that store in local package // since we had installed the latest package, there is nothing to update. // We shouldn`t see any site operation header value // And there is no polling, since it finished within 15 seconds responseMessage = await manager.InstallExtension(testPackageId); armResult = await responseMessage.Content.ReadAsAsync <ArmEntry <SiteExtensionInfo> >(); Assert.Equal(string.Empty, armResult.Location); // test "x-ms-geo-location" header is empty, same value should be assign to "Location" Assert.Equal(latestPackage.Id, armResult.Properties.Id); Assert.Equal(feedEndpoint, armResult.Properties.FeedUrl); Assert.Equal(HttpStatusCode.OK, responseMessage.StatusCode); Assert.True(responseMessage.Headers.Contains(Constants.RequestIdHeader)); // no installation operation happened, shouldn`t see SiteOperationHeader return Assert.False(responseMessage.Headers.Contains(Constants.SiteOperationHeaderKey)); TestTracer.Trace("Uninstall '{0}' async", testPackageId); responseMessage = await manager.UninstallExtension(testPackageId); armResult = await responseMessage.Content.ReadAsAsync <ArmEntry <SiteExtensionInfo> >(); Assert.Null(armResult); Assert.Equal(HttpStatusCode.OK, responseMessage.StatusCode); Assert.True(responseMessage.Headers.Contains(Constants.RequestIdHeader)); TestTracer.Trace("Get '{0}' again. Expecting 404.", testPackageId); var ex = await KuduAssert.ThrowsUnwrappedAsync <HttpUnsuccessfulRequestException>(async() => { await manager.GetLocalExtension(testPackageId); }); Assert.Equal(HttpStatusCode.NotFound, ex.ResponseMessage.StatusCode); }); }
public async Task ProcessApiTests() { string appName = "ProcessApiTests"; await ApplicationManager.RunAsync(appName, async appManager => { // Test current process var process = await appManager.ProcessManager.GetCurrentProcessAsync(); int currentId = process.Id; var currentUser = process.UserName; DateTime startTime = process.StartTime; Assert.NotNull(process); Assert.Contains("w3wp", process.Name); Assert.Contains("/api/processes/" + currentId, process.Href.AbsoluteUri); // Test get process by id process = await appManager.ProcessManager.GetProcessAsync(currentId); Assert.NotNull(process); Assert.Contains("w3wp", process.Name); Assert.Contains("/api/processes/" + currentId, process.Href.AbsoluteUri); // Test get not running process id var notfound = await KuduAssert.ThrowsUnwrappedAsync <HttpUnsuccessfulRequestException>(() => appManager.ProcessManager.GetProcessAsync(99999)); Assert.Equal(HttpStatusCode.NotFound, notfound.ResponseMessage.StatusCode); Assert.Contains("is not running", notfound.ResponseMessage.ExceptionMessage); // Test process list var processes = await appManager.ProcessManager.GetProcessesAsync(); Assert.True(processes.Count() >= 1); Assert.True(processes.Any(p => p.Id == currentId)); Assert.True(processes.All(p => p.UserName == currentUser)); // Test all-users process list var allProcesses = await appManager.ProcessManager.GetProcessesAsync(allUsers: true); Assert.True(allProcesses.Count() >= processes.Count()); Assert.True(allProcesses.Any(p => p.Id == currentId)); Assert.True(allProcesses.Any(p => p.UserName == currentUser)); // Test process dumps foreach (var format in new[] { "raw", "zip" }) { TestTracer.Trace("Test minidump format={0}", format); using (var stream = new MemoryStream()) { using (var minidump = await appManager.ProcessManager.MiniDump(format: format)) { Assert.NotNull(minidump); await minidump.CopyToAsync(stream); } TestTracer.Trace("Test minidump lenth={0}", stream.Length); Assert.True(stream.Length > 0); } } //Test Handles process = await appManager.ProcessManager.GetCurrentProcessAsync(); Assert.NotNull(process); Assert.True( process.OpenFileHandles.Any( h => h.IndexOf("kudu.core.dll", StringComparison.InvariantCultureIgnoreCase) != -1)); //Test Modules process = await appManager.ProcessManager.GetCurrentProcessAsync(); Assert.NotNull(process); Assert.True( process.Modules.Any(h => h.FileName.Equals("ntdll.dll", StringComparison.InvariantCultureIgnoreCase))); // Test kill process await KuduAssert.ThrowsUnwrappedAsync <HttpRequestException>(() => appManager.ProcessManager.KillProcessAsync(currentId)); HttpUtils.WaitForSite(appManager.SiteUrl, delayBeforeRetry: 10000); process = await appManager.ProcessManager.GetCurrentProcessAsync(); Assert.NotEqual(startTime, process.StartTime); }); }