Example #1
0
        public async Task GlobalLockActivatesOnceOnly()
        {
            var timeout  = new CancellationTokenSource(1000).Token;
            var identity = new ClusterIdentity {
                Kind = "thing", Identity = NextId().ToString()
            };
            const int attempts = 10;

            var locks = await Task.WhenAll(Enumerable.Range(1, attempts)
                                           .Select(i => _storage.TryAcquireLock(identity, timeout))
                                           );

            var successFullLock = locks.Where(it => it != null).ToList();

            successFullLock.Should().HaveCount(1);
            successFullLock.Single() !.ClusterIdentity.Should().BeEquivalentTo(identity);
        }
Example #2
0
        public async Task GlobalLockActivatesOnceOnlyAcrossMultipleClients()
        {
            var timeout  = new CancellationTokenSource(1000).Token;
            var identity = new ClusterIdentity {
                Kind = "thing", Identity = "1234"
            };
            const int attempts = 10;

            var locks = await Task.WhenAll(Enumerable.Range(1, attempts)
                                           .SelectMany(_ => new[]
            {
                _storage.TryAcquireLock(identity, timeout),
                _storageInstance2.TryAcquireLock(identity, timeout)
            }
                                                       )
                                           );

            var successfulLock = locks.Where(it => it != null).ToList();

            successfulLock.Should().HaveCount(1);
            successfulLock.Single() !.ClusterIdentity.Should().BeEquivalentTo(identity);
        }