Skip to content

Commit

Permalink
- update to include latest dependencies
Browse files Browse the repository at this point in the history
- also I now include postgres V2 in the tests to check on parity
  • Loading branch information
olitomlinson committed Feb 19, 2024
1 parent c618600 commit 95f8a8d
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 18 deletions.
16 changes: 16 additions & 0 deletions IntegrationTests/DaprComponents/standard-postgres-v2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: standard-postgres-v2
spec:
type: state.postgresql
# Note: setting "version" to "v2" is required to use the v2 of the component
version: v2
metadata:
# Connection string
- name: connectionString
value: "host=db user=postgres password=postgres port=5432 database=postgres"
- name: tablePrefix
value: v2_state
- name: metadataTableName
value: v2_metadata
4 changes: 3 additions & 1 deletion IntegrationTests/DaprComponents/standard-postgres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ spec:
version: v1
metadata:
- name: connectionString
value: "host=db user=postgres password=postgres port=5432 database=postgres"
value: "host=db user=postgres password=postgres port=5432 database=postgres"
- name: tableName
value: v1_state
6 changes: 3 additions & 3 deletions IntegrationTests/IntegrationTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dapr.Client" Version="1.11.0" />
<PackageReference Include="Dapr.Client" Version="1.13.0-rc02" />
<ProjectReference Include="../src/Component.csproj" />
<PackageReference Include="JetBrains.Annotations" Version="2022.3.1" />
<PackageReference Include="Testcontainers" Version="3.5.0" />
<PackageReference Include="Testcontainers.PostgreSql" Version="3.5.0" />
<PackageReference Include="Testcontainers" Version="3.7.0" />
<PackageReference Include="Testcontainers.PostgreSql" Version="3.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
Expand Down
2 changes: 1 addition & 1 deletion IntegrationTests/TestContainers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public TestContainers()
_socketVolume = new VolumeBuilder().Build();

_daprContainer = new ContainerBuilder()
.WithImage("ghcr.io/dapr/daprd:1.12.2")
.WithImage("ghcr.io/dapr/daprd:1.13.0-rc.6")
.WithName($"dapr-{containerSuffix}")
.WithNetwork(_network)
.WithNetworkAliases("dapr")
Expand Down
65 changes: 54 additions & 11 deletions IntegrationTests/Tests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Dapr.Client;
using Microsoft.Extensions.ObjectPool;
using Xunit.Abstractions;

namespace IntegrationTests;
Expand All @@ -9,20 +10,43 @@ public class StateIsolationTests : IClassFixture<TestContainers>
private readonly TestContainers _testContainers;
private readonly DaprClient _daprClient;
private Func<string> GetRandomKey;
private static string _pluggableStoreTable = "pluggable-postgres-table";
private static string _pluggableStoreSchema = "pluggable-postgres-schema";
private static string _InTreeStore = "standard-postgres";
private Random _random = new Random();

public static IEnumerable<object[]> AllStores(){
foreach(var store in OnlyTenantStores())
yield return store;
yield return new object[] { _InTreeStore };
public static IEnumerable<object[]> AllStores{
get {
foreach(var store in AllStoresWithoutPostgresV2)
yield return store;
foreach(var store in PostgresV2)
yield return store;
}
}

public static IEnumerable<object[]> AllStoresWithoutPostgresV2
{
get {
foreach(var store in OnlyTenantStores)
yield return store;
foreach(var store in PostgresV1)
yield return store;
}
}

public static IEnumerable<object[]> OnlyTenantStores
{
get {
yield return new object[] { "pluggable-postgres-table" };
yield return new object[] { "pluggable-postgres-schema" };
}
}

public static IEnumerable<object[]> OnlyTenantStores(){
yield return new object[] { _pluggableStoreTable };
yield return new object[] { _pluggableStoreSchema };
public static IEnumerable<object[]> PostgresV1
{
get { yield return new object[] { "standard-postgres" }; }
}

public static IEnumerable<object[]> PostgresV2
{
get { yield return new object[] { "standard-postgres-v2" }; }
}

public StateIsolationTests(TestContainers testContainers, ITestOutputHelper output)
Expand Down Expand Up @@ -167,7 +191,7 @@ public async Task UpdatesWithEtag(string store)
}

[Theory]
[MemberData(nameof(AllStores))]
[MemberData(nameof(AllStoresWithoutPostgresV2))]
public async Task UpdatesAndEtagInvalidIsThrown(string store)
{
var key = GetRandomKey();
Expand All @@ -184,6 +208,25 @@ public async Task UpdatesAndEtagInvalidIsThrown(string store)
await _daprClient.TrySaveStateAsync<string>(store, key, updatedValue, malformedEtag, metadata: tenantId.AsMetaData(), cancellationToken: new CancellationTokenSource(5000).Token); });
}

[Theory]
[MemberData(nameof(PostgresV2))]
public async Task PostgresV2_UpdatesAndEtagIsMismatched(string store)
{
var key = GetRandomKey();
var seedValue = "Chicken";
var tenantId = Guid.NewGuid().ToString();

await _daprClient.SaveStateAsync<string>(store, key, seedValue, metadata: tenantId.AsMetaData(), cancellationToken: new CancellationTokenSource(5000).Token);
var (firstGet, etag) = await _daprClient.GetStateAndETagAsync<string>(store, key, metadata: tenantId.AsMetaData(), cancellationToken: new CancellationTokenSource(5000).Token);

var updatedValue = "Egg";
var malformedEtag = $"not-a-valid-etag";

var result = await _daprClient.TrySaveStateAsync<string>(store, key, updatedValue, malformedEtag, metadata: tenantId.AsMetaData(), cancellationToken: new CancellationTokenSource(5000).Token);
Assert.False(result);
}


[Theory]
[MemberData(nameof(AllStores))]
public async Task UpdatesCantUseOldEtags(string store)
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
db:
image: postgres:15.2-alpine
image: postgres:15.5-alpine
restart: always
environment:
- POSTGRES_USER=postgres
Expand All @@ -22,7 +22,7 @@ services:
depends_on:
- db
pluggableapp-dapr:
image: "daprio/daprd:1.12.2-mariner"
image: "daprio/daprd:1.13.0-rc.6"
deploy:
restart_policy:
condition: on-failure
Expand Down

0 comments on commit 95f8a8d

Please sign in to comment.