Skip to content

Commit

Permalink
Add 1ES CI for DTFx.AS v2 (#1139)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmrdavid authored Jul 18, 2024
1 parent 33764d0 commit e73e75f
Show file tree
Hide file tree
Showing 19 changed files with 101 additions and 71 deletions.
8 changes: 4 additions & 4 deletions eng/ci/public-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ resources:
ref: refs/tags/release

extends:
# The template we extend injects compliance-checks into the pipleine, such as SDL and CodeQL
# The template we extend injects compliance-checks into the pipeline, such as SDL and CodeQL
template: v1/1ES.Unofficial.PipelineTemplate.yml@1es
parameters:
pool:
Expand Down Expand Up @@ -67,7 +67,7 @@ extends:
# Run tests
- template: /eng/templates/test.yml@self
parameters:
testAssembly: '**\bin\**\netcoreapp3.1\DurableTask.Core.Tests.dll'
testAssembly: '**\bin\**\DurableTask.Core.Tests.dll'
- stage: DTFxASValidate
dependsOn: []
jobs:
Expand All @@ -86,7 +86,7 @@ extends:
# Run tests
- template: /eng/templates/test.yml@self
parameters:
testAssembly: '**\bin\**\netcoreapp3.1\DurableTask.AzureStorage.Tests.dll'
testAssembly: '**\bin\**\DurableTask.AzureStorage.Tests.dll'
- stage: DTFxEmulatorValidate
dependsOn: []
jobs:
Expand All @@ -105,4 +105,4 @@ extends:
# Run tests
- template: /eng/templates/test.yml@self
parameters:
testAssembly: '**\bin\**\netcoreapp3.1\DurableTask.Emulator.Tests.dll'
testAssembly: '**\bin\**\DurableTask.Emulator.Tests.dll'
24 changes: 11 additions & 13 deletions eng/templates/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@ steps:
- task: VSTest@2
displayName: 'Run tests'
inputs:
testAssemblyVer2: |
${{ parameters.testAssembly }}
!**\obj\**
testFiltercriteria: 'TestCategory!=DisabledInCI'
vsTestVersion: 17.0
distributionBatchType: basedOnExecutionTime
platform: 'any cpu'
configuration: 'Debug'
diagnosticsEnabled: True
collectDumpOn: always
rerunFailedTests: true
rerunFailedThreshold: 30
rerunMaxAttempts: 3
testAssemblyVer2: ${{ parameters.testAssembly }}
testFiltercriteria: 'TestCategory!=DisabledInCI'
vsTestVersion: 17.0
distributionBatchType: basedOnExecutionTime
platform: 'any cpu'
configuration: 'Debug'
diagnosticsEnabled: True
collectDumpOn: always
rerunFailedTests: true
rerunFailedThreshold: 30
rerunMaxAttempts: 3
7 changes: 6 additions & 1 deletion src/DurableTask.AzureStorage/DurableTask.AzureStorage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>embedded</DebugType>
<IncludeSymbols>false</IncludeSymbols>
<!--NuGet licenseUrl and PackageIconUrl/iconUrl deprecation. -->
<PackageReadmeFile>.\README.md</PackageReadmeFile>
<!--NuGet licenseUrl and PackageIconUrl/iconUrl deprecation. -->
<NoWarn>NU5125;NU5048;CS7035</NoWarn> <!-- TODO: addition of CS7035 (version format doesn't follow convention) is a temporary workaround during 1ES migration -->
</PropertyGroup>

Expand Down Expand Up @@ -53,6 +54,10 @@
<ProjectReference Include="..\DurableTask.Core\DurableTask.Core.csproj" />
</ItemGroup>

<ItemGroup>
<None Include=".\..\..\README.md" Pack="true" PackagePath="\"/>
</ItemGroup>

<ItemGroup Condition="'$(Configuration)'=='Release'">
<Content Include="..\..\_manifest\**">
<Pack>true</Pack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ public override async IAsyncEnumerable<OrchestrationState> GetStateAsync(IEnumer
yield break;
}

IEnumerable<Task<OrchestrationState>> instanceQueries = instanceIds.Select(instance => this.GetStateAsync(instance, allExecutions: true, fetchInput: false, cancellationToken).SingleAsync().AsTask());
IEnumerable<Task<OrchestrationState>> instanceQueries = instanceIds.Select(instance => this.GetStateAsync(instance, allExecutions: true, fetchInput: false, cancellationToken).SingleOrDefaultAsync().AsTask());
foreach (OrchestrationState state in await Task.WhenAll(instanceQueries))
{
if (state != null)
Expand Down
7 changes: 6 additions & 1 deletion src/DurableTask.Core/DurableTask.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<FileVersion Condition="'$(FileVersionRevision)' != ''">$(VersionPrefix).$(FileVersionRevision)</FileVersion>
<!-- The assembly version is only the major/minor pair, making it easier to do in-place upgrades -->
<AssemblyVersion>$(MajorVersion).$(MinorVersion).0.0</AssemblyVersion>
<PackageReadmeFile>.\README.md</PackageReadmeFile>
</PropertyGroup>

<!-- This version is used as the nuget package version -->
Expand All @@ -38,12 +39,16 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="5.0.1" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="6.0.1" />
<PackageReference Include="System.Reactive.Core" Version="4.4.1" />
<PackageReference Include="System.Reactive.Compatibility" Version="4.4.1" />
<PackageReference Include="Castle.Core" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
<None Include=".\..\..\README.md" Pack="true" PackagePath="\"/>
</ItemGroup>

<ItemGroup Condition="'$(Configuration)'=='Release'">
<Content Include="..\..\_manifest\**">
<Pack>true</Pack>
Expand Down
1 change: 1 addition & 0 deletions src/DurableTask.Core/TaskActivityDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace DurableTask.Core
using DurableTask.Core.Logging;
using DurableTask.Core.Middleware;
using DurableTask.Core.Tracing;
using ActivityStatusCode = Tracing.ActivityStatusCode;

/// <summary>
/// Dispatcher for task activities to handle processing and renewing of work items
Expand Down
1 change: 1 addition & 0 deletions src/DurableTask.Core/TaskOrchestrationDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace DurableTask.Core
using DurableTask.Core.Middleware;
using DurableTask.Core.Serializing;
using DurableTask.Core.Tracing;
using ActivityStatusCode = Tracing.ActivityStatusCode;

/// <summary>
/// Dispatcher for orchestrations to handle processing and renewing, completion of orchestration events
Expand Down
14 changes: 7 additions & 7 deletions src/DurableTask.Core/Tracing/TraceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class TraceHelper
DateTimeOffset startTime = startEvent.ParentTraceContext.ActivityStartTime ?? default;

Activity? activity = ActivityTraceSource.StartActivity(
name: activityName,
activityName,
kind: activityKind,
parentContext: activityContext,
startTime: startTime);
Expand Down Expand Up @@ -139,7 +139,7 @@ public class TraceHelper
}

Activity? newActivity = ActivityTraceSource.StartActivity(
name: CreateSpanName(TraceActivityConstants.Activity, scheduledEvent.Name, scheduledEvent.Version),
CreateSpanName(TraceActivityConstants.Activity, scheduledEvent.Name, scheduledEvent.Version),
kind: ActivityKind.Server,
parentContext: activityContext);

Expand Down Expand Up @@ -180,7 +180,7 @@ public class TraceHelper
}

Activity? newActivity = ActivityTraceSource.StartActivity(
name: CreateSpanName(TraceActivityConstants.Activity, taskScheduledEvent.Name, taskScheduledEvent.Version),
CreateSpanName(TraceActivityConstants.Activity, taskScheduledEvent.Name, taskScheduledEvent.Version),
kind: ActivityKind.Client,
startTime: taskScheduledEvent.Timestamp,
parentContext: Activity.Current?.Context ?? default);
Expand Down Expand Up @@ -274,7 +274,7 @@ internal static void EmitTraceActivityForTaskFailed(
}

Activity? activity = ActivityTraceSource.StartActivity(
name: CreateSpanName(TraceActivityConstants.Orchestration, createdEvent.Name, createdEvent.Version),
CreateSpanName(TraceActivityConstants.Orchestration, createdEvent.Name, createdEvent.Version),
kind: ActivityKind.Client,
startTime: createdEvent.Timestamp,
parentContext: Activity.Current?.Context ?? default);
Expand Down Expand Up @@ -358,7 +358,7 @@ internal static void EmitTraceActivityForSubOrchestrationFailed(
string? targetInstanceId)
{
Activity? newActivity = ActivityTraceSource.StartActivity(
name: CreateSpanName(TraceActivityConstants.OrchestrationEvent, eventRaisedEvent.Name, null),
CreateSpanName(TraceActivityConstants.OrchestrationEvent, eventRaisedEvent.Name, null),
kind: ActivityKind.Producer,
parentContext: Activity.Current?.Context ?? default);

Expand Down Expand Up @@ -391,7 +391,7 @@ internal static void EmitTraceActivityForSubOrchestrationFailed(
internal static Activity? StartActivityForNewEventRaisedFromClient(EventRaisedEvent eventRaised, OrchestrationInstance instance)
{
Activity? newActivity = ActivityTraceSource.StartActivity(
name: CreateSpanName(TraceActivityConstants.OrchestrationEvent, eventRaised.Name, null),
CreateSpanName(TraceActivityConstants.OrchestrationEvent, eventRaised.Name, null),
kind: ActivityKind.Producer,
parentContext: Activity.Current?.Context ?? default,
tags: new KeyValuePair<string, object?>[]
Expand All @@ -418,7 +418,7 @@ internal static void EmitTraceActivityForTimer(
TimerFiredEvent timerFiredEvent)
{
Activity? newActivity = ActivityTraceSource.StartActivity(
name: CreateTimerSpanName(orchestrationName),
CreateTimerSpanName(orchestrationName),
kind: ActivityKind.Internal,
startTime: startTime,
parentContext: Activity.Current?.Context ?? default);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2252,6 +2252,7 @@ await Task.WhenAll(
/// End-to-end test which validates a simple orchestrator function that calls an activity function
/// and checks the OpenTelemetry trace information
/// </summary>
[TestCategory("DisabledInCI")]
[DataTestMethod]
[DataRow(true)]
[DataRow(false)]
Expand Down Expand Up @@ -2344,6 +2345,7 @@ public async Task OpenTelemetry_SayHelloWithActivity(bool enableExtendedSessions
/// End-to-end test which validates a simple orchestrator function that waits for an external event
/// raised through the RaiseEvent API and checks the OpenTelemetry trace information
/// </summary>
[TestCategory("DisabledInCI")]
[DataTestMethod]
[DataRow(true)]
[DataRow(false)]
Expand Down Expand Up @@ -2445,6 +2447,7 @@ public async Task OpenTelemetry_ExternalEvent_RaiseEvent(bool enableExtendedSess
/// End-to-end test which validates a simple orchestrator function that waits for an external event
/// raised by calling SendEvent and checks the OpenTelemetry trace information
/// </summary>
[TestCategory("DisabledInCI")]
[DataTestMethod]
[DataRow(true)]
[DataRow(false)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,31 @@
<TargetFrameworks>netcoreapp3.1;net462</TargetFrameworks>
</PropertyGroup>


<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" />
<PackageReference Include="Microsoft.WindowsAzure.ConfigurationManager" version="3.2.1" />
<PackageReference Include="WindowsAzure.Storage" version="8.7.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' != 'net462'">
<PackageReference Include="Azure.Monitor.OpenTelemetry.Exporter" Version="1.0.0-beta.3" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.6" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" />
<PackageReference Include="WindowsAzure.Storage" version="9.3.3" />
</ItemGroup>

<!-- Common package dependencies -->
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.2.0" />
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.5.0" />
<PackageReference Include="MSTest.TestFramework" Version="3.5.0" />
<PackageReference Include="Moq" Version="4.10.0" />

<!-- We don't really make use of these dependencies, but 1ES somehow detects them in our test project and flags them for update.
Since this is just a test project, and to prevent "warning fatigue" so real CVEs stand out, we choose to upgrade the dependency explicitly to remove the false alarm.-->
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" /> <!-- Version 4.3.1 was detected by default-->
<PackageReference Include="Microsoft.Data.Services.Client" Version="5.8.4" /> <!-- Without this, we resolve Microsoft.Data.OData 5.8.2, which is flagged-->
</ItemGroup>

<ItemGroup>
Expand All @@ -48,9 +51,6 @@
<None Update="large.jpeg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="testhost.dll.config" Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
6 changes: 4 additions & 2 deletions test/DurableTask.AzureStorage.Tests/TestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public static TestOrchestrationHost GetTestOrchestrationHost(
{
string storageConnectionString = GetTestStorageAccountConnectionString();

// TODO: update Microsoft.Extensions.Logging to avoid the following warning suppression
#pragma warning disable CS0618 // Type or member is obsolete
var settings = new AzureStorageOrchestrationServiceSettings
{
ExtendedSessionIdleTimeout = TimeSpan.FromSeconds(extendedSessionTimeoutInSeconds),
Expand All @@ -40,9 +42,9 @@ public static TestOrchestrationHost GetTestOrchestrationHost(
TaskHubName = GetTestTaskHubName(),

// Setting up a logger factory to enable the new DurableTask.Core logs
// TODO: Add a logger provider so we can collect these logs in memory.
LoggerFactory = new LoggerFactory(),
LoggerFactory = new LoggerFactory().AddConsole(LogLevel.Trace),
};
#pragma warning restore CS0618 // Type or member is obsolete

// Give the caller a chance to make test-specific changes to the settings
modifySettingsAction?.Invoke(settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@ await WaitForConditionAsync(

// Start with four workers and four partitions. Then kill three workers.
// Test that the remaining worker will take all the partitions.
[TestCategory("DisabledInCI")]
[TestMethod]
public async Task TestKillThreeWorker()
{
Expand Down Expand Up @@ -586,7 +585,6 @@ await WaitForConditionAsync(
/// Ensure that all instances should be processed sucessfully.
/// </summary>
/// <returns></returns>
[TestCategory("DisabledInCI")]
[TestMethod]
public async Task EnsureOwnedQueueExclusive()
{
Expand Down
27 changes: 21 additions & 6 deletions test/DurableTask.Core.Tests/DispatcherMiddlewareTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------
#if !NET462 // for some reasons these tests are not discoverable on 1ES, leading to the test getting aborted. TODO: Needs investigation
#nullable enable
namespace DurableTask.Core.Tests
{
Expand All @@ -27,6 +28,8 @@ namespace DurableTask.Core.Tests
using DurableTask.Core.History;
using DurableTask.Emulator;
using DurableTask.Test.Orchestrations;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Console;
using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
Expand All @@ -36,23 +39,34 @@ public class DispatcherMiddlewareTests
TaskHubClient client = null!;

[TestInitialize]
public async Task Initialize()
public void InitializeTests()
{
// configure logging so traces are emitted during tests.
// This facilitates debugging when tests fail.

// TODO: update Microsoft.Extensions.Logging to avoid the following warning suppression
#pragma warning disable CS0618 // Type or member is obsolete
var loggerFactory = new LoggerFactory().AddConsole(LogLevel.Trace);
#pragma warning restore CS0618 // Type or member is obsolete
var service = new LocalOrchestrationService();
this.worker = new TaskHubWorker(service);
this.worker = new TaskHubWorker(service, loggerFactory);

await this.worker
// We use `GetAwaiter().GetResult()` because otherwise this method will fail with:
// "X has wrong signature. The method must be non-static, public, does not return a value and should not take any parameter."
this.worker
.AddTaskOrchestrations(typeof(SimplestGreetingsOrchestration), typeof(ParentWorkflow), typeof(ChildWorkflow))
.AddTaskActivities(typeof(SimplestGetUserTask), typeof(SimplestSendGreetingTask))
.StartAsync();
.StartAsync().GetAwaiter().GetResult();

this.client = new TaskHubClient(service);
}

[TestCleanup]
public async Task TestCleanup()
public void CleanupTests()
{
await this.worker!.StopAsync(true);
// We use `GetAwaiter().GetResult()` because otherwise this method will fail with:
// "X has wrong signature. The method must be non-static, public, does not return a value and should not take any parameter."
this.worker!.StopAsync(true).GetAwaiter().GetResult();
}

[TestMethod]
Expand Down Expand Up @@ -440,3 +454,4 @@ public async Task MockActivityOrchestration()
}
}
}
#endif
Loading

0 comments on commit e73e75f

Please sign in to comment.