Skip to content

Commit a3ce112

Browse files
Add retry to cosmos tests
1 parent 4530284 commit a3ce112

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

EntityInjector.Samples.CosmosTest/EntityInjector.Samples.CosmosTest.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.52.0" />
1414
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
1515
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
16+
<PackageReference Include="xRetry" Version="1.9.0" />
1617
<PackageReference Include="xunit" Version="2.9.3" />
1718
<PackageReference Include="xunit.runner.visualstudio" Version="2.9.3" />
1819
</ItemGroup>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# EntityInjector.Samples.CosmosTest
2+
3+
This sample demonstrates how to use EntityInjector with a Cosmos database using the docker linux emulator.
4+
It shows how to bind route parameters directly to entities using dependency injection.
5+
6+
Note that due to issues with the cosmos emulator we have added a retry on each test.
7+
8+
## Prerequisites
9+
10+
- Docker installed and running
11+
- .NET 8 SDK installed
12+
13+
## How to run
14+
15+
1. From the repository root, start the database using Docker Compose:
16+
17+
```bash
18+
docker compose up --build
19+
```
20+
21+
This will create a Cosmos container which can be easily browsed on localhost:1234.
22+
23+
2. From the sample project directory, build and run the tests:
24+
25+
```bash
26+
dotnet clean && dotnet restore && dotnet test
27+
```

EntityInjector.Samples.CosmosTest/Tests/MultipleModelsTests.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using Microsoft.AspNetCore.TestHost;
1313
using Microsoft.Azure.Cosmos.Linq;
1414
using Microsoft.Extensions.DependencyInjection;
15+
using xRetry;
1516
using Xunit;
1617

1718
namespace EntityInjector.Samples.CosmosTest.Tests;
@@ -84,7 +85,7 @@ private async Task<List<Product>> GetSeededProductsAsync()
8485
return products;
8586
}
8687

87-
[Fact]
88+
[RetryFact(maxRetries: 10, delayBetweenRetriesMs: 1000)]
8889
public async Task CanBindFromRouteToUserEntityViaGuid()
8990
{
9091
var users = await GetSeededUsersAsync();
@@ -101,7 +102,7 @@ public async Task CanBindFromRouteToUserEntityViaGuid()
101102
Assert.Equal(expectedUser.Age, result.Age);
102103
}
103104

104-
[Fact]
105+
[RetryFact(maxRetries: 10, delayBetweenRetriesMs: 1000)]
105106
public async Task CanBindFromRouteToProductEntityViaInt()
106107
{
107108
var products = await GetSeededProductsAsync();
@@ -118,7 +119,7 @@ public async Task CanBindFromRouteToProductEntityViaInt()
118119
Assert.Equal(expectedProduct.Price, result.Price);
119120
}
120121

121-
[Fact]
122+
[RetryFact(maxRetries: 10, delayBetweenRetriesMs: 1000)]
122123
public async Task CanFetchMultipleUsersByHttpRequest()
123124
{
124125
var users = (await GetSeededUsersAsync()).Take(2).ToList();
@@ -142,7 +143,7 @@ public async Task CanFetchMultipleUsersByHttpRequest()
142143
}
143144
}
144145

145-
[Fact]
146+
[RetryFact(maxRetries: 10, delayBetweenRetriesMs: 1000)]
146147
public async Task CanFetchMultipleProductsByHttpRequest()
147148
{
148149
var products = (await GetSeededProductsAsync()).Take(2).ToList();

EntityInjector.Samples.CosmosTest/Tests/StringKeyTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using Microsoft.AspNetCore.TestHost;
1313
using Microsoft.Azure.Cosmos.Linq;
1414
using Microsoft.Extensions.DependencyInjection;
15+
using xRetry;
1516
using Xunit;
1617

1718
namespace EntityInjector.Samples.CosmosTest.Tests;
@@ -51,7 +52,7 @@ public StringKeyTests(CosmosTestFixture fixture)
5152
_fixture = fixture;
5253
}
5354

54-
[Fact]
55+
[RetryFact(maxRetries: 10, delayBetweenRetriesMs: 1000)]
5556
public async Task CanBindFromRouteToUserEntityViaString()
5657
{
5758
// Get a seeded user from Cosmos DB
@@ -76,7 +77,7 @@ public async Task CanBindFromRouteToUserEntityViaString()
7677
Assert.Equal(expectedUser.Name, result.Name);
7778
}
7879

79-
[Fact]
80+
[RetryFact(maxRetries: 10, delayBetweenRetriesMs: 1000)]
8081
public async Task CanFetchMultipleUsersByHttpRequest()
8182
{
8283
var iterator = _fixture.UsersContainer.GetItemLinqQueryable<User>(true).ToFeedIterator();

0 commit comments

Comments
 (0)