I was expecting
- var locked = getAndLock( for x seconds )
- wait x + 100ms
- var notlocked = get() // without lock
- assert notLocked.Cas != 0xffffffffffffffff
but it fails.
The C# source [1] indicates that the expiry unit is seconds, not milliseconds. The only tests in the driver use 15 seconds, the default
Client: package id=“CouchbaseNetClient” version=“2.3.11” targetFramework="net462"
Server: running version 4.5.1-2844 Enterprise Edition (build-2844).
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using Couchbase;
using Couchbase.Configuration.Client;
using Couchbase.Core;
using Couchbase.IO;
using NUnit.Framework;
namespace couchtesting
{
[TestFixture]
public class couchbase_locking
{
private Cluster _cluster;
private IBucket _bucket;
[OneTimeSetUp]
public void BucketSetup()
{
var bucketName = "default";
var config = new ClientConfiguration { Servers = new List<Uri>(new[] { new Uri("http://localhost:8091/") }) };
config.BucketConfigs.Clear();
config.BucketConfigs.Add(bucketName, new BucketConfiguration { BucketName = bucketName });
_cluster = new Cluster(config);
_bucket = _cluster.OpenBucket(bucketName);
}
[OneTimeTearDown]
public void CouchCleanup()
{
_cluster?.Dispose();
}
[Test]
public void get_after_expired_getLock_allows_update_from_unlocked_cas()
{
uint OneSecond = 1;
TimeSpan OneAndABitSeconds = TimeSpan.FromMilliseconds(1100);
var doc = new Doc(Guid.NewGuid().ToString());
try
{
_bucket.Insert(doc.Id, doc);
var locked = _bucket.GetAndLock<Doc>(doc.Id, OneSecond);
var timer = Stopwatch.StartNew();
Thread.Sleep(OneAndABitSeconds);
timer.Stop();
Assert.That(timer.ElapsedMilliseconds, Is.GreaterThan(1000));
var notlocked = _bucket.Get<Doc>(doc.Id);
Assert.That(notlocked.Cas, Is.Not.EqualTo(ulong.MaxValue));
}
finally
{
_bucket.Remove(doc.Id);
}
}
public class Doc
{
public Doc(string id) { Id = id; }
public string Id { get; set; }
}
}
}