-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add eventual consistency test (#594)
- Loading branch information
Showing
2 changed files
with
57 additions
and
10 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
tests/Integration/Momento.Sdk.Tests/Cache/ReplicaReadTest.cs
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,45 @@ | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace Momento.Sdk.Tests.Integration.Cache; | ||
|
||
[Collection("CacheClient")] | ||
public class ReplicaReadTest : TestBase | ||
{ | ||
private new readonly ICacheClient client; | ||
public ReplicaReadTest(CacheClientFixture fixture) : base(fixture) | ||
{ | ||
client = fixture.ClientWithBalancedReads; | ||
} | ||
|
||
[Fact] | ||
public async Task LatestValueAfterReplicationDelay() | ||
{ | ||
const int numTrials = 10; | ||
const int delayBetweenTrials = 100; | ||
const int replicationDelayMs = 1000; | ||
var random = new Random(); | ||
|
||
var trials = Enumerable.Range(0, numTrials).Select(async trialNumber => | ||
{ | ||
var startDelay = (trialNumber + 1) * delayBetweenTrials + (random.NextDouble() - 0.5) * 10; | ||
await Task.Delay((int)startDelay); | ||
|
||
var key = Utils.NewGuidString(); | ||
var value = Utils.NewGuidString(); | ||
|
||
var setResponse = await client.SetAsync(cacheName, key, value); | ||
Assert.True(setResponse is CacheSetResponse.Success, $"Unexpected response: {setResponse}"); | ||
|
||
await Task.Delay(replicationDelayMs); | ||
|
||
var getResponse = await client.GetAsync(cacheName, key); | ||
Assert.True(getResponse is CacheGetResponse.Hit, $"Unexpected response: {getResponse}"); | ||
var hitResponse = (CacheGetResponse.Hit)getResponse; | ||
string setValue = hitResponse.ValueString; | ||
Assert.Equal(value, setValue); | ||
}); | ||
|
||
await Task.WhenAll(trials); | ||
} | ||
} |
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