Skip to content

Commit

Permalink
fix: update int test ttls to be more lenient (#441)
Browse files Browse the repository at this point in the history
  • Loading branch information
bruuuuuuuce authored May 15, 2023
1 parent 046ebb5 commit b215a2e
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 99 deletions.
72 changes: 36 additions & 36 deletions tests/Integration/Momento.Sdk.Tests/DictionaryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ public async Task DictionarySetGetAsync_FieldIsByteArrayValueIsByteArray_NoRefre
var field = Utils.NewGuidByteArray();
var value = Utils.NewGuidByteArray();

CacheDictionarySetFieldResponse setResponse = await client.DictionarySetFieldAsync(cacheName, dictionaryName, field, value, CollectionTtl.Of(TimeSpan.FromSeconds(5)).WithNoRefreshTtlOnUpdates());
CacheDictionarySetFieldResponse setResponse = await client.DictionarySetFieldAsync(cacheName, dictionaryName, field, value, CollectionTtl.Of(TimeSpan.FromSeconds(Utils.InitialRefreshTtl)).WithNoRefreshTtlOnUpdates());
Assert.True(setResponse is CacheDictionarySetFieldResponse.Success, $"Unexpected response: {setResponse}");
await Task.Delay(100);
await Task.Delay(Utils.WaitForItemToBeSet);

setResponse = await client.DictionarySetFieldAsync(cacheName, dictionaryName, field, value, CollectionTtl.Of(TimeSpan.FromSeconds(10)).WithNoRefreshTtlOnUpdates());
setResponse = await client.DictionarySetFieldAsync(cacheName, dictionaryName, field, value, CollectionTtl.Of(TimeSpan.FromSeconds(Utils.UpdatedRefreshTtl)).WithNoRefreshTtlOnUpdates());
Assert.True(setResponse is CacheDictionarySetFieldResponse.Success, $"Unexpected response: {setResponse}");
await Task.Delay(4900);
await Task.Delay(Utils.WaitForInitialItemToExpire);

CacheDictionaryGetFieldResponse response = await client.DictionaryGetFieldAsync(cacheName, dictionaryName, field);
Assert.True(response is CacheDictionaryGetFieldResponse.Miss, $"Unexpected response: {response}");
Expand All @@ -106,7 +106,7 @@ public async Task DictionarySetGetAsync_FieldIsByteArrayValueIsByteArray_Refresh

CacheDictionarySetFieldResponse setResponse = await client.DictionarySetFieldAsync(cacheName, dictionaryName, field, value, CollectionTtl.Of(TimeSpan.FromSeconds(2)));
Assert.True(setResponse is CacheDictionarySetFieldResponse.Success, $"Unexpected response: {setResponse}");
setResponse = await client.DictionarySetFieldAsync(cacheName, dictionaryName, field, value, CollectionTtl.Of(TimeSpan.FromSeconds(10)));
setResponse = await client.DictionarySetFieldAsync(cacheName, dictionaryName, field, value, CollectionTtl.Of(TimeSpan.FromSeconds(Utils.UpdatedRefreshTtl)));
Assert.True(setResponse is CacheDictionarySetFieldResponse.Success, $"Unexpected response: {setResponse}");
await Task.Delay(2000);

Expand Down Expand Up @@ -162,7 +162,7 @@ public async Task DictionaryIncrementAsync_IncrementFromZero_RefreshTtl()

CacheDictionaryIncrementResponse resp = await client.DictionaryIncrementAsync(cacheName, dictionaryName, field, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(2)));
Assert.True(resp is CacheDictionaryIncrementResponse.Success, $"Unexpected response: {resp}");
resp = await client.DictionaryIncrementAsync(cacheName, dictionaryName, field, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(10)));
resp = await client.DictionaryIncrementAsync(cacheName, dictionaryName, field, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(Utils.UpdatedRefreshTtl)));
Assert.True(resp is CacheDictionaryIncrementResponse.Success, $"Unexpected response: {resp}");
await Task.Delay(2000);

Expand All @@ -177,13 +177,13 @@ public async Task DictionaryIncrementAsync_IncrementFromZero_NoRefreshTtl()
var dictionaryName = Utils.NewGuidString();
var field = Utils.NewGuidString();

CacheDictionaryIncrementResponse resp = await client.DictionaryIncrementAsync(cacheName, dictionaryName, field, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(5)));
CacheDictionaryIncrementResponse resp = await client.DictionaryIncrementAsync(cacheName, dictionaryName, field, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(Utils.InitialRefreshTtl)));
Assert.True(resp is CacheDictionaryIncrementResponse.Success, $"Unexpected response: {resp}");
await Task.Delay(101);
await Task.Delay(Utils.WaitForItemToBeSet);

resp = await client.DictionaryIncrementAsync(cacheName, dictionaryName, field, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(10)).WithNoRefreshTtlOnUpdates());
resp = await client.DictionaryIncrementAsync(cacheName, dictionaryName, field, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(Utils.UpdatedRefreshTtl)).WithNoRefreshTtlOnUpdates());
Assert.True(resp is CacheDictionaryIncrementResponse.Success, $"Unexpected response: {resp}");
await Task.Delay(4900);
await Task.Delay(Utils.WaitForInitialItemToExpire);

CacheDictionaryGetFieldResponse response = await client.DictionaryGetFieldAsync(cacheName, dictionaryName, field);
Assert.True(response is CacheDictionaryGetFieldResponse.Miss, $"Unexpected response: {response}");
Expand Down Expand Up @@ -316,13 +316,13 @@ public async Task DictionarySetGetAsync_FieldIsStringValueIsString_NoRefreshTtl(
var field = Utils.NewGuidString();
var value = Utils.NewGuidString();

CacheDictionarySetFieldResponse setResponse = await client.DictionarySetFieldAsync(cacheName, dictionaryName, field, value, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(5)));
CacheDictionarySetFieldResponse setResponse = await client.DictionarySetFieldAsync(cacheName, dictionaryName, field, value, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(Utils.InitialRefreshTtl)));
Assert.True(setResponse is CacheDictionarySetFieldResponse.Success, $"Unexpected response: {setResponse}");
await Task.Delay(100);
await Task.Delay(Utils.WaitForItemToBeSet);

setResponse = await client.DictionarySetFieldAsync(cacheName, dictionaryName, field, value, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(10)).WithNoRefreshTtlOnUpdates());
setResponse = await client.DictionarySetFieldAsync(cacheName, dictionaryName, field, value, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(Utils.UpdatedRefreshTtl)).WithNoRefreshTtlOnUpdates());
Assert.True(setResponse is CacheDictionarySetFieldResponse.Success, $"Unexpected response: {setResponse}");
await Task.Delay(4900);
await Task.Delay(Utils.WaitForInitialItemToExpire);

CacheDictionaryGetFieldResponse response = await client.DictionaryGetFieldAsync(cacheName, dictionaryName, field);
Assert.True(response is CacheDictionaryGetFieldResponse.Miss, $"Unexpected response: {response}");
Expand All @@ -337,7 +337,7 @@ public async Task DictionarySetGetAsync_FieldIsStringValueIsString_RefreshTtl()

CacheDictionarySetFieldResponse setResponse = await client.DictionarySetFieldAsync(cacheName, dictionaryName, field, value, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(2)));
Assert.True(setResponse is CacheDictionarySetFieldResponse.Success, $"Unexpected response: {setResponse}");
setResponse = await client.DictionarySetFieldAsync(cacheName, dictionaryName, field, value, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(10)));
setResponse = await client.DictionarySetFieldAsync(cacheName, dictionaryName, field, value, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(Utils.UpdatedRefreshTtl)));
Assert.True(setResponse is CacheDictionarySetFieldResponse.Success, $"Unexpected response: {setResponse}");
await Task.Delay(2000);

Expand Down Expand Up @@ -379,13 +379,13 @@ public async Task DictionarySetGetAsync_FieldIsStringValueIsByteArray_NoRefreshT
var field = Utils.NewGuidString();
var value = Utils.NewGuidByteArray();

CacheDictionarySetFieldResponse setResponse = await client.DictionarySetFieldAsync(cacheName, dictionaryName, field, value, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(5)));
CacheDictionarySetFieldResponse setResponse = await client.DictionarySetFieldAsync(cacheName, dictionaryName, field, value, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(Utils.InitialRefreshTtl)));
Assert.True(setResponse is CacheDictionarySetFieldResponse.Success, $"Unexpected response: {setResponse}");
await Task.Delay(100);
await Task.Delay(Utils.WaitForItemToBeSet);

setResponse = await client.DictionarySetFieldAsync(cacheName, dictionaryName, field, value, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(10)).WithNoRefreshTtlOnUpdates());
setResponse = await client.DictionarySetFieldAsync(cacheName, dictionaryName, field, value, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(Utils.UpdatedRefreshTtl)).WithNoRefreshTtlOnUpdates());
Assert.True(setResponse is CacheDictionarySetFieldResponse.Success, $"Unexpected response: {setResponse}");
await Task.Delay(4900);
await Task.Delay(Utils.WaitForInitialItemToExpire);

CacheDictionaryGetFieldResponse response = await client.DictionaryGetFieldAsync(cacheName, dictionaryName, field);
Assert.True(response is CacheDictionaryGetFieldResponse.Miss, $"Unexpected response: {response}");
Expand All @@ -400,7 +400,7 @@ public async Task DictionarySetGetAsync_FieldIsStringValueIsByteArray_RefreshTtl

CacheDictionarySetFieldResponse setResponse = await client.DictionarySetFieldAsync(cacheName, dictionaryName, field, value, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(2)));
Assert.True(setResponse is CacheDictionarySetFieldResponse.Success, $"Unexpected response: {setResponse}");
setResponse = await client.DictionarySetFieldAsync(cacheName, dictionaryName, field, value, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(10)));
setResponse = await client.DictionarySetFieldAsync(cacheName, dictionaryName, field, value, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(Utils.UpdatedRefreshTtl)));
Assert.True(setResponse is CacheDictionarySetFieldResponse.Success, $"Unexpected response: {setResponse}");
await Task.Delay(2000);

Expand Down Expand Up @@ -441,7 +441,7 @@ public async Task DictionarySetFieldsAsync_FieldsAreByteArrayValuesAreByteArray_

var items = new Dictionary<byte[], byte[]>() { { field1, value1 }, { field2, value2 } };

await client.DictionarySetFieldsAsync(cacheName, dictionaryName, items, CollectionTtl.Of(TimeSpan.FromSeconds(10)));
await client.DictionarySetFieldsAsync(cacheName, dictionaryName, items, CollectionTtl.Of(TimeSpan.FromSeconds(Utils.UpdatedRefreshTtl)));

CacheDictionaryGetFieldResponse getResponse = await client.DictionaryGetFieldAsync(cacheName, dictionaryName, field1);
Assert.True(getResponse is CacheDictionaryGetFieldResponse.Hit, $"Unexpected response: {getResponse}");
Expand All @@ -460,11 +460,11 @@ public async Task DictionarySetFieldsAsync_FieldsAreByteArrayValuesAreByteArray_
var value = Utils.NewGuidByteArray();
var content = new Dictionary<byte[], byte[]>() { { field, value } };

await client.DictionarySetFieldsAsync(cacheName, dictionaryName, content, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(5)));
await Task.Delay(100);
await client.DictionarySetFieldsAsync(cacheName, dictionaryName, content, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(Utils.InitialRefreshTtl)));
await Task.Delay(Utils.WaitForItemToBeSet);

await client.DictionarySetFieldsAsync(cacheName, dictionaryName, content, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(10)).WithNoRefreshTtlOnUpdates());
await Task.Delay(4900);
await client.DictionarySetFieldsAsync(cacheName, dictionaryName, content, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(Utils.UpdatedRefreshTtl)).WithNoRefreshTtlOnUpdates());
await Task.Delay(Utils.WaitForInitialItemToExpire);

CacheDictionaryGetFieldResponse response = await client.DictionaryGetFieldAsync(cacheName, dictionaryName, field);
Assert.True(response is CacheDictionaryGetFieldResponse.Miss, $"Unexpected response: {response}");
Expand All @@ -479,7 +479,7 @@ public async Task DictionarySetFieldsAsync_FieldsAreByteArrayValuesAreByteArray_
var content = new Dictionary<byte[], byte[]>() { { field, value } };

await client.DictionarySetFieldsAsync(cacheName, dictionaryName, content, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(2)));
await client.DictionarySetFieldsAsync(cacheName, dictionaryName, content, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(10)));
await client.DictionarySetFieldsAsync(cacheName, dictionaryName, content, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(Utils.UpdatedRefreshTtl)));
await Task.Delay(2000);

CacheDictionaryGetFieldResponse response = await client.DictionaryGetFieldAsync(cacheName, dictionaryName, field);
Expand Down Expand Up @@ -538,11 +538,11 @@ public async Task DictionarySetFieldsAsync_FieldsAreStringValuesAreString_NoRefr
var value = Utils.NewGuidString();
var content = new Dictionary<string, string>() { { field, value } };

await client.DictionarySetFieldsAsync(cacheName, dictionaryName, content, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(5)));
await Task.Delay(100);
await client.DictionarySetFieldsAsync(cacheName, dictionaryName, content, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(Utils.InitialRefreshTtl)));
await Task.Delay(Utils.WaitForItemToBeSet);

await client.DictionarySetFieldsAsync(cacheName, dictionaryName, content, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(10)).WithNoRefreshTtlOnUpdates());
await Task.Delay(4900);
await client.DictionarySetFieldsAsync(cacheName, dictionaryName, content, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(Utils.UpdatedRefreshTtl)).WithNoRefreshTtlOnUpdates());
await Task.Delay(Utils.WaitForInitialItemToExpire);

CacheDictionaryGetFieldResponse response = await client.DictionaryGetFieldAsync(cacheName, dictionaryName, field);
Assert.True(response is CacheDictionaryGetFieldResponse.Miss, $"Unexpected response: {response}");
Expand All @@ -557,7 +557,7 @@ public async Task DictionarySetFieldsAsync_FieldsAreStringValuesAreString_Refres
var content = new Dictionary<string, string>() { { field, value } };

await client.DictionarySetFieldsAsync(cacheName, dictionaryName, content, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(2)));
await client.DictionarySetFieldsAsync(cacheName, dictionaryName, content, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(10)));
await client.DictionarySetFieldsAsync(cacheName, dictionaryName, content, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(Utils.UpdatedRefreshTtl)));
await Task.Delay(2000);

CacheDictionaryGetFieldResponse response = await client.DictionaryGetFieldAsync(cacheName, dictionaryName, field);
Expand Down Expand Up @@ -616,11 +616,11 @@ public async Task DictionarySetFieldsAsync_FieldsAreStringValuesAreByteArray_NoR
var value = Utils.NewGuidByteArray();
var content = new Dictionary<string, byte[]>() { { field, value } };

await client.DictionarySetFieldsAsync(cacheName, dictionaryName, content, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(5)).WithNoRefreshTtlOnUpdates());
await Task.Delay(100);
await client.DictionarySetFieldsAsync(cacheName, dictionaryName, content, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(Utils.InitialRefreshTtl)).WithNoRefreshTtlOnUpdates());
await Task.Delay(Utils.WaitForItemToBeSet);

await client.DictionarySetFieldsAsync(cacheName, dictionaryName, content, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(10)).WithNoRefreshTtlOnUpdates());
await Task.Delay(4900);
await client.DictionarySetFieldsAsync(cacheName, dictionaryName, content, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(Utils.UpdatedRefreshTtl)).WithNoRefreshTtlOnUpdates());
await Task.Delay(Utils.WaitForInitialItemToExpire);

CacheDictionaryGetFieldResponse response = await client.DictionaryGetFieldAsync(cacheName, dictionaryName, field);
Assert.True(response is CacheDictionaryGetFieldResponse.Miss, $"Unexpected response: {response}");
Expand All @@ -635,7 +635,7 @@ public async Task DictionarySetFieldsAsync_FieldsAreStringValuesAreByteArray_Ref
var content = new Dictionary<string, byte[]>() { { field, value } };

await client.DictionarySetFieldsAsync(cacheName, dictionaryName, content, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(2)));
await client.DictionarySetFieldsAsync(cacheName, dictionaryName, content, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(10)));
await client.DictionarySetFieldsAsync(cacheName, dictionaryName, content, ttl: CollectionTtl.Of(TimeSpan.FromSeconds(Utils.UpdatedRefreshTtl)));
await Task.Delay(2000);

CacheDictionaryGetFieldResponse response = await client.DictionaryGetFieldAsync(cacheName, dictionaryName, field);
Expand Down
Loading

0 comments on commit b215a2e

Please sign in to comment.