Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
45 changes: 45 additions & 0 deletions pipeline/azure-pipelines-emulator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
trigger: none
pr:
branches:
include:
- master
- releases/*

pool:
vmImage: 'windows-latest'

steps:
- pwsh: |
Write-Host "Downloading Cosmos Emulator - $env:EMULATORMSIURL" -ForegroundColor green
Invoke-WebRequest "$env:EMULATORMSIURL" -OutFile "$env:temp\azure-cosmosdb-emulator.msi"
Write-Host "Finished Downloading Cosmos Emulator - $env:temp\azure-cosmosdb-emulator.msi" -ForegroundColor green
dir "$env:temp"
choco install lessmsi
choco upgrade lessmsi
mkdir "$env:temp\Azure Cosmos DB Emulator"
lessmsi x "$env:temp\azure-cosmosdb-emulator.msi" "$env:temp\Azure Cosmos DB Emulator\"
Write-Host "Starting Cosmos DB Emulator" -ForegroundColor green
Start-Process "$env:temp\Azure Cosmos DB Emulator\SourceDir\Azure Cosmos DB Emulator\CosmosDB.Emulator.exe" "/NoExplorer /NoUI /DisableRateLimiting /PartitionCount=100 /Consistency=Strong /enableRio /overrides=sqlAllowGroupByClause:true" -Verb RunAs
Import-Module "$env:temp\Azure Cosmos DB Emulator\SourceDir\Azure Cosmos DB Emulator\PSModules\Microsoft.Azure.CosmosDB.Emulator"
Get-Item env:* | Sort-Object -Property Name
for ($i=0; $i -lt 10; $i++) {
$status=Get-CosmosDbEmulatorStatus
if ($status -ne "Running") {
sleep 30;
Write-Host "Cosmos DB Emulator Status: $status" -ForegroundColor yellow
} else {
break;
}
}
- task: DotNetCoreCLI@2
displayName: Build
inputs:
command: build
projects: '**/*.csproj'
- script: dotnet test ./src/DocumentDB.ChangeFeedProcessor.IntegrationTests/DocumentDB.ChangeFeedProcessor.IntegrationTests.csproj --logger trx
displayName: 'Running tests'
- task: PublishTestResults@2
condition: succeededOrFailed()
inputs:
testRunner: VSTest
testResultsFiles: '**/*.trx'
29 changes: 29 additions & 0 deletions pipeline/azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
trigger: none
pr:
branches:
include:
- master
- releases/*

strategy:
matrix:
windows:
imageName: 'windows-latest'

pool:
vmImage: $(imageName)

steps:
- task: DotNetCoreCLI@2
displayName: Build
inputs:
command: build
projects: '**/*.csproj'
arguments: '--configuration Release'
- script: dotnet test ./src/DocumentDB.ChangeFeedProcessor.UnitTests/DocumentDB.ChangeFeedProcessor.UnitTests.csproj --logger trx
displayName: 'Running tests'
- task: PublishTestResults@2
condition: succeededOrFailed()
inputs:
testRunner: VSTest
testResultsFiles: '**/*.trx'
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Reflection;
using System.Threading;
Expand All @@ -24,7 +23,6 @@ public class TestClassData
internal readonly int testCount;
internal readonly bool isPartitionedMonitoredCollection;
internal readonly bool isPartitionedLeaseCollection;
internal volatile int executedTestCount;
internal DocumentCollectionInfo monitoredCollectionInfo;
internal DocumentCollectionInfo leaseCollectionInfoTemplate;

Expand Down Expand Up @@ -93,18 +91,13 @@ public class IntegrationTestCollection : ICollectionFixture<IntegrationTestFixtu
/// </remarks>
[Trait("Category", "Integration")]
[Collection("Integration tests")]
public class IntegrationTest: IDisposable
public class IntegrationTest: IAsyncLifetime
{
private const string leaseCollectionInfoPropertyName = "leaseCollectionInfo";
protected static int monitoredOfferThroughput;
protected static int leaseOfferThroughput;
protected static readonly TimeSpan changeWaitTimeout = TimeSpan.FromSeconds(30);

/// <summary>
/// This dictionary has one entry per derived class.
/// </summary>
private static object testClassesSyncRoot = new object();

IntegrationTestFixture fixture;

protected DocumentCollectionInfo LeaseCollectionInfo
Expand Down Expand Up @@ -138,28 +131,23 @@ public IntegrationTest(
isPartitionedCollection,
isPartitionedLeaseCollection);
}

TestInitializeAsync().Wait();
}

public async Task TestInitializeAsync()
public async Task InitializeAsync()
{
if (this.ClassData.monitoredCollectionInfo == null)
try
{
try
{
if (this.ClassData.monitoredCollectionInfo == null)
{
this.ClassData.leaseCollectionInfoTemplate = await TestClassInitializeAsync(this, $"data_{this.GetType().Name}");
}
}
catch(Exception ex)
{
Debug.Write(ex);
throw;
}
await TestClassInitializeAsync(this, $"data_{this.GetType().Name}");
}
catch(Exception ex)
{
Debug.Write(ex);
throw;
}

Debug.Assert(this.ClassData.monitoredCollectionInfo != null, "Monitored collection information missing.");
Debug.Assert(this.ClassData.leaseCollectionInfoTemplate != null, "Lease collection information missing.");

this.LeaseCollectionInfo = new DocumentCollectionInfo(this.ClassData.leaseCollectionInfoTemplate);
this.LeaseCollectionInfo.CollectionName = $"leases_{this.GetType().Name}_{Guid.NewGuid().ToString()}";

Expand All @@ -179,24 +167,15 @@ public async Task TestInitializeAsync()
}
}

public void Dispose()
{
TestCleanupAsync().Wait();
}

public async Task TestCleanupAsync()
public async Task DisposeAsync()
{
Debug.Assert(this.LeaseCollectionInfo != null);
using (var client = new DocumentClient(this.LeaseCollectionInfo.Uri, this.LeaseCollectionInfo.MasterKey, this.LeaseCollectionInfo.ConnectionPolicy))
{
await client.DeleteDocumentCollectionAsync(UriFactory.CreateDocumentCollectionUri(this.LeaseCollectionInfo.DatabaseName, this.LeaseCollectionInfo.CollectionName));
}

var executedTestCount = Interlocked.Increment(ref this.ClassData.executedTestCount);
if (this.ClassData.executedTestCount == this.ClassData.testCount)
{
await TestClassCleanupAsync(this);
}
await TestClassCleanupAsync(this);
}

/// <summary>
Expand All @@ -214,15 +193,14 @@ protected virtual Task FinishTestClassInitializeAsync()
return Task.CompletedTask;
}

private static async Task<DocumentCollectionInfo> TestClassInitializeAsync(IntegrationTest test, string monitoredCollectionName)
private static async Task TestClassInitializeAsync(IntegrationTest test, string monitoredCollectionName)
{
Debug.Assert(test != null);
Debug.Assert(monitoredCollectionName != null);

DocumentCollectionInfo leaseCollectionInfo;
IntegrationTestsHelper.GetConfigurationSettings(
out test.ClassData.monitoredCollectionInfo,
out leaseCollectionInfo,
out test.ClassData.leaseCollectionInfoTemplate,
out monitoredOfferThroughput,
out leaseOfferThroughput);

Expand Down Expand Up @@ -250,9 +228,7 @@ private static async Task<DocumentCollectionInfo> TestClassInitializeAsync(Integ
await IntegrationTestsHelper.CreateDocumentCollectionAsync(client, test.ClassData.monitoredCollectionInfo.DatabaseName, monitoredCollection, monitoredOfferThroughput);
}

test.FinishTestClassInitializeAsync().Wait();

return leaseCollectionInfo;
await test.FinishTestClassInitializeAsync();
}

private static async Task TestClassCleanupAsync(IntegrationTest test)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using Microsoft.Azure.Documents.ChangeFeedProcessor.IntegrationTests.Utils;
using Microsoft.Azure.Documents.Client;
using Microsoft.Azure.Documents.Linq;
using Xunit;

namespace Microsoft.Azure.Documents.ChangeFeedProcessor.IntegrationTests
Expand Down Expand Up @@ -67,7 +68,7 @@ public async Task CountDocumentsInCollection_NormalCase()
try
{
Assert.True(partitionKeyRangeCount == openedCount, "Wrong openedCount");
Assert.True(documentCount == processedCount, "Wrong processedCount");
Assert.True(documentCount == processedCount, $"Wrong processedCount {documentCount} {processedCount}");
}
finally
{
Expand Down Expand Up @@ -164,7 +165,7 @@ public async Task CountDocumentsInCollection_TwoHosts()

try
{
Assert.True(documentCount == processedCount, "Wrong processedCount");
Assert.True(documentCount == processedCount, $"Wrong processedCount {documentCount} {processedCount}");
}
finally
{
Expand Down Expand Up @@ -214,6 +215,7 @@ protected override async Task FinishTestClassInitializeAsync()
using (var client = new DocumentClient(this.ClassData.monitoredCollectionInfo.Uri, this.ClassData.monitoredCollectionInfo.MasterKey, this.ClassData.monitoredCollectionInfo.ConnectionPolicy))
{
var collectionUri = UriFactory.CreateDocumentCollectionUri(this.ClassData.monitoredCollectionInfo.DatabaseName, this.ClassData.monitoredCollectionInfo.CollectionName);

await IntegrationTestsHelper.CreateDocumentsAsync(client, collectionUri, documentCount);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ namespace Microsoft.Azure.Documents.ChangeFeedProcessor.IntegrationTests.Utils
{
internal class IntegrationTestsHelper
{
// Used when tests are running in CI/CD pipeline
private const string GatewayEndpointEnvironmentName = "COSMOSDBEMULATOR_ENDPOINT";

static readonly string Endpoint;
static readonly string MasterKey;
static readonly string DatabaseId;
Expand All @@ -26,7 +29,7 @@ static IntegrationTestsHelper()
.AddJsonFile("appsettings.json")
.Build();

Endpoint = config["IntegrationTests:endpoint"];
Endpoint = Environment.GetEnvironmentVariable(GatewayEndpointEnvironmentName) ?? config["IntegrationTests:endpoint"];
MasterKey = config["IntegrationTests:masterKey"];
DatabaseId = config["IntegrationTests:databaseId"];
MonitoredOfferThroughput = config["IntegrationTests:monitoredOfferThroughput"];
Expand Down Expand Up @@ -77,7 +80,19 @@ internal static async Task CreateDocumentCollectionAsync(DocumentClient client,
var database = new Database { Id = databaseId };
database = await client.CreateDatabaseIfNotExistsAsync(database);

await client.CreateDocumentCollectionAsync(database.SelfLink, collection, new RequestOptions { OfferThroughput = offerThroughput });
int retryCount = 3;
while (retryCount-- > 0)
{
try
{
await client.CreateDocumentCollectionAsync(database.SelfLink, collection, new RequestOptions { OfferThroughput = offerThroughput });
break;
}
catch (DocumentClientException)
{
// Public emulator might have transient
}
}
}

internal static async Task CreateDocumentsAsync(DocumentClient client, Uri collectionUri, int count)
Expand Down