Skip to content
This repository was archived by the owner on Jul 5, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ If you want to do clean up all the containers created by the test, execute the `
## Debugging the functional tests
It is important to note that since the test application is deployed as a separate process/container, debugging the tests itself will not help debug the application code. A debugger need to be attached
to the process hosting the Application. (IISExpress or IIS)
The test apps refers to the Web SDK assemblies from your local build. After making the changes to product code, build locally (from Visual Studio or using ```buildDebug.cmd```). Then start the test application from its publish
folder in either IISExpress or IIS, and attach debugger to it. Open the .cs file you want your breakpoint in and set it. Now triggering a request to the application will hit the breakpoint.
The test apps refers to the Web SDK assemblies from your local build. After making the changes to product code, build locally (from Visual Studio or using ```buildDebug.cmd```). Then build and start the test application from its publish folder in either IISExpress or IIS, and attach debugger to it. Open the .cs file you want your breakpoint in and set it. Now triggering a request to the application will hit the breakpoint.
The exact request to be triggered depends on what you are doing. If investigating functional test failures locally, then the tests logs should contain the url it hit to trigger scenarios.

Dependency Collector tests deploy the test apps, along with dependencies (Fake Ingestion, SQL etc) to Docker containers inside same Docker virtual network, so that apps can access the dependencies with their names. However, if
Expand Down
66 changes: 56 additions & 10 deletions Test/E2ETests/E2ETests/Test452Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using AI;
using Microsoft.ApplicationInsights.DataContracts;
using System.Collections.Generic;
using System.Globalization;
using System.Net;

namespace E2ETests
{
Expand Down Expand Up @@ -86,7 +88,7 @@ public static void MyClassInitializeBase()
DockerUtils.ExecuteDockerComposeCommand("up -d --build", DockerComposeFileName);
Thread.Sleep(5000);
DockerUtils.PrintDockerProcessStats("Docker-Compose -build retry");

PopulateIPAddresses();
allAppsHealthy = HealthCheckAndRemoveImageIfNeededAllApp();
}

Expand Down Expand Up @@ -220,26 +222,30 @@ public void TestXComponentWebAppToWebApi()
Apps[AppNameBeingTested].ikey, Apps[TestConstants.WebApiName].ikey).Wait();
}

public void TestSyncHttpDependency(string expectedPrefix, string appname, string path)
public void TestHttpDependency(string expectedPrefix, string appname, string path,
string resultCodeExpected = "200",
bool successExpected = true)
{
var expectedDependencyTelemetry = new DependencyTelemetry();
expectedDependencyTelemetry.Type = "Http";
expectedDependencyTelemetry.Success = true;
expectedDependencyTelemetry.Success = successExpected;
expectedDependencyTelemetry.ResultCode = resultCodeExpected;

ValidateBasicDependency(Apps[appname].ipAddress, path, expectedDependencyTelemetry,
Apps[appname].ikey, 1, expectedPrefix);
}

public void TestSyncHttpDependency(string expectedPrefix)
{
TestSyncHttpDependency(expectedPrefix, AppNameBeingTested, "/Dependencies.aspx?type=httpsync");
TestHttpDependency(expectedPrefix, AppNameBeingTested, "/Dependencies.aspx?type=httpsync");
}

public void TestAsyncWithHttpClientHttpDependency(string expectedPrefix)
{
var expectedDependencyTelemetry = new DependencyTelemetry();
expectedDependencyTelemetry.Type = "Http";
expectedDependencyTelemetry.Success = true;
expectedDependencyTelemetry.ResultCode = "200";

ValidateBasicDependency(Apps[AppNameBeingTested].ipAddress, "/Dependencies.aspx?type=httpasynchttpclient", expectedDependencyTelemetry,
Apps[AppNameBeingTested].ikey, 1, expectedPrefix);
Expand All @@ -249,7 +255,10 @@ public void TestPostCallHttpDependency(string expectedPrefix)
{
var expectedDependencyTelemetry = new DependencyTelemetry();
expectedDependencyTelemetry.Type = "Http";
expectedDependencyTelemetry.Success = true;
expectedDependencyTelemetry.Success = true;

// 204 as the webapi does not return anything
expectedDependencyTelemetry.ResultCode = "204";

ValidateBasicDependency(Apps[AppNameBeingTested].ipAddress, "/Dependencies.aspx?type=httppost", expectedDependencyTelemetry,
Apps[AppNameBeingTested].ikey, 1, expectedPrefix);
Expand All @@ -260,6 +269,7 @@ public void TestFailedHttpDependency(string expectedPrefix)
var expectedDependencyTelemetry = new DependencyTelemetry();
expectedDependencyTelemetry.Type = "Http";
expectedDependencyTelemetry.Success = false;
expectedDependencyTelemetry.ResultCode = "500";

ValidateBasicDependency(Apps[AppNameBeingTested].ipAddress, "/Dependencies.aspx?type=httpfailedwithexception", expectedDependencyTelemetry,
Apps[AppNameBeingTested].ikey, 1, expectedPrefix);
Expand All @@ -271,6 +281,9 @@ public void TestFailedAtDnsHttpDependency(string expectedPrefix)
expectedDependencyTelemetry.Type = "Http";
expectedDependencyTelemetry.Success = false;

// Failed at DNS means status code not collected
//expectedDependencyTelemetry.ResultCode = "200";

ValidateBasicDependency(Apps[AppNameBeingTested].ipAddress, "/Dependencies.aspx?type=httpfailedwithinvaliddns", expectedDependencyTelemetry,
Apps[AppNameBeingTested].ikey, 1, expectedPrefix);
}
Expand All @@ -280,6 +293,7 @@ public void TestAsyncHttpDependency1(string expectedPrefix)
var expectedDependencyTelemetry = new DependencyTelemetry();
expectedDependencyTelemetry.Type = "Http";
expectedDependencyTelemetry.Success = true;
expectedDependencyTelemetry.ResultCode = "200";

ValidateBasicDependency(Apps[AppNameBeingTested].ipAddress, "/Dependencies.aspx?type=httpasync1", expectedDependencyTelemetry,
Apps[AppNameBeingTested].ikey, 1, expectedPrefix);
Expand All @@ -290,6 +304,7 @@ public void TestAsyncFailedHttpDependency1(string expectedPrefix)
var expectedDependencyTelemetry = new DependencyTelemetry();
expectedDependencyTelemetry.Type = "Http";
expectedDependencyTelemetry.Success = false;
expectedDependencyTelemetry.ResultCode = "500";

ValidateBasicDependency(Apps[AppNameBeingTested].ipAddress, "/Dependencies.aspx?type=failedhttpasync1", expectedDependencyTelemetry,
Apps[AppNameBeingTested].ikey, 1, expectedPrefix);
Expand All @@ -300,6 +315,7 @@ public void TestAsyncHttpDependency2(string expectedPrefix)
var expectedDependencyTelemetry = new DependencyTelemetry();
expectedDependencyTelemetry.Type = "Http";
expectedDependencyTelemetry.Success = true;
expectedDependencyTelemetry.ResultCode = "200";

ValidateBasicDependency(Apps[AppNameBeingTested].ipAddress, "/Dependencies.aspx?type=httpasync2", expectedDependencyTelemetry,
Apps[AppNameBeingTested].ikey, 1, expectedPrefix);
Expand All @@ -310,6 +326,7 @@ public void TestAsyncFailedHttpDependency2(string expectedPrefix)
var expectedDependencyTelemetry = new DependencyTelemetry();
expectedDependencyTelemetry.Type = "Http";
expectedDependencyTelemetry.Success = false;
expectedDependencyTelemetry.ResultCode = "500";

ValidateBasicDependency(Apps[AppNameBeingTested].ipAddress, "/Dependencies.aspx?type=failedhttpasync2", expectedDependencyTelemetry,
Apps[AppNameBeingTested].ikey, 1, expectedPrefix);
Expand All @@ -320,6 +337,7 @@ public void TestAsyncHttpDependency3(string expectedPrefix)
var expectedDependencyTelemetry = new DependencyTelemetry();
expectedDependencyTelemetry.Type = "Http";
expectedDependencyTelemetry.Success = true;
expectedDependencyTelemetry.ResultCode = "200";

ValidateBasicDependency(Apps[AppNameBeingTested].ipAddress, "/Dependencies.aspx?type=httpasync3", expectedDependencyTelemetry,
Apps[AppNameBeingTested].ikey, 1, expectedPrefix);
Expand All @@ -330,6 +348,7 @@ public void TestAsyncFailedHttpDependency3(string expectedPrefix)
var expectedDependencyTelemetry = new DependencyTelemetry();
expectedDependencyTelemetry.Type = "Http";
expectedDependencyTelemetry.Success = false;
expectedDependencyTelemetry.ResultCode = "500";

ValidateBasicDependency(Apps[AppNameBeingTested].ipAddress, "/Dependencies.aspx?type=failedhttpasync3", expectedDependencyTelemetry,
Apps[AppNameBeingTested].ikey, 1, expectedPrefix);
Expand All @@ -340,6 +359,7 @@ public void TestAsyncHttpDependency4(string expectedPrefix)
var expectedDependencyTelemetry = new DependencyTelemetry();
expectedDependencyTelemetry.Type = "Http";
expectedDependencyTelemetry.Success = true;
expectedDependencyTelemetry.ResultCode = "200";

ValidateBasicDependency(Apps[AppNameBeingTested].ipAddress, "/Dependencies.aspx?type=httpasync4", expectedDependencyTelemetry,
Apps[AppNameBeingTested].ikey, 1, expectedPrefix);
Expand All @@ -350,6 +370,7 @@ public void TestAsyncFailedHttpDependency4(string expectedPrefix)
var expectedDependencyTelemetry = new DependencyTelemetry();
expectedDependencyTelemetry.Type = "Http";
expectedDependencyTelemetry.Success = false;
expectedDependencyTelemetry.ResultCode = "500";

ValidateBasicDependency(Apps[AppNameBeingTested].ipAddress, "/Dependencies.aspx?type=failedhttpasync4", expectedDependencyTelemetry,
Apps[AppNameBeingTested].ikey, 1, expectedPrefix);
Expand All @@ -360,6 +381,7 @@ public void TestAsyncAwaitCallHttpDependency(string expectedPrefix)
var expectedDependencyTelemetry = new DependencyTelemetry();
expectedDependencyTelemetry.Type = "Http";
expectedDependencyTelemetry.Success = true;
expectedDependencyTelemetry.ResultCode = "200";

ValidateBasicDependency(Apps[AppNameBeingTested].ipAddress, "/Dependencies.aspx?type=httpasyncawait1", expectedDependencyTelemetry,
Apps[AppNameBeingTested].ikey, 1, expectedPrefix);
Expand All @@ -370,6 +392,7 @@ public void TestFailedAsyncAwaitCallHttpDependency(string expectedPrefix)
var expectedDependencyTelemetry = new DependencyTelemetry();
expectedDependencyTelemetry.Type = "Http";
expectedDependencyTelemetry.Success = false;
expectedDependencyTelemetry.ResultCode = "500";

ValidateBasicDependency(Apps[AppNameBeingTested].ipAddress, "/Dependencies.aspx?type=failedhttpasyncawait1", expectedDependencyTelemetry,
Apps[AppNameBeingTested].ikey, 1, expectedPrefix);
Expand All @@ -382,7 +405,7 @@ public void TestAzureTableDependencyWebApp(string expectedPrefix)
// Expected type is http instead of AzureTable as type is based on the target url which
// will be a local url in case of emulator.
expectedDependencyTelemetry.Type = "Http";
expectedDependencyTelemetry.Success = true;
expectedDependencyTelemetry.Success = true;

// 2 dependency item is expected.
// 1 from creating table, and 1 from writing data to it.
Expand All @@ -397,7 +420,7 @@ public void TestAzureQueueDependencyWebApp(string expectedPrefix)
// Expected type is http instead of AzureTable as type is based on the target url which
// will be a local url in case of emulator.
expectedDependencyTelemetry.Type = "Http";
expectedDependencyTelemetry.Success = true;
expectedDependencyTelemetry.Success = true;

// 2 dependency item is expected.
// 1 from creating queue, and 1 from writing data to it.
Expand All @@ -412,7 +435,7 @@ public void TestAzureBlobDependencyWebApp(string expectedPrefix)
// Expected type is http instead of AzureTable as type is based on the target url which
// will be a local url in case of emulator.
expectedDependencyTelemetry.Type = "Http";
expectedDependencyTelemetry.Success = true;
expectedDependencyTelemetry.Success = true;

// 2 dependency item is expected.
// 1 from creating table, and 1 from writing data to it.
Expand All @@ -428,6 +451,10 @@ public void TestSqlDependency(string expectedPrefix, string appname, string path
var expectedDependencyTelemetry = new DependencyTelemetry();
expectedDependencyTelemetry.Type = "SQL";
expectedDependencyTelemetry.Success = success;
if (!success)
{
expectedDependencyTelemetry.ResultCode = "208";
}

ValidateBasicDependency(Apps[appname].ipAddress, path, expectedDependencyTelemetry,
Apps[appname].ikey, 1, expectedPrefix);
Expand Down Expand Up @@ -831,7 +858,8 @@ private async Task ValidateBasicRequestAsync(string targetInstanceIp, string tar
}

private void ValidateBasicDependency(string targetInstanceIp, string targetPath,
DependencyTelemetry expectedDependencyTelemetry, string ikey, int count, string expectedPrefix, int additionalSleepTimeMsec = 0)
DependencyTelemetry expectedDependencyTelemetry, string ikey, int count,
string expectedPrefix, int additionalSleepTimeMsec = 0)
{
var success = ExecuteWebRequestToTarget(targetInstanceIp, targetPath).Result;
Assert.IsTrue(success, "Web App did not respond with success. Failing test. Check exception from logs.");
Expand Down Expand Up @@ -986,6 +1014,24 @@ private void ValidateDependency(DependencyTelemetry expectedDependencyTelemetry,

string actualSdkVersion = actualDependencyTelemetry.tags[new ContextTagKeys().InternalSdkVersion];
Assert.IsTrue(actualSdkVersion.Contains(expectedPrefix), "Actual version:" + actualSdkVersion);

if(!string.IsNullOrEmpty(expectedDependencyTelemetry.ResultCode))
{
Assert.AreEqual(expectedDependencyTelemetry.ResultCode, actualDependencyTelemetry.data.baseData.resultCode);
}

var depTime = TimeSpan.Parse(actualDependencyTelemetry.data.baseData.duration, CultureInfo.InvariantCulture);
if (expectedDependencyTelemetry.Success.HasValue)
{
if(expectedDependencyTelemetry.Success.Value == true)
{
Assert.IsTrue(depTime.TotalMilliseconds > 0, "Access time should be above zero");
}
else
{
Assert.IsTrue(depTime.TotalMilliseconds >= 0, "Access time should be zero or above zero if success is false.");
}
}
}

private void PrintDependencies(IList<TelemetryItem<AI.RemoteDependencyData>> dependencies)
Expand Down Expand Up @@ -1014,7 +1060,7 @@ private void PrintRequests(IList<TelemetryItem<AI.RequestData>> requests)
{
foreach (var req in requests)
{
Trace.WriteLine("Dependency Item Details");
Trace.WriteLine("Request Item Details");
Trace.WriteLine("req.time: " + req.time);
Trace.WriteLine("req.iKey: " + req.iKey);
Trace.WriteLine("req.name: " + req.name);
Expand Down
16 changes: 12 additions & 4 deletions Test/E2ETests/E2ETests/netcore20/TestCore20OnNetCore20.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.ApplicationInsights.DataContracts;
using System.Collections;
using System.Collections.Generic;
using System.Net;

namespace E2ETests.netcore20
{
Expand Down Expand Up @@ -57,16 +58,23 @@ public static void MyClassInitialize(TestContext testContext)

[TestMethod]
[TestCategory("Core20")]
public void TestCore20OnNetCore20_SyncHttpDependency()
public void TestCore20OnNetCore20_HttpDependency()
{
base.TestSyncHttpDependency(VersionPrefix, AppNameBeingTested, "/external/calls?type=http");
base.TestHttpDependency(VersionPrefix, AppNameBeingTested, "/external/calls?type=http", "200", true);
}

[TestMethod]
[TestCategory("Core20")]
public void TestCore20OnNetCore20_SyncHttpPostDependency()
public void TestCore20OnNetCore20_HttpPostDependency()
{
base.TestSyncHttpDependency(VersionPrefix, AppNameBeingTested, "/external/calls?type=httppost");
base.TestHttpDependency(VersionPrefix, AppNameBeingTested, "/external/calls?type=httppost", "204", true);
}

[TestMethod]
[TestCategory("Core20")]
public void TestCore20OnNetCore20_FailedHttpDependency()
{
base.TestHttpDependency(VersionPrefix, AppNameBeingTested, "/external/calls?type=failedhttp", "500", false);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public partial class Dependencies : System.Web.UI.Page

private const string UrlTestWebApiGetCallTemplate = "http://{0}:80/api/values";
private const string UrlGoogle = "http://google.com";
public const string UrlWhichThrowException = "http://e2etestwebapi:80/api/values/999";
public const string UrlWhichThrowExceptionFormat = "http://{0}:80/api/values/999";
private const string UrlWithNonexistentHostName = "http://abcdefzzzzeeeeadadad.com";
private static bool etwEnabled = false;

Expand All @@ -43,6 +43,7 @@ protected void Page_Load(object sender, EventArgs e)

var webApiHostName = Microsoft.Azure.CloudConfigurationManager.GetSetting("webapihostname");
string UrlTestWebApiGetCall = string.Format(UrlTestWebApiGetCallTemplate, webApiHostName);
string UrlWhichThrowException = string.Format(UrlWhichThrowExceptionFormat, webApiHostName);

var ingestionhostname = Microsoft.Azure.CloudConfigurationManager.GetSetting("ingestionhostname");
TelemetryConfiguration.Active.TelemetryChannel.EndpointAddress = string.Format(EndPointAddressFormat, ingestionhostname);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ public AppInsightsOptions()
}
public string EndPoint { get; set; }
public string SqlServerInstance { get; set; }
public string Webapihostname { get; set; }
}
}
Loading