Skip to content

Commit

Permalink
Run Cosmos tests for pull requests
Browse files Browse the repository at this point in the history
Fix deadlock in Cosmos Test cleanup
  • Loading branch information
AndriySvyryd committed Jul 3, 2019
1 parent d1843cd commit 70d7913
Show file tree
Hide file tree
Showing 23 changed files with 314 additions and 181 deletions.
11 changes: 6 additions & 5 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ variables:
- name: _DotNetArtifactsCategory
value: ENTITYFRAMEWORKCORE
- name: _CosmosConnectionUrl
value: 'https://ef-nightly-test.documents.azure.com:443/'
value: https://ef-nightly-test.documents.azure.com:443/

trigger:
- master
Expand Down Expand Up @@ -78,6 +78,7 @@ jobs:
DEALLOCATE db;
'@
displayName: Cleanup databases
- powershell: gci env:
- script: eng\common\cibuild.cmd -configuration $(_BuildConfig) -prepareMachine $(_InternalBuildArgs)
env:
Test__Cosmos__Sql__DefaultConnection: $(_CosmosConnectionUrl)
Expand All @@ -94,28 +95,28 @@ jobs:
- job: macOS
pool:
vmImage: macOS-10.13
variables:
- ${{ if and(eq(variables['System.TeamProject'], 'public'), eq(variables['system.pullrequest.isfork'], false), notin(variables['Build.Reason'], 'IndividualCI', 'BatchedCI', 'PullRequest')) }}:
- _CosmosToken: $(ef-nightly-cosmos-key)
steps:
- bash: brew install libspatialite
displayName: Install SpatiaLite
continueOnError: true
- script: eng/common/cibuild.sh --configuration $(_BuildConfig) --binaryLog --prepareMachine
env:
Test__Cosmos__Sql__DefaultConnection: $(_CosmosConnectionUrl)
Test__Cosmos__Sql__AuthToken: $(_CosmosToken)
name: Build
continueOnError: true

- job: Linux
pool:
vmImage: ubuntu-16.04
variables:
- ${{ if and(eq(variables['System.TeamProject'], 'public'), eq(variables['system.pullrequest.isfork'], false), notin(variables['Build.Reason'], 'IndividualCI', 'BatchedCI')) }}:
- _CosmosToken: $(ef-nightly-cosmos-key)
steps:
- bash: sudo apt-get install -y libsqlite3-mod-spatialite
displayName: Install SpatiaLite
continueOnError: true
- script: eng/common/cibuild.sh --configuration $(_BuildConfig) --prepareMachine
env:
Test__Cosmos__Sql__DefaultConnection: $(_CosmosConnectionUrl)
Test__Cosmos__Sql__AuthToken: $(_CosmosToken)
name: Build
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static PropertyBuilder ForCosmosToProperty(
[NotNull] string name)
{
Check.NotNull(propertyBuilder, nameof(propertyBuilder));
Check.NotEmpty(name, nameof(name));
Check.NotNull(name, nameof(name));

propertyBuilder.Metadata.SetCosmosPropertyName(name);

Expand Down
26 changes: 18 additions & 8 deletions test/EFCore.Cosmos.FunctionalTests/ConfigPatternsCosmosTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos;
using Microsoft.EntityFrameworkCore.Cosmos.TestUtilities;
using Microsoft.EntityFrameworkCore.TestUtilities;
Expand All @@ -19,10 +20,12 @@ public ConfigPatternsCosmosTest(CosmosFixture fixture)
}

[ConditionalFact]
public void Cosmos_client_instance_is_shared_between_contexts()
public async Task Cosmos_client_instance_is_shared_between_contexts()
{
CosmosClient client;
using (var testDatabase = CosmosTestStore.CreateInitialized(DatabaseName))
var testDatabase = CosmosTestStore.CreateInitialized(DatabaseName);
var testDatabase2 = CosmosTestStore.CreateInitialized(DatabaseName, o => o.Region(CosmosRegions.AustraliaCentral));
try
{
var options = CreateOptions(testDatabase);

Expand All @@ -37,25 +40,28 @@ public void Cosmos_client_instance_is_shared_between_contexts()
{
Assert.Same(client, context.Database.GetCosmosClient());
}
}

using (var testDatabase = CosmosTestStore.CreateInitialized(DatabaseName, o => o.Region(CosmosRegions.AustraliaCentral)))
{
var options = CreateOptions(testDatabase);
options = CreateOptions(testDatabase2);

using (var context = new CustomerContext(options))
{
Assert.NotSame(client, context.Database.GetCosmosClient());
}
}
finally
{
await testDatabase2?.DisposeAsync();
await testDatabase.DisposeAsync();
}
}

[ConditionalFact]
public void Should_not_throw_if_specified_region_is_right()
public async Task Should_not_throw_if_specified_region_is_right()
{
var regionName = CosmosRegions.AustraliaCentral;

using (var testDatabase = CosmosTestStore.CreateInitialized(DatabaseName, o => o.Region(regionName)))
var testDatabase = CosmosTestStore.CreateInitialized(DatabaseName, o => o.Region(regionName));
try
{
var options = CreateOptions(testDatabase);

Expand All @@ -70,6 +76,10 @@ public void Should_not_throw_if_specified_region_is_right()
context.SaveChanges();
}
}
finally
{
await testDatabase.DisposeAsync();
}
}

[ConditionalFact]
Expand Down
64 changes: 52 additions & 12 deletions test/EFCore.Cosmos.FunctionalTests/EndToEndCosmosTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ public EndToEndCosmosTest(CosmosFixture fixture)
}

[ConditionalFact(Skip = "Issue#16146")]
public void Can_add_update_delete_end_to_end()
public async Task Can_add_update_delete_end_to_end()
{
using (var testDatabase = CosmosTestStore.CreateInitialized(DatabaseName))
var testDatabase = CosmosTestStore.CreateInitialized(DatabaseName);
try
{
var options = Fixture.CreateOptions(testDatabase);

Expand Down Expand Up @@ -70,12 +71,17 @@ public void Can_add_update_delete_end_to_end()
Assert.Equal(0, context.Set<Customer>().Count());
}
}
finally
{
await testDatabase.DisposeAsync();
}
}

[ConditionalFact(Skip = "Issue#16146")]
public async Task Can_add_update_delete_end_to_end_async()
{
using (var testDatabase = CosmosTestStore.CreateInitialized(DatabaseName))
var testDatabase = CosmosTestStore.CreateInitialized(DatabaseName);
try
{
var options = Fixture.CreateOptions(testDatabase);

Expand Down Expand Up @@ -119,6 +125,10 @@ public async Task Can_add_update_delete_end_to_end_async()
Assert.Equal(0, await context.Set<Customer>().CountAsync());
}
}
finally
{
await testDatabase.DisposeAsync();
}
}

private class Customer
Expand All @@ -144,7 +154,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
[ConditionalFact(Skip = "Issue #16146")]
public async Task Can_add_update_delete_detached_entity_end_to_end_async()
{
using (var testDatabase = CosmosTestStore.CreateInitialized(DatabaseName))
var testDatabase = CosmosTestStore.CreateInitialized(DatabaseName);
try
{
var options = Fixture.CreateOptions(testDatabase);

Expand Down Expand Up @@ -208,12 +219,17 @@ public async Task Can_add_update_delete_detached_entity_end_to_end_async()
Assert.Equal(0, context.Set<Customer>().Count());
}
}
finally
{
await testDatabase.DisposeAsync();
}
}

[ConditionalFact(Skip = "Issue#16146")]
public void Can_add_update_delete_end_to_end_with_partition_key()
public async Task Can_add_update_delete_end_to_end_with_partition_key()
{
using (var testDatabase = CosmosTestStore.CreateInitialized(DatabaseName))
var testDatabase = CosmosTestStore.CreateInitialized(DatabaseName);
try
{
var options = Fixture.CreateOptions(testDatabase);

Expand Down Expand Up @@ -259,6 +275,10 @@ public void Can_add_update_delete_end_to_end_with_partition_key()
Assert.Equal(0, context.Set<Customer>().Count());
}
}
finally
{
await testDatabase.DisposeAsync();
}
}

private class PartitionKeyContext : DbContext
Expand All @@ -275,9 +295,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
}

[ConditionalFact]
public void Can_update_unmapped_properties()
public async Task Can_update_unmapped_properties()
{
using (var testDatabase = CosmosTestStore.CreateInitialized(DatabaseName))
var testDatabase = CosmosTestStore.CreateInitialized(DatabaseName);
try
{
var options = Fixture.CreateOptions(testDatabase);

Expand Down Expand Up @@ -323,6 +344,10 @@ public void Can_update_unmapped_properties()
context.SaveChanges();
}
}
finally
{
await testDatabase.DisposeAsync();
}
}

private class ExtraCustomerContext : CustomerContext
Expand All @@ -340,9 +365,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
}

[ConditionalFact(Skip = "Issue#16146")]
public void Can_use_non_persisted_properties()
public async Task Can_use_non_persisted_properties()
{
using (var testDatabase = CosmosTestStore.CreateInitialized(DatabaseName))
var testDatabase = CosmosTestStore.CreateInitialized(DatabaseName);
try
{
var options = Fixture.CreateOptions(testDatabase);

Expand Down Expand Up @@ -370,6 +396,10 @@ public void Can_use_non_persisted_properties()
Assert.Equal(0, context.SaveChanges());
}
}
finally
{
await testDatabase.DisposeAsync();
}
}

private class UnmappedCustomerContext : CustomerContext
Expand All @@ -388,7 +418,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
[ConditionalFact]
public async Task Using_a_conflicting_incompatible_id_throws()
{
using (var testDatabase = CosmosTestStore.CreateInitialized(DatabaseName))
var testDatabase = CosmosTestStore.CreateInitialized(DatabaseName);
try
{
var options = Fixture.CreateOptions(testDatabase);

Expand All @@ -405,6 +436,10 @@ await Assert.ThrowsAnyAsync<Exception>(
});
}
}
finally
{
await testDatabase.DisposeAsync();
}
}

private class ConflictingIncompatibleId
Expand All @@ -430,7 +465,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
[ConditionalFact(Skip = "Issue #16146")]
public async Task Can_add_update_delete_end_to_end_with_conflicting_id()
{
using (var testDatabase = CosmosTestStore.CreateInitialized(DatabaseName))
var testDatabase = CosmosTestStore.CreateInitialized(DatabaseName);
try
{
var options = Fixture.CreateOptions(testDatabase);

Expand Down Expand Up @@ -482,6 +518,10 @@ public async Task Can_add_update_delete_end_to_end_with_conflicting_id()
Assert.Equal(0, context.Set<ConflictingId>().Count());
}
}
finally
{
await testDatabase.DisposeAsync();
}
}

private class ConflictingId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Microsoft.EntityFrameworkCore.Cosmos.TestUtilities;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.TestUtilities.Xunit;
using Xunit;

namespace Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal
Expand All @@ -17,7 +16,8 @@ public class CosmosDatabaseCreatorTest
[InlineData(false)]
public async Task EnsureCreated_returns_true_when_database_does_not_exist(bool async)
{
using (var testDatabase = CosmosTestStore.Create("NonExisting"))
var testDatabase = CosmosTestStore.Create("NonExisting");
try
{
using (var context = new BloggingContext(testDatabase))
{
Expand All @@ -26,6 +26,10 @@ public async Task EnsureCreated_returns_true_when_database_does_not_exist(bool a
Assert.True(async ? await creator.EnsureCreatedAsync() : creator.EnsureCreated());
}
}
finally
{
await testDatabase.DisposeAsync();
}
}

[ConditionalTheory]
Expand All @@ -49,7 +53,8 @@ public async Task EnsureCreated_returns_true_when_database_exists_but_collection
[InlineData(false)]
public async Task EnsureCreated_returns_false_when_database_and_collections_exists(bool async)
{
using (var testDatabase = CosmosTestStore.Create("EnsureCreatedReady"))
var testDatabase = CosmosTestStore.Create("EnsureCreatedReady");
try
{
testDatabase.Initialize(null, () => new BloggingContext(testDatabase), null);

Expand All @@ -60,14 +65,19 @@ public async Task EnsureCreated_returns_false_when_database_and_collections_exis
Assert.False(async ? await creator.EnsureCreatedAsync() : creator.EnsureCreated());
}
}
finally
{
await testDatabase.DisposeAsync();
}
}

[ConditionalTheory]
[InlineData(true)]
[InlineData(false)]
public async Task EnsureDeleted_returns_true_when_database_exists(bool async)
{
using (var testDatabase = CosmosTestStore.CreateInitialized("EnsureDeleteBlogging"))
var testDatabase = CosmosTestStore.CreateInitialized("EnsureDeleteBlogging");
try
{
using (var context = new BloggingContext(testDatabase))
{
Expand All @@ -76,14 +86,19 @@ public async Task EnsureDeleted_returns_true_when_database_exists(bool async)
Assert.True(async ? await creator.EnsureDeletedAsync() : creator.EnsureDeleted());
}
}
finally
{
await testDatabase.DisposeAsync();
}
}

[ConditionalTheory]
[InlineData(true)]
[InlineData(false)]
public async Task EnsureDeleted_returns_false_when_database_does_not_exist(bool async)
{
using (var testDatabase = CosmosTestStore.Create("EnsureDeleteBlogging"))
var testDatabase = CosmosTestStore.Create("EnsureDeleteBlogging");
try
{
using (var context = new BloggingContext(testDatabase))
{
Expand All @@ -92,6 +107,10 @@ public async Task EnsureDeleted_returns_false_when_database_does_not_exist(bool
Assert.False(async ? await creator.EnsureDeletedAsync() : creator.EnsureDeleted());
}
}
finally
{
await testDatabase.DisposeAsync();
}
}

public class BloggingContext : DbContext
Expand Down
Loading

0 comments on commit 70d7913

Please sign in to comment.