Skip to content

Commit

Permalink
Fix TestDaprInteractor
Browse files Browse the repository at this point in the history
Signed-off-by: joshvanl <me@joshvanl.dev>
  • Loading branch information
JoshVanL committed Oct 31, 2023
1 parent df5a6c0 commit 5922940
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Dapr.Actors/Communication/ActorStateResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Dapr.Actors.Communication
/// <summary>
/// Represents a response from fetching an actor state key.
/// </summary>
class ActorStateResponse<T>
public class ActorStateResponse<T>
{
/// <summary>
/// Initializes a new instance of the <see cref="ActorStateResponse{T}"/> class.
Expand Down
2 changes: 1 addition & 1 deletion test/Dapr.Actors.Test/TestDaprInteractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public Task SaveStateTransactionallyAsync(string actorType, string actorId, stri
/// <param name="keyName">Name of key to get value for.</param>
/// <param name="cancellationToken">Cancels the operation.</param>
/// <returns>A task that represents the asynchronous operation.</returns>
public Task<string> GetStateAsync(string actorType, string actorId, string keyName, CancellationToken cancellationToken = default)
public Task<ActorStateResponse<string>> GetStateAsync(string actorType, string actorId, string keyName, CancellationToken cancellationToken = default)
{
throw new System.NotImplementedException();
}
Expand Down
2 changes: 1 addition & 1 deletion test/Dapr.E2E.Test.Actors/Reminders/IReminderActor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// Copyright 2021 The Dapr Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
6 changes: 5 additions & 1 deletion test/Dapr.E2E.Test.Actors/State/IStateActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@
namespace Dapr.E2E.Test.Actors.State
{
public interface IStateActor : IPingActor, IActor
{ }
{
Task<string> GetState(string key);

Task SetState(string key, string value, TimeSpan? ttl);
}
}
15 changes: 12 additions & 3 deletions test/Dapr.E2E.Test.App/Actors/StateActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,30 @@

namespace Dapr.E2E.Test.Actors.State
{
public class StateActor : Actor
public class StateActor : Actor, IStateActor
{
public StateActor(ActorHost host)
: base(host)
{
}

public Task Ping()
{
return Task.CompletedTask;
}

public Task<string> GetState(string key)
{
return this.StateManager.GetStateAsync<string>(key);
}

public Task<string> SetState(string key, string value, TimeSpan? ttl)
public Task SetState(string key, string value, TimeSpan? ttl)
{
return this.StateManager.SetStateAsync<string>(key, value, ttl: ttl);
if (ttl.HasValue)
{
return this.StateManager.SetStateAsync<String>(key, value, ttl: ttl.Value);
}
return this.StateManager.SetStateAsync<String>(key, value);
}
}
}
16 changes: 10 additions & 6 deletions test/Dapr.E2E.Test/Actors/E2ETests.StateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,19 @@ public async Task ActorCanSaveStateWithTTL()

await WaitForActorRuntimeAsync(proxy, cts.Token);

Check failure on line 31 in test/Dapr.E2E.Test/Actors/E2ETests.StateTests.cs

View workflow job for this annotation

GitHub Actions / run integration tests (6.0)

Dapr.E2E.Test.E2ETests.ActorCanSaveStateWithTTL: System.OperationCanceledException : The operation was canceled.

await proxy.SaveState("key", "value", 2, cts.Token);
await proxy.SetState("key", "value", TimeSpan.FromSeconds(2));

state = await.proxy.GetState("key", cts.Token);
Assert.Equal("value", state.Value);
var resp = await proxy.GetState("key");
Assert.Equal("value", resp);

await Task.Delay(TimeSpan.FromSeconds(2), cts.Token);
await Task.Delay(TimeSpan.FromSeconds(2));

state = await.proxy.GetState("key", cts.Token);
Assert.Null(state.Value);
resp = await proxy.GetState("key");
Assert.Null(resp);

await proxy.SetState("key", "new-value", null);
resp = await proxy.GetState("key");
Assert.Equal("new-value", resp);
}
}
}

0 comments on commit 5922940

Please sign in to comment.