Skip to content

Commit

Permalink
Ensure all tests are running in CI pipeline (#645)
Browse files Browse the repository at this point in the history
  • Loading branch information
ConnorMcMahon authored and cgillum committed Mar 13, 2019
1 parent f39241d commit 4ca88f2
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ The general flow for making a change to the script host is:
3. Run the unit tests via Visual Studio Test Explorer by selecting "Run All"

## Writing tests
All tests for Durable Functions are found in [test/Common](https://github.com/Azure/azure-functions-durable-extension/tree/dev/test/Common). These tests are written using the [XUnit framework](https://xunit.github.io/).

NOTE: In order to run any tests you write in our CI pipeline, the test must have one of the following attributes:

- `[Trait("Category", PlatformSpecificHelpers.TestCategory)]`
- `[Trait("Category", PlatformSpecificHelpers.TestCategory + "_BVT")]`
- `[Trait("Category", PlatformSpecificHelpers.FlakeyTestCategory)]`

Please avoid writing flakey tests.

## Testing code changes locally (Visual Studio)

Expand Down
13 changes: 13 additions & 0 deletions test/Common/DurableTaskLifeCycleNotificationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public DurableTaskLifeCycleNotificationTest(ITestOutputHelper output)
}

[Theory]
[Trait("Category", PlatformSpecificHelpers.TestCategory)]
[InlineData(true)]
[InlineData(false)]
public async Task OrchestrationStartAndCompleted(bool extendedSessionsEnabled)
Expand Down Expand Up @@ -117,6 +118,7 @@ public async Task OrchestrationStartAndCompleted(bool extendedSessionsEnabled)
}

[Theory]
[Trait("Category", PlatformSpecificHelpers.TestCategory)]
[InlineData(true)]
[InlineData(false)]
public async Task OrchestrationFailed(bool extendedSessionsEnabled)
Expand Down Expand Up @@ -201,6 +203,7 @@ public async Task OrchestrationFailed(bool extendedSessionsEnabled)
}

[Theory]
[Trait("Category", PlatformSpecificHelpers.TestCategory)]
[InlineData(true)]
[InlineData(false)]
public async Task OrchestrationTerminate(bool extendedSessionsEnabled)
Expand Down Expand Up @@ -292,6 +295,7 @@ public async Task OrchestrationTerminate(bool extendedSessionsEnabled)
}

[Theory]
[Trait("Category", PlatformSpecificHelpers.TestCategory)]
[InlineData(true)]
[InlineData(false)]
public async Task OrchestrationStartedOptOutOfEvent(bool extendedSessionsEnabled)
Expand Down Expand Up @@ -349,6 +353,7 @@ public async Task OrchestrationStartedOptOutOfEvent(bool extendedSessionsEnabled
}

[Theory]
[Trait("Category", PlatformSpecificHelpers.TestCategory)]
[InlineData(true)]
[InlineData(false)]
public async Task OrchestrationCompletedOptOutOfEvent(bool extendedSessionsEnabled)
Expand Down Expand Up @@ -406,6 +411,7 @@ public async Task OrchestrationCompletedOptOutOfEvent(bool extendedSessionsEnabl
}

[Theory]
[Trait("Category", PlatformSpecificHelpers.TestCategory)]
[InlineData(true)]
[InlineData(false)]
public async Task OrchestrationFailedOptOutOfEvent(bool extendedSessionsEnabled)
Expand Down Expand Up @@ -464,6 +470,7 @@ public async Task OrchestrationFailedOptOutOfEvent(bool extendedSessionsEnabled)
}

[Theory]
[Trait("Category", PlatformSpecificHelpers.TestCategory)]
[InlineData(true)]
[InlineData(false)]
public async Task OrchestrationTerminatedOptOutOfEvent(bool extendedSessionsEnabled)
Expand Down Expand Up @@ -527,6 +534,7 @@ public async Task OrchestrationTerminatedOptOutOfEvent(bool extendedSessionsEnab
}

[Theory]
[Trait("Category", PlatformSpecificHelpers.TestCategory)]
[InlineData(true)]
[InlineData(false)]
public async Task OrchestrationEventGridApiReturnBadStatus(bool extendedSessionsEnabled)
Expand Down Expand Up @@ -792,6 +800,7 @@ private HttpMessageHandler ConfigureEventGridMockHandler(
}

[Theory]
[Trait("Category", PlatformSpecificHelpers.TestCategory)]
[InlineData(true)]
[InlineData(false)]
public async Task OrchestrationEventGridApiServiceUnavailableRetry(bool extendedSessionsEnabled)
Expand Down Expand Up @@ -871,6 +880,7 @@ public async Task OrchestrationEventGridApiServiceUnavailableRetry(bool extended
}

[Theory]
[Trait("Category", PlatformSpecificHelpers.TestCategory)]
[InlineData(true)]
[InlineData(false)]
public async Task OrchestrationEventGridApiExceptionRetry(bool extendedSessionsEnabled)
Expand Down Expand Up @@ -949,6 +959,7 @@ public async Task OrchestrationEventGridApiExceptionRetry(bool extendedSessionsE
}

[Theory]
[Trait("Category", PlatformSpecificHelpers.TestCategory)]
[InlineData(true)]
[InlineData(false)]
public async Task OrchestrationEventGridApiExceptionNoRetry(bool extendedSessionsEnabled)
Expand Down Expand Up @@ -1018,6 +1029,7 @@ public async Task OrchestrationEventGridApiExceptionNoRetry(bool extendedSession
}

[Theory]
[Trait("Category", PlatformSpecificHelpers.TestCategory)]
[InlineData(true)]
[InlineData(false)]
public async Task OrchestrationEventGridApiExceptionRetryCountOver(bool extendedSessionsEnabled)
Expand Down Expand Up @@ -1087,6 +1099,7 @@ public async Task OrchestrationEventGridApiExceptionRetryCountOver(bool extended
}

[Theory]
[Trait("Category", PlatformSpecificHelpers.TestCategory)]
[InlineData(true)]
[InlineData(false)]
public async Task OrchestrationEventGridApiRetryStatus(bool extendedSessionsEnabled)
Expand Down
1 change: 1 addition & 0 deletions test/Common/HttpApiHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ public async Task GetAllStatus_is_Success()
}

[Fact]
[Trait("Category", PlatformSpecificHelpers.TestCategory)]
public async Task GetQueryStatus_is_Success()
{
var list = (IList<DurableOrchestrationStatus>)new List<DurableOrchestrationStatus>
Expand Down
48 changes: 48 additions & 0 deletions test/Common/TestFrameworkTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Xunit;
using Xunit.Sdk;

namespace Microsoft.Azure.WebJobs.Extensions.DurableTask.Tests
{
public class TestFrameworkTests
{
[Fact]
[Trait("Category", PlatformSpecificHelpers.TestCategory)]
public void AllTestsHaveContinuousIntegrationFriendlyCategories()
{
Assembly currentAssembly = Assembly.GetExecutingAssembly();
List<MethodInfo> testsMissingCategoryTrait = currentAssembly.GetTypes()
.SelectMany(type => type.GetMethods())
.Where(MethodIsTest)
.Where(MethodMissingCorrectCategoryTrait)
.ToList();
Assert.False(testsMissingCategoryTrait.Any());
}

private static bool MethodIsTest(MethodInfo method)
{
var factAttribute = method.GetCustomAttribute<FactAttribute>(true);
var theoryAttribute = method.GetCustomAttribute<TheoryAttribute>(true);
return factAttribute != null || theoryAttribute != null;
}

private static bool MethodMissingCorrectCategoryTrait(MethodInfo method)
{
IReadOnlyList<KeyValuePair<string, string>> methodTraits = TraitHelper.GetTraits(method);
return !methodTraits.Any(TraitIsValidCategory);
}

private static bool TraitIsValidCategory(KeyValuePair<string, string> trait)
{
return trait.Key.Equals("Category") &&
(trait.Value.Equals(PlatformSpecificHelpers.TestCategory) ||
trait.Value.Equals(PlatformSpecificHelpers.TestCategory + "_BVT") ||
trait.Value.Equals(PlatformSpecificHelpers.FlakeyTestCategory));
}
}
}

0 comments on commit 4ca88f2

Please sign in to comment.