Skip to content

Commit cd61a24

Browse files
authored
(#187) Serialize tests for better reliability (#190)
1 parent 68fb075 commit cd61a24

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

tests/CommunityToolkit.Datasync.Server.EntityFrameworkCore.Test/AzureSqlEntityTableRepository_Tests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@
1010
namespace CommunityToolkit.Datasync.Server.EntityFrameworkCore.Test;
1111

1212
[ExcludeFromCodeCoverage]
13+
[Collection("LiveTestsCollection")]
1314
public class AzureSqlEntityTableRepository_Tests : RepositoryTests<AzureSqlEntityMovie>
1415
{
1516
#region Setup
17+
private readonly DatabaseFixture _fixture;
1618
private readonly Random random = new();
1719
private readonly string connectionString;
1820
private readonly List<AzureSqlEntityMovie> movies;
1921
private readonly Lazy<AzureSqlDbContext> _context;
2022

21-
public AzureSqlEntityTableRepository_Tests(ITestOutputHelper output) : base()
23+
public AzureSqlEntityTableRepository_Tests(DatabaseFixture fixture, ITestOutputHelper output) : base()
2224
{
25+
this._fixture = fixture;
2326
this.connectionString = Environment.GetEnvironmentVariable("DATASYNC_AZSQL_CONNECTIONSTRING");
2427
if (!string.IsNullOrEmpty(this.connectionString))
2528
{

tests/CommunityToolkit.Datasync.Server.EntityFrameworkCore.Test/CosmosEntityTableRepository_Tests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@
1010
namespace CommunityToolkit.Datasync.Server.EntityFrameworkCore.Test;
1111

1212
[ExcludeFromCodeCoverage]
13+
[Collection("LiveTestsCollection")]
1314
public class CosmosEntityTableRepository_Tests : RepositoryTests<CosmosEntityMovie>
1415
{
1516
#region Setup
17+
private readonly DatabaseFixture _fixture;
1618
private readonly Random random = new();
1719
private readonly string connectionString;
1820
private readonly List<CosmosEntityMovie> movies;
1921
private readonly Lazy<CosmosDbContext> _context;
2022

21-
public CosmosEntityTableRepository_Tests(ITestOutputHelper output) : base()
23+
public CosmosEntityTableRepository_Tests(DatabaseFixture fixture, ITestOutputHelper output) : base()
2224
{
25+
this._fixture = fixture;
2326
this.connectionString = Environment.GetEnvironmentVariable("DATASYNC_COSMOS_CONNECTIONSTRING");
2427
if (!string.IsNullOrEmpty(this.connectionString))
2528
{
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace CommunityToolkit.Datasync.Server.EntityFrameworkCore.Test;
6+
7+
/// <summary>
8+
/// This can be used to share state between the various live tests. It isn't used right now.
9+
/// </summary>
10+
public class DatabaseFixture
11+
{
12+
13+
}
14+
15+
[CollectionDefinition("LiveTestsCollection", DisableParallelization = true)]
16+
public class LiveTestsCollection : ICollectionFixture<DatabaseFixture>
17+
{
18+
// This class has no code, and is never created. Its purpose is simply
19+
// to be the place to apply [CollectionDefinition] and all the
20+
// ICollectionFixture<> interfaces.
21+
}

tests/CommunityToolkit.Datasync.Server.EntityFrameworkCore.Test/PgEntityTableRepository_Tests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@
1010
namespace CommunityToolkit.Datasync.Server.EntityFrameworkCore.Test;
1111

1212
[ExcludeFromCodeCoverage]
13+
[Collection("LiveTestsCollection")]
1314
public class PgEntityTableRepository_Tests : RepositoryTests<PgEntityMovie>
1415
{
1516
#region Setup
17+
private readonly DatabaseFixture _fixture;
1618
private readonly Random random = new();
1719
private readonly string connectionString;
1820
private readonly List<PgEntityMovie> movies;
1921
private readonly Lazy<PgDbContext> _context;
2022

21-
public PgEntityTableRepository_Tests(ITestOutputHelper output) : base()
23+
public PgEntityTableRepository_Tests(DatabaseFixture fixture, ITestOutputHelper output) : base()
2224
{
25+
this._fixture = fixture;
2326
this.connectionString = Environment.GetEnvironmentVariable("DATASYNC_PGSQL_CONNECTIONSTRING");
2427
if (!string.IsNullOrEmpty(this.connectionString))
2528
{

0 commit comments

Comments
 (0)