Ejemplo n.º 1
0
        public void Acquire_completes_sync_then_release_succeeds()
        {
            ExclusiveLock l = new ExclusiveLock();

            ExclusiveLock.Token token = AssertTaskCompleted(l.AcquireAsync());

            l.Release(token);
        }
Ejemplo n.º 2
0
        public void Release_same_token_twice_throws_InvalidOperation()
        {
            ExclusiveLock l = new ExclusiveLock();

            ExclusiveLock.Token token = AssertTaskCompleted(l.AcquireAsync());

            l.Release(token);

            Assert.Throws <InvalidOperationException>(() => l.Release(token));
        }
Ejemplo n.º 3
0
        public void First_acquire_completes_sync_next_acquire_is_pending_until_first_release()
        {
            ExclusiveLock l = new ExclusiveLock();

            ExclusiveLock.Token token = AssertTaskCompleted(l.AcquireAsync());

            Task <ExclusiveLock.Token> nextAcquireTask = AssertTaskPending(l.AcquireAsync());

            l.Release(token);

            AssertTaskCompleted(nextAcquireTask);
        }
Ejemplo n.º 4
0
        public void Acquire_and_release_three_times_in_a_row_completes_sync_each_time()
        {
            ExclusiveLock l = new ExclusiveLock();

            ExclusiveLock.Token token1 = AssertTaskCompleted(l.AcquireAsync());
            l.Release(token1);

            ExclusiveLock.Token token2 = AssertTaskCompleted(l.AcquireAsync());
            l.Release(token2);

            ExclusiveLock.Token token3 = AssertTaskCompleted(l.AcquireAsync());
            l.Release(token3);
        }
Ejemplo n.º 5
0
        public void Three_acquires_first_completes_sync_next_acquires_are_pending_until_previous_owners_release()
        {
            ExclusiveLock l = new ExclusiveLock();

            ExclusiveLock.Token token1 = AssertTaskCompleted(l.AcquireAsync());

            Task <ExclusiveLock.Token> acquireTask1 = AssertTaskPending(l.AcquireAsync());
            Task <ExclusiveLock.Token> acquireTask2 = AssertTaskPending(l.AcquireAsync());

            l.Release(token1);

            ExclusiveLock.Token token2 = AssertTaskCompleted(acquireTask1);

            l.Release(token2);

            AssertTaskCompleted(acquireTask2);
        }