Skip to content

Commit 9b4efa2

Browse files
authored
CI/CD Adding automatic pipeline tests (#153)
* Support for pipelines endpoint * pipelines * Adding assert * Adding lock * Refactor initialization * Cleanup * yaml update * Using async initialize * Cleanup * throwing if retries consumed * Removing TestClassData * Renames
1 parent 81c53de commit 9b4efa2

File tree

9 files changed

+185
-204
lines changed

9 files changed

+185
-204
lines changed

pipeline/azure-pipelines-emulator.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
trigger: none
2+
pr:
3+
branches:
4+
include:
5+
- master
6+
- releases/*
7+
8+
pool:
9+
vmImage: 'windows-latest'
10+
11+
steps:
12+
- pwsh: |
13+
Write-Host "Downloading Cosmos Emulator - $env:EMULATORMSIURL" -ForegroundColor green
14+
Invoke-WebRequest "$env:EMULATORMSIURL" -OutFile "$env:temp\azure-cosmosdb-emulator.msi"
15+
Write-Host "Finished Downloading Cosmos Emulator - $env:temp\azure-cosmosdb-emulator.msi" -ForegroundColor green
16+
dir "$env:temp"
17+
choco install lessmsi
18+
choco upgrade lessmsi
19+
mkdir "$env:temp\Azure Cosmos DB Emulator"
20+
lessmsi x "$env:temp\azure-cosmosdb-emulator.msi" "$env:temp\Azure Cosmos DB Emulator\"
21+
Write-Host "Starting Cosmos DB Emulator" -ForegroundColor green
22+
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
23+
Import-Module "$env:temp\Azure Cosmos DB Emulator\SourceDir\Azure Cosmos DB Emulator\PSModules\Microsoft.Azure.CosmosDB.Emulator"
24+
Get-Item env:* | Sort-Object -Property Name
25+
for ($i=0; $i -lt 10; $i++) {
26+
$status=Get-CosmosDbEmulatorStatus
27+
if ($status -ne "Running") {
28+
sleep 30;
29+
Write-Host "Cosmos DB Emulator Status: $status" -ForegroundColor yellow
30+
} else {
31+
break;
32+
}
33+
}
34+
- task: DotNetCoreCLI@2
35+
displayName: Build
36+
inputs:
37+
command: build
38+
projects: '**/*.csproj'
39+
- script: dotnet test ./src/DocumentDB.ChangeFeedProcessor.IntegrationTests/DocumentDB.ChangeFeedProcessor.IntegrationTests.csproj --logger trx
40+
displayName: 'Running tests'
41+
- task: PublishTestResults@2
42+
condition: succeededOrFailed()
43+
inputs:
44+
testRunner: VSTest
45+
testResultsFiles: '**/*.trx'

pipeline/azure-pipelines.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
trigger: none
2+
pr:
3+
branches:
4+
include:
5+
- master
6+
- releases/*
7+
8+
strategy:
9+
matrix:
10+
windows:
11+
imageName: 'windows-latest'
12+
13+
pool:
14+
vmImage: $(imageName)
15+
16+
steps:
17+
- task: DotNetCoreCLI@2
18+
displayName: Build
19+
inputs:
20+
command: build
21+
projects: '**/*.csproj'
22+
arguments: '--configuration Release'
23+
- script: dotnet test ./src/DocumentDB.ChangeFeedProcessor.UnitTests/DocumentDB.ChangeFeedProcessor.UnitTests.csproj --logger trx
24+
displayName: 'Running tests'
25+
- task: PublishTestResults@2
26+
condition: succeededOrFailed()
27+
inputs:
28+
testRunner: VSTest
29+
testResultsFiles: '**/*.trx'

src/DocumentDB.ChangeFeedProcessor.IntegrationTests/DynamicCollectionTests.cs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,10 @@ public class DynamicCollectionTests : IntegrationTest
2525
{
2626
const int documentCount = 513;
2727

28-
public DynamicCollectionTests(IntegrationTestFixture fixture) : base(fixture, typeof(DynamicCollectionTests))
29-
{
30-
}
31-
3228
[Fact]
3329
public async Task CountAddedDocuments()
3430
{
35-
int partitionCount = await IntegrationTestsHelper.GetPartitionCount(this.ClassData.monitoredCollectionInfo);
31+
int partitionCount = await IntegrationTestsHelper.GetPartitionCount(this.MonitoredCollectionInfo);
3632
int openedCount = 0, processedCount = 0;
3733
var allObserversStarted = new ManualResetEvent(false);
3834
var allDocsProcessed = new ManualResetEvent(false);
@@ -54,7 +50,7 @@ public async Task CountAddedDocuments()
5450

5551
var host = new ChangeFeedEventHost(
5652
Guid.NewGuid().ToString(),
57-
this.ClassData.monitoredCollectionInfo,
53+
this.MonitoredCollectionInfo,
5854
this.LeaseCollectionInfo,
5955
new ChangeFeedOptions { StartFromBeginning = false },
6056
new ChangeFeedHostOptions());
@@ -63,11 +59,11 @@ public async Task CountAddedDocuments()
6359
var isStartOk = allObserversStarted.WaitOne(IntegrationTest.changeWaitTimeout + IntegrationTest.changeWaitTimeout);
6460
Assert.True(isStartOk, "Timed out waiting for observres to start");
6561

66-
using (var client = new DocumentClient(this.ClassData.monitoredCollectionInfo.Uri, this.ClassData.monitoredCollectionInfo.MasterKey, this.ClassData.monitoredCollectionInfo.ConnectionPolicy))
62+
using (var client = new DocumentClient(this.MonitoredCollectionInfo.Uri, this.MonitoredCollectionInfo.MasterKey, this.MonitoredCollectionInfo.ConnectionPolicy))
6763
{
6864
await IntegrationTestsHelper.CreateDocumentsAsync(
6965
client,
70-
UriFactory.CreateDocumentCollectionUri(this.ClassData.monitoredCollectionInfo.DatabaseName, this.ClassData.monitoredCollectionInfo.CollectionName),
66+
UriFactory.CreateDocumentCollectionUri(this.MonitoredCollectionInfo.DatabaseName, this.MonitoredCollectionInfo.CollectionName),
7167
documentCount);
7268
}
7369

@@ -86,8 +82,8 @@ await IntegrationTestsHelper.CreateDocumentsAsync(
8682
[Fact]
8783
public async Task TestStartTime()
8884
{
89-
var collectionUri = UriFactory.CreateDocumentCollectionUri(this.ClassData.monitoredCollectionInfo.DatabaseName, this.ClassData.monitoredCollectionInfo.CollectionName);
90-
using (var client = new DocumentClient(this.ClassData.monitoredCollectionInfo.Uri, this.ClassData.monitoredCollectionInfo.MasterKey, this.ClassData.monitoredCollectionInfo.ConnectionPolicy))
85+
var collectionUri = UriFactory.CreateDocumentCollectionUri(this.MonitoredCollectionInfo.DatabaseName, this.MonitoredCollectionInfo.CollectionName);
86+
using (var client = new DocumentClient(this.MonitoredCollectionInfo.Uri, this.MonitoredCollectionInfo.MasterKey, this.MonitoredCollectionInfo.ConnectionPolicy))
9187
{
9288
await client.CreateDocumentAsync(collectionUri, JsonConvert.DeserializeObject("{\"id\": \"doc1\"}"));
9389

@@ -99,7 +95,7 @@ public async Task TestStartTime()
9995

10096
await client.CreateDocumentAsync(collectionUri, JsonConvert.DeserializeObject("{\"id\": \"doc2\"}"));
10197

102-
int partitionCount = await IntegrationTestsHelper.GetPartitionCount(this.ClassData.monitoredCollectionInfo);
98+
int partitionCount = await IntegrationTestsHelper.GetPartitionCount(this.MonitoredCollectionInfo);
10399
var allDocsProcessed = new ManualResetEvent(false);
104100

105101
var processedDocs = new List<Document>();
@@ -118,7 +114,7 @@ public async Task TestStartTime()
118114

119115
var host = new ChangeFeedEventHost(
120116
Guid.NewGuid().ToString(),
121-
this.ClassData.monitoredCollectionInfo,
117+
this.MonitoredCollectionInfo,
122118
this.LeaseCollectionInfo,
123119
new ChangeFeedOptions { StartTime = timeInBeweeen },
124120
new ChangeFeedHostOptions());
@@ -143,15 +139,15 @@ public async Task TestStartTime()
143139
public async Task TestReducePageSizeScenario()
144140
{
145141
// Use different colleciton: we need 1-partition collection to make sure all docs get to same partition.
146-
var databaseUri = UriFactory.CreateDatabaseUri(this.ClassData.monitoredCollectionInfo.DatabaseName);
142+
var databaseUri = UriFactory.CreateDatabaseUri(this.MonitoredCollectionInfo.DatabaseName);
147143

148-
DocumentCollectionInfo monitoredCollectionInfo = new DocumentCollectionInfo(this.ClassData.monitoredCollectionInfo);
149-
monitoredCollectionInfo.CollectionName = this.ClassData.monitoredCollectionInfo.CollectionName + "_" + Guid.NewGuid().ToString();
144+
DocumentCollectionInfo monitoredCollectionInfo = new DocumentCollectionInfo(this.MonitoredCollectionInfo);
145+
monitoredCollectionInfo.CollectionName = this.MonitoredCollectionInfo.CollectionName + "_" + Guid.NewGuid().ToString();
150146

151-
var collectionUri = UriFactory.CreateDocumentCollectionUri(this.ClassData.monitoredCollectionInfo.DatabaseName, monitoredCollectionInfo.CollectionName);
147+
var collectionUri = UriFactory.CreateDocumentCollectionUri(this.MonitoredCollectionInfo.DatabaseName, monitoredCollectionInfo.CollectionName);
152148
var monitoredCollection = new DocumentCollection { Id = monitoredCollectionInfo.CollectionName };
153149

154-
using (var client = new DocumentClient(this.ClassData.monitoredCollectionInfo.Uri, this.ClassData.monitoredCollectionInfo.MasterKey, this.ClassData.monitoredCollectionInfo.ConnectionPolicy))
150+
using (var client = new DocumentClient(this.MonitoredCollectionInfo.Uri, this.MonitoredCollectionInfo.MasterKey, this.MonitoredCollectionInfo.ConnectionPolicy))
155151
{
156152
await client.CreateDocumentCollectionAsync(databaseUri, monitoredCollection, new RequestOptions { OfferThroughput = 10000 });
157153

@@ -169,7 +165,7 @@ public async Task TestReducePageSizeScenario()
169165
);}"
170166
};
171167

172-
var sprocUri = UriFactory.CreateStoredProcedureUri(this.ClassData.monitoredCollectionInfo.DatabaseName, monitoredCollection.Id, sproc.Id);
168+
var sprocUri = UriFactory.CreateStoredProcedureUri(this.MonitoredCollectionInfo.DatabaseName, monitoredCollection.Id, sproc.Id);
173169
await client.CreateStoredProcedureAsync(collectionUri, sproc);
174170
await client.ExecuteStoredProcedureAsync<object>(sprocUri, 0);
175171

src/DocumentDB.ChangeFeedProcessor.IntegrationTests/EstimatorTests.cs

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,15 @@ namespace Microsoft.Azure.Documents.ChangeFeedProcessor.IntegrationTests
1818
[Collection("Integration tests")]
1919
public class EstimatorTests : IntegrationTest
2020
{
21-
public EstimatorTests(IntegrationTestFixture fixture) : base(fixture, typeof(EstimatorTests), false)
21+
public EstimatorTests() : base(false)
2222
{
2323
}
2424

2525
[Fact]
2626
public async Task CountPendingDocuments()
2727
{
28-
// Cleanup the test collection to avoid other tests' documents causing issues with StartFromBeginning
29-
await this.ResetTestCollection();
3028
int documentCount = 1;
31-
int partitionCount = await IntegrationTestsHelper.GetPartitionCount(this.ClassData.monitoredCollectionInfo);
29+
int partitionCount = await IntegrationTestsHelper.GetPartitionCount(this.MonitoredCollectionInfo);
3230
int openedCount = 0, processedCount = 0;
3331
var allObserversStarted = new ManualResetEvent(false);
3432
var allDocsProcessed = new ManualResetEvent(false);
@@ -52,7 +50,7 @@ public async Task CountPendingDocuments()
5250

5351
var host = new ChangeFeedEventHost(
5452
hostName,
55-
this.ClassData.monitoredCollectionInfo,
53+
this.MonitoredCollectionInfo,
5654
this.LeaseCollectionInfo,
5755
new ChangeFeedOptions { StartFromBeginning = false },
5856
new ChangeFeedHostOptions());
@@ -64,11 +62,11 @@ public async Task CountPendingDocuments()
6462
long estimation = await host.GetEstimatedRemainingWork();
6563
Assert.Equal(0, estimation);
6664

67-
using (var client = new DocumentClient(this.ClassData.monitoredCollectionInfo.Uri, this.ClassData.monitoredCollectionInfo.MasterKey, this.ClassData.monitoredCollectionInfo.ConnectionPolicy))
65+
using (var client = new DocumentClient(this.MonitoredCollectionInfo.Uri, this.MonitoredCollectionInfo.MasterKey, this.MonitoredCollectionInfo.ConnectionPolicy))
6866
{
6967
await IntegrationTestsHelper.CreateDocumentsAsync(
7068
client,
71-
UriFactory.CreateDocumentCollectionUri(this.ClassData.monitoredCollectionInfo.DatabaseName, this.ClassData.monitoredCollectionInfo.CollectionName),
69+
UriFactory.CreateDocumentCollectionUri(this.MonitoredCollectionInfo.DatabaseName, this.MonitoredCollectionInfo.CollectionName),
7270
1);
7371

7472
var isStartOk = allObserversStarted.WaitOne(IntegrationTest.changeWaitTimeout + IntegrationTest.changeWaitTimeout);
@@ -84,15 +82,15 @@ await IntegrationTestsHelper.CreateDocumentsAsync(
8482

8583
await IntegrationTestsHelper.CreateDocumentsAsync(
8684
client,
87-
UriFactory.CreateDocumentCollectionUri(this.ClassData.monitoredCollectionInfo.DatabaseName, this.ClassData.monitoredCollectionInfo.CollectionName),
85+
UriFactory.CreateDocumentCollectionUri(this.MonitoredCollectionInfo.DatabaseName, this.MonitoredCollectionInfo.CollectionName),
8886
1);
8987

9088
estimation = await host.GetEstimatedRemainingWork();
9189
Assert.Equal(1, estimation);
9290

9391
await IntegrationTestsHelper.CreateDocumentsAsync(
9492
client,
95-
UriFactory.CreateDocumentCollectionUri(this.ClassData.monitoredCollectionInfo.DatabaseName, this.ClassData.monitoredCollectionInfo.CollectionName),
93+
UriFactory.CreateDocumentCollectionUri(this.MonitoredCollectionInfo.DatabaseName, this.MonitoredCollectionInfo.CollectionName),
9694
10);
9795

9896
estimation = await host.GetEstimatedRemainingWork();
@@ -101,7 +99,7 @@ await IntegrationTestsHelper.CreateDocumentsAsync(
10199
// Create a new host to process pending changes
102100
var newHost = new ChangeFeedEventHost(
103101
hostName,
104-
this.ClassData.monitoredCollectionInfo,
102+
this.MonitoredCollectionInfo,
105103
this.LeaseCollectionInfo,
106104
new ChangeFeedOptions { StartFromBeginning = false },
107105
new ChangeFeedHostOptions());
@@ -132,13 +130,11 @@ await IntegrationTestsHelper.CreateDocumentsAsync(
132130
[Fact]
133131
public async Task WhenNoLeasesExistReturn1()
134132
{
135-
// Cleanup the test collection to avoid other tests' documents causing issues with StartFromBeginning
136-
await this.ResetTestCollection();
137133
var hostName = Guid.NewGuid().ToString();
138134

139135
var host = new ChangeFeedEventHost(
140136
hostName,
141-
this.ClassData.monitoredCollectionInfo,
137+
this.MonitoredCollectionInfo,
142138
this.LeaseCollectionInfo,
143139
new ChangeFeedOptions { StartFromBeginning = false },
144140
new ChangeFeedHostOptions());
@@ -155,10 +151,8 @@ public async Task WhenNoLeasesExistReturn1()
155151
[Fact]
156152
public async Task WhenLeasesHaveContinuationTokenNullReturn0()
157153
{
158-
// Cleanup the test collection to avoid other tests' documents causing issues with StartFromBeginning
159-
await this.ResetTestCollection();
160154
int documentCount = 1;
161-
int partitionCount = await IntegrationTestsHelper.GetPartitionCount(this.ClassData.monitoredCollectionInfo);
155+
int partitionCount = await IntegrationTestsHelper.GetPartitionCount(this.MonitoredCollectionInfo);
162156
int openedCount = 0, processedCount = 0;
163157
var allObserversStarted = new ManualResetEvent(false);
164158
var allDocsProcessed = new ManualResetEvent(false);
@@ -183,7 +177,7 @@ public async Task WhenLeasesHaveContinuationTokenNullReturn0()
183177
// We create a host to initialize the leases with ContinuationToken null
184178
var host = new ChangeFeedEventHost(
185179
hostName,
186-
this.ClassData.monitoredCollectionInfo,
180+
this.MonitoredCollectionInfo,
187181
this.LeaseCollectionInfo,
188182
new ChangeFeedOptions { StartFromBeginning = false },
189183
new ChangeFeedHostOptions());
@@ -205,10 +199,8 @@ public async Task WhenLeasesHaveContinuationTokenNullReturn0()
205199
[Fact]
206200
public async Task WhenLeasesHaveContinuationTokenNullStartFromBeginning()
207201
{
208-
// Cleanup the test collection to avoid other tests' documents causing issues with StartFromBeginning
209-
await this.ResetTestCollection();
210202
int documentCount = 1;
211-
int partitionCount = await IntegrationTestsHelper.GetPartitionCount(this.ClassData.monitoredCollectionInfo);
203+
int partitionCount = await IntegrationTestsHelper.GetPartitionCount(this.MonitoredCollectionInfo);
212204
int openedCount = 0, processedCount = 0;
213205
var allObserversStarted = new ManualResetEvent(false);
214206
var allDocsProcessed = new ManualResetEvent(false);
@@ -233,7 +225,7 @@ public async Task WhenLeasesHaveContinuationTokenNullStartFromBeginning()
233225
// We create a host to initialize the leases with ContinuationToken null
234226
var host = new ChangeFeedEventHost(
235227
hostName,
236-
this.ClassData.monitoredCollectionInfo,
228+
this.MonitoredCollectionInfo,
237229
this.LeaseCollectionInfo,
238230
new ChangeFeedOptions { StartFromBeginning = false },
239231
new ChangeFeedHostOptions());
@@ -244,14 +236,14 @@ public async Task WhenLeasesHaveContinuationTokenNullStartFromBeginning()
244236
await host.UnregisterObserversAsync();
245237

246238
using (var client = new DocumentClient(
247-
this.ClassData.monitoredCollectionInfo.Uri,
248-
this.ClassData.monitoredCollectionInfo.MasterKey,
249-
this.ClassData.monitoredCollectionInfo.ConnectionPolicy))
239+
this.MonitoredCollectionInfo.Uri,
240+
this.MonitoredCollectionInfo.MasterKey,
241+
this.MonitoredCollectionInfo.ConnectionPolicy))
250242
{
251243
// Insert documents
252244
await IntegrationTestsHelper.CreateDocumentsAsync(
253245
client,
254-
UriFactory.CreateDocumentCollectionUri(this.ClassData.monitoredCollectionInfo.DatabaseName, this.ClassData.monitoredCollectionInfo.CollectionName),
246+
UriFactory.CreateDocumentCollectionUri(this.MonitoredCollectionInfo.DatabaseName, this.MonitoredCollectionInfo.CollectionName),
255247
10);
256248

257249
// Since the leases have ContinuationToken null state, the estimator will use StartFromBeginning and pick-up the changes that happened from the start

0 commit comments

Comments
 (0)