public static void Perf_AcquiringLock_DifferentResources()
        {
            var       connectionProvider = ConnectionUtils.GetConnectionProvider();
            var       lockTimeout        = TimeSpan.Zero;
            const int concurrentQueries  = 1000;

            var successFullThreads = RunConcurrent(concurrentQueries,
                                                   lockTimeout,
                                                   connectionProvider,
                                                   x => x.ToString());

            Assert.Equal(concurrentQueries, successFullThreads);
        }
        public static void Perf_AcquiringLock_SameResource()
        {
            var       connectionProvider = ConnectionUtils.GetConnectionProvider();
            var       lockTimeout        = TimeSpan.FromMilliseconds(1000);
            const int concurrentQueries  = 1000;

            var threads = RunConcurrent(concurrentQueries,
                                        lockTimeout,
                                        connectionProvider,
                                        x => "oneLockToRuleThemAll");

            Assert.Equal(concurrentQueries, threads);
        }
        public static void Ctor_ActuallyGrantsExclusiveLock()
        {
            const int numberOfParallelJobs = 1000;
            var       connectionProvider   = ConnectionUtils.GetConnectionProvider();
            var       parallelOptions      = new ParallelOptions {
                MaxDegreeOfParallelism = numberOfParallelJobs
            };
            var i = 0;

            Parallel.For(0, numberOfParallelJobs, parallelOptions, _ =>
            {
                using (new DistributedLock("increment_test", TimeSpan.FromSeconds(1), connectionProvider))
                {
                    // prevent compiler/jit from reordering
                    var temp = Volatile.Read(ref i);
                    Volatile.Write(ref i, temp + 1);
                }
            });

            Assert.Equal(numberOfParallelJobs, i);
        }