Hi all.
I want to start with that I’ve checked system time on application and couchbase servers. Everything is fine.
Couchbase adds the same time constant for each expiry. This constant is specific for each Couchbase server. For one server it is ~2 minutes 20 sec. For another, it is ~6 minutes 18 sec. If I decide to store something for 1 minute, then it will be really stored for 3 or 7 minutes. I don’t have any idea why does it happen. Can you help me?
I’ve used this test to catch this issue.
public static IEnumerable<object[]> Expiries = new List<object[]>
{
new object[] { TimeSpan.FromSeconds(10) },
new object[] { TimeSpan.FromSeconds(30) },
new object[] { TimeSpan.FromMinutes(1) },
new object[] { TimeSpan.FromMinutes(10) },
new object[] { TimeSpan.FromMinutes(30) },
new object[] { TimeSpan.FromHours(1) },
new object[] { TimeSpan.FromHours(10) },
new object[] { TimeSpan.FromDays(1) },
new object[] { TimeSpan.FromDays(10) }
};
[Theory]
[MemberData(nameof(Expiries))]
[Trait(TraitConstants.TraitCategory, TraitConstants.IntegrationTestCategory)]
public async Task InsertGet_EternalCouchbaseConstants_ConstantsAreValid(TimeSpan expiry)
{
await Initialize();
var stopWatch = Stopwatch.StartNew();
await _collection.InsertAsync(CouchbaseId, "someString", options => options
.Expiry(expiry));
var getResult = await _collection.GetAsync(CouchbaseId, options => options
.Expiry());
stopWatch.Stop();
var expectedExpiryTime = SystemClock.Instance.GetCurrentInstant().ToDateTimeUtc().Add(expiry);
var minExpectedExpiryTime = expectedExpiryTime.Subtract(stopWatch.Elapsed);
var maxExpectedExpiryTime = expectedExpiryTime.Add(stopWatch.Elapsed);
Assert.NotNull(getResult.ExpiryTime);
var expiryTimeUtc = getResult.ExpiryTime.Value.ToUniversalTime();
Assert.True(expiryTimeUtc > minExpectedExpiryTime);
Assert.True(expiryTimeUtc > maxExpectedExpiryTime); //Should be less
var difference = expiryTimeUtc - expectedExpiryTime;
_testOutputHelper.WriteLine($"Inserted expiry: {expiry}.");
_testOutputHelper.WriteLine($"Expected expiry time: {expectedExpiryTime}.");
_testOutputHelper.WriteLine($"Getted expiry time: {expiryTimeUtc}.");
_testOutputHelper.WriteLine($"Difference: {difference}.");
}