-
-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Retry request on DeadLetterResponse (#1822)
Instead of failing virtual actor request when DeadLetterResponse is received, retry the request. Also make sure that DeadLetterResponse is not returned to client when request is called with object as type parameter. Fixes #1799
- Loading branch information
1 parent
1bf095b
commit 6c27bc8
Showing
2 changed files
with
70 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using ClusterTest.Messages; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace Proto.Cluster.Tests; | ||
|
||
public class RetryOnDeadLetterTests | ||
{ | ||
[Fact] | ||
public async Task ShouldRetryRequestOnDeadLetterResponseRegardlessOfResponseType() | ||
{ | ||
await using var fixture = new Fixture(1); | ||
await fixture.InitializeAsync(); | ||
|
||
var member = fixture.Members.First(); | ||
var identity = CreateIdentity("dead-letter-test"); | ||
|
||
// make sure the actor is created and the PID is cached | ||
await member.RequestAsync<Pong>(identity, EchoActor.Kind, new Ping(), CancellationTokens.FromSeconds(1)); | ||
|
||
// pretend we have an invalid PID in the cache | ||
var otherMember = await fixture.SpawnNode(); | ||
if (member.PidCache.TryGet(ClusterIdentity.Create(identity, EchoActor.Kind), out var pid)) | ||
{ | ||
var newPid = PID.FromAddress(otherMember.System.Address, pid.Id); | ||
if (!member.PidCache.TryUpdate(ClusterIdentity.Create(identity, EchoActor.Kind), newPid, pid)) | ||
{ | ||
Assert.Fail("Failed to replace actor's pid with a fake one in the pid cache"); | ||
} | ||
} | ||
else | ||
{ | ||
Assert.Fail("Did not find expected actor identity in the pid cache"); | ||
} | ||
|
||
// check if the correct response type is returned | ||
var response = await member.RequestAsync<object>(identity, EchoActor.Kind, new Ping(), CancellationTokens.FromSeconds(1)); | ||
response.Should().BeOfType<Pong>(); | ||
|
||
} | ||
|
||
private string CreateIdentity(string baseId) => $"{Guid.NewGuid().ToString("N").Substring(0, 6)}-{baseId}-"; | ||
|
||
private class Fixture : BaseInMemoryClusterFixture | ||
{ | ||
public Fixture(int clusterSize) | ||
: base(clusterSize, cc => cc | ||
.WithActorRequestTimeout(TimeSpan.FromSeconds(1)) | ||
) | ||
{ | ||
} | ||
} | ||
} |