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

Capturing Test run data from Developer Local Machines #26

Merged
merged 9 commits into from
Jun 9, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/manual-publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ jobs:
needs: build
name: Deploy Packages
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
steps:
- name: Download Package artifact
uses: actions/download-artifact@master
Expand All @@ -79,6 +78,7 @@ jobs:
release:
needs: deploy
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
steps:
- name: Create Draft Release
id: create_release
Expand Down
2 changes: 1 addition & 1 deletion src/Agoda.Builds.Metrics/Agoda.Builds.Metrics.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>

<TargetFrameworks>netstandard2.0;net472</TargetFrameworks>
<!-- Suppresses the warnings about the package not having assemblies in lib/*/.dll.-->
<NoPackageAnalysis>true</NoPackageAnalysis>
<!-- Change the default location where NuGet will put the build output -->
<BuildOutputTargetFolder>tasks</BuildOutputTargetFolder>
<!-- Include all referenced assemblies in the package -->
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Build.Framework" Version="15.1.1012" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
</PropertyGroup>

<ItemGroup>
Expand Down
37 changes: 33 additions & 4 deletions src/Agoda.DevFeedback.Common/DevFeedbackPublisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,56 @@ namespace Agoda.DevFeedback.Common
{
public static class DevFeedbackPublisher
{
public static void Publish(string apiEndpoint, DevFeedbackData data)
public static void Publish<T>(string apiEndpoint, T data)
{
Publish(apiEndpoint,data, DevLocalDataType.Build);
}

public static void Publish<T>(string apiEndpoint, T data, DevLocalDataType devLocalDataType)
{
var targetEndpoint = string.Empty;
switch (devLocalDataType)
{
case DevLocalDataType.Build:
targetEndpoint = GetApiEndpoint(apiEndpoint);
break;
case DevLocalDataType.NUint:
targetEndpoint = GetNunitApiEndpoint(apiEndpoint);
break;
default:
throw new ArgumentOutOfRangeException(nameof(devLocalDataType), devLocalDataType, null);
}
using (var httpClient = new HttpClient())
{
httpClient.Timeout = TimeSpan.FromSeconds(10);
httpClient.Timeout = TimeSpan.FromSeconds(2);

var content = new StringContent(JsonSerializer.Serialize(data), Encoding.UTF8, "application/json");
var response = httpClient.PostAsync(GetApiEndpoint(apiEndpoint), content).Result;
var response = httpClient.PostAsync(targetEndpoint, content).Result;

response.EnsureSuccessStatusCode();
}
}

private const string BASE_URL = "http://compilation-metrics/";
//private const string BASE_URL = "http://localhost:5000/";
static string GetApiEndpoint(string apiEndpoint)
{
if (string.IsNullOrEmpty(apiEndpoint))
{
apiEndpoint = Environment.GetEnvironmentVariable("BUILD_METRICS_ES_ENDPOINT");
}

return string.IsNullOrEmpty(apiEndpoint) ? "http://compilation-metrics/dotnet" : apiEndpoint;
return string.IsNullOrEmpty(apiEndpoint) ? $"{BASE_URL}dotnet" : apiEndpoint;
}

static string GetNunitApiEndpoint(string apiEndpoint)
{
if (string.IsNullOrEmpty(apiEndpoint))
{
apiEndpoint = Environment.GetEnvironmentVariable("NUNIT_METRICS_ES_ENDPOINT");
}

return string.IsNullOrEmpty(apiEndpoint) ? $"{BASE_URL}dotnet/nunit" : apiEndpoint;
}
}
}
8 changes: 8 additions & 0 deletions src/Agoda.DevFeedback.Common/DevLocalDataType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Agoda.DevFeedback.Common
{
public enum DevLocalDataType
{
Build,
NUint
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Agoda.Tests.Metrics.NUnit\Agoda.Tests.Metrics.NUnit.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Agoda.Analyzers" Version="1.0.523">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="NSubstitute" Version="4.2.2" />
<PackageReference Include="nunit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
<PackageReference Include="Shouldly" Version="4.2.1" />
</ItemGroup>
</Project>
19 changes: 19 additions & 0 deletions src/Agoda.Tests.Metrics.NUnit.Tests/LargeAmountOftestData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Collections;
using NUnit.Framework;

namespace Agoda.Tests.Metrics.NUnit.Tests;

public class LargeAmountOftestData
{
public static IEnumerable TestCases
{
get
{
for (var i = 1; i <= 1000; i++)
{
yield return new TestCaseData(i);
}

}
}
}
16 changes: 16 additions & 0 deletions src/Agoda.Tests.Metrics.NUnit.Tests/LoadTesting.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using NUnit.Framework;
using Shouldly;

namespace Agoda.Tests.Metrics.NUnit.Tests;

[TestFixture]
public class LoadTesting
{
[Test]
[Ignore("Used only for local testing to verify performance")]
[TestCaseSource(typeof(LargeAmountOftestData), nameof(LargeAmountOftestData.TestCases))]
public void WhenHaveLargeAmountsOfTest_ShouldSendInBatches(int n)
{
n.ShouldBeGreaterThan(0);
}
}
66 changes: 66 additions & 0 deletions src/Agoda.Tests.Metrics.NUnit.Tests/NUnitTestCaseConverterTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using NUnit.Framework;
using Shouldly;

namespace Agoda.Tests.Metrics.NUnit.Tests;

[TestFixture]
public class NUnitTestCaseConverterTests
{
[Test]
public void WhenInitTestCaseConverter_ShouldPopulateListOfTestCasesCorrectly()
{
var report =
@"<test-run id=""0"" name=""Agoda.TestingLib.Tests.dll"" fullname=""C:\source\TestNunitEvent\src\Agoda.TestingLib.Tests\bin\Debug\net6.0\Agoda.TestingLib.Tests.dll"" runstate=""Runnable"" testcasecount=""1"" result=""Passed"" total=""1"" passed=""1"" failed=""0"" warnings=""0"" inconclusive=""0"" skipped=""0"" asserts=""0"" engine-version=""3.15.3.0"" clr-version=""6.0.15"" start-time=""2023-03-26 05:43:46Z"" end-time=""2023-03-26 05:43:46Z"" duration=""0.085810"">
<command-line><![CDATA[C:\Users\myUser\AppData\Local\JetBrains\Installations\ReSharperPlatformVs17_cfc2aae1\TestRunner\netcoreapp3.0\ReSharperTestRunner.dll --parentProcessId 38540 -p 61838 -r e2d19589-94d1-4168-b342-3b18129cc640]]></command-line>
<filter>
<id>0-1000</id>
</filter>
<test-suite type=""Assembly"" id=""0-1002"" name=""Agoda.TestingLib.Tests.dll"" fullname=""C:/source/TestNunitEvent/src/Agoda.TestingLib.Tests/bin/Debug/net6.0/Agoda.TestingLib.Tests.dll"" runstate=""Runnable"" testcasecount=""1"" result=""Passed"" start-time=""2023-03-26T05:43:46.8009450Z"" end-time=""2023-03-26T05:43:46.8464532Z"" duration=""0.045445"" total=""1"" passed=""1"" failed=""0"" warnings=""0"" inconclusive=""0"" skipped=""0"" asserts=""0"">
<environment framework-version=""3.13.3.0"" clr-version=""6.0.15"" os-version=""Microsoft Windows 10.0.19044"" platform=""Win32NT"" cwd=""C:\source\TestNunitEvent\src\Agoda.TestingLib.Tests\bin\Debug\net6.0"" machine-name=""6TW24J3"" user=""jdickson"" user-domain=""AGODA"" culture=""en-AU"" uiculture=""en-US"" os-architecture=""x64"" />
<settings>
<setting name=""ProcessModel"" value=""InProcess"" />
<setting name=""DomainUsage"" value=""None"" />
<setting name=""ShadowCopyFiles"" value=""False"" />
<setting name=""TestParametersDictionary"" value="""" />
<setting name=""NumberOfTestWorkers"" value=""0"" />
<setting name=""SynchronousEvents"" value=""False"" />
<setting name=""RandomSeed"" value=""361791836"" />
<setting name=""LOAD"" value=""System.Collections.Generic.List`1[System.String]"" />
<setting name=""WorkDirectory"" value=""C:\source\TestNunitEvent\src\Agoda.TestingLib.Tests\bin\Debug\net6.0"" />
</settings>
<properties>
<property name=""_PID"" value=""51400"" />
<property name=""_APPDOMAIN"" value=""ReSharperTestRunner"" />
</properties>
<test-suite type=""TestSuite"" id=""0-1003"" name=""Agoda"" fullname=""Agoda"" runstate=""Runnable"" testcasecount=""1"" result=""Passed"" start-time=""2023-03-26T05:43:46.8069136Z"" end-time=""2023-03-26T05:43:46.8464495Z"" duration=""0.039535"" total=""1"" passed=""1"" failed=""0"" warnings=""0"" inconclusive=""0"" skipped=""0"" asserts=""0"">
<test-suite type=""TestSuite"" id=""0-1004"" name=""TestingLib"" fullname=""Agoda.TestingLib"" runstate=""Runnable"" testcasecount=""1"" result=""Passed"" start-time=""2023-03-26T05:43:46.8072958Z"" end-time=""2023-03-26T05:43:46.8464463Z"" duration=""0.039150"" total=""1"" passed=""1"" failed=""0"" warnings=""0"" inconclusive=""0"" skipped=""0"" asserts=""0"">
<test-suite type=""TestSuite"" id=""0-1005"" name=""Tests"" fullname=""Agoda.TestingLib.Tests"" runstate=""Runnable"" testcasecount=""1"" result=""Passed"" start-time=""2023-03-26T05:43:46.8073083Z"" end-time=""2023-03-26T05:43:46.8464343Z"" duration=""0.039127"" total=""1"" passed=""1"" failed=""0"" warnings=""0"" inconclusive=""0"" skipped=""0"" asserts=""0"">
<test-suite type=""TestFixture"" id=""0-1000"" name=""UnitTest1"" fullname=""Agoda.TestingLib.Tests.UnitTest1"" classname=""Agoda.TestingLib.Tests.UnitTest1"" runstate=""Runnable"" testcasecount=""1"" result=""Passed"" start-time=""2023-03-26T05:43:46.8073115Z"" end-time=""2023-03-26T05:43:46.8460458Z"" duration=""0.038735"" total=""1"" passed=""1"" failed=""0"" warnings=""0"" inconclusive=""0"" skipped=""0"" asserts=""0"">
<test-case id=""0-1001"" name=""1WhenOneIsOne_ItSHouldBeOne"" fullname=""Agoda.TestingLib.Tests.UnitTest1.1WhenOneIsOne_ItSHouldBeOne"" methodname=""WhenOneIsOne_ItSHouldBeOne"" classname=""Agoda.TestingLib.Tests.UnitTest1"" runstate=""Runnable"" seed=""396657978"" result=""Passed"" start-time=""2023-03-26T05:43:46.8096530Z"" end-time=""2023-03-26T05:43:46.8428099Z"" duration=""0.033255"" asserts=""0"" />
<test-case id=""0-1002"" name=""2WhenOneIsOne_ItSHouldBeOne"" fullname=""Agoda.TestingLib.Tests.UnitTest1.2WhenOneIsOne_ItSHouldBeOne"" methodname=""WhenOneIsOne_ItSHouldBeOne"" classname=""Agoda.TestingLib.Tests.UnitTest1"" runstate=""Runnable"" seed=""396657978"" result=""Passed"" start-time=""2023-03-26T05:43:46.8096530Z"" end-time=""2023-03-26T05:43:46.8428099Z"" duration=""0.033255"" asserts=""0"" />
</test-suite>
</test-suite>
<test-suite type=""TestSuite"" id=""0-1005"" name=""Tests"" fullname=""Agoda.TestingLib.Tests2"" runstate=""Runnable"" testcasecount=""1"" result=""Passed"" start-time=""2023-03-26T05:43:46.8073083Z"" end-time=""2023-03-26T05:43:46.8464343Z"" duration=""0.039127"" total=""1"" passed=""1"" failed=""0"" warnings=""0"" inconclusive=""0"" skipped=""0"" asserts=""0"">
<test-suite type=""TestFixture"" id=""0-1000"" name=""UnitTest1"" fullname=""Agoda.TestingLib.Tests.UnitTest2"" classname=""Agoda.TestingLib.Tests.UnitTest1"" runstate=""Runnable"" testcasecount=""1"" result=""Passed"" start-time=""2023-03-26T05:43:46.8073115Z"" end-time=""2023-03-26T05:43:46.8460458Z"" duration=""0.038735"" total=""1"" passed=""1"" failed=""0"" warnings=""0"" inconclusive=""0"" skipped=""0"" asserts=""0"">
<test-case id=""0-1003"" name=""3WhenOneIsOne_ItSHouldBeOne"" fullname=""Agoda.TestingLib.Tests.UnitTest2.3WhenOneIsOne_ItSHouldBeOne"" methodname=""WhenOneIsOne_ItSHouldBeOne"" classname=""Agoda.TestingLib.Tests.UnitTest1"" runstate=""Runnable"" seed=""396657978"" result=""Passed"" start-time=""2023-03-26T05:43:46.8096530Z"" end-time=""2023-03-26T05:43:46.8428099Z"" duration=""0.033255"" asserts=""0"" />
<test-case id=""0-1004"" name=""4WhenOneIsOne_ItSHouldBeOne"" fullname=""Agoda.TestingLib.Tests.UnitTest2.4WhenOneIsOne_ItSHouldBeOne"" methodname=""WhenOneIsOne_ItSHouldBeOne"" classname=""Agoda.TestingLib.Tests.UnitTest1"" runstate=""Runnable"" seed=""396657978"" result=""Passed"" start-time=""2023-03-26T05:43:46.8096530Z"" end-time=""2023-03-26T05:43:46.8428099Z"" duration=""0.033255"" asserts=""0"" />
</test-suite>
</test-suite>

</test-suite>
</test-suite>
</test-suite>
</test-run>
";
var result = new NUnitXmlEventConverter(report);
result.TestCases.Count.ShouldBe(4);
for (int i = 1; i <= 4; i++)
{
result.TestCases[i - 1].Name.ShouldBe($"{i}WhenOneIsOne_ItSHouldBeOne",customMessage:$"Name on {i}");
result.TestCases[i - 1].Id.ShouldBe($"0-100{i}", customMessage: $"Id on {i}");
result.TestCases[i - 1].Fullname.ShouldBe($"Agoda.TestingLib.Tests.UnitTest{(i+1) / 2}.{i}WhenOneIsOne_ItSHouldBeOne", customMessage: $"Fullname on {i}");
result.TestCases[i - 1].Duration.ShouldBe(0.033255, customMessage: $"Duration on {i}");
}

}
}
25 changes: 25 additions & 0 deletions src/Agoda.Tests.Metrics.NUnit.Tests/NUnitTestCasePayloadTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Agoda.DevFeedback.Common;
using NSubstitute;
using NUnit.Framework;
using Shouldly;

namespace Agoda.Tests.Metrics.NUnit.Tests;

[TestFixture]
public class NUnitTestCasePayloadTests
{
[Test]
public void WhenInit_ShouldHaveDefaultVarsFromEnvironment()
{
var underTest = new NUnitTestCasePayload(null,Substitute.For<GitContext>(), new List<TestCase>());

underTest.Id.ShouldNotBeNull();
underTest.UserName.ShouldBe(Environment.UserName);
underTest.CpuCount.ShouldBe(Environment.ProcessorCount);
#pragma warning disable AG0035
underTest.Hostname.ShouldBe(Environment.MachineName);
#pragma warning restore AG0035
underTest.Platform.ShouldBe((int)Environment.OSVersion.Platform);
underTest.Os.ShouldBe(Environment.OSVersion.VersionString);
}
}
1 change: 1 addition & 0 deletions src/Agoda.Tests.Metrics.NUnit/Agoda.Testinglib.addins
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Agoda.Tests.Metrics.NUnit.dll
30 changes: 30 additions & 0 deletions src/Agoda.Tests.Metrics.NUnit/Agoda.Tests.Metrics.NUnit.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
</PropertyGroup>

<ItemGroup>
<None Remove="Agoda.Testinglib.addins" />
</ItemGroup>

<ItemGroup>
<Content Include="Agoda.Testinglib.addins" >
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PackageCopyToOutput>true</PackageCopyToOutput>
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Agoda.Analyzers" Version="1.0.523">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NUnit.Engine" Version="3.16.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Agoda.DevFeedback.Common\Agoda.DevFeedback.Common.csproj" />
</ItemGroup>
</Project>
40 changes: 40 additions & 0 deletions src/Agoda.Tests.Metrics.NUnit/AgodaNUnitEventListener.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using NUnit.Engine;
using System;
using NUnit.Engine.Extensibility;
using System.Xml.Linq;
using Agoda.DevFeedback.Common;

namespace Agoda.Tests.Metrics.NUnit
{
[Extension]
public class AgodaNUnitEventListener : ITestEventListener
{
public AgodaNUnitEventListener()
{

}
public void OnTestEvent(string report)
{
try
{
var xmlConverter = new NUnitXmlEventConverter(report);

if (xmlConverter.TestCases.Count == 0) return;
if (!report.StartsWith("<test-run")) return;

var gitContext = GitContextReader.GetGitContext();

var data = new NUnitTestCasePayload(
typeof(AgodaNUnitEventListener).Assembly.GetName().Version.ToString(),
gitContext,
xmlConverter.TestCases
);
DevFeedbackPublisher.Publish(null, data, DevLocalDataType.NUint);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
}
Loading