Exemplo n.º 1
0
    public static void ExitRequestsPreserveSemaphoreState()
    {
        var stack = new StackPolicy(Options.Create(new QueuePolicyOptions
        {
            MaxConcurrentRequests = 1,
            RequestQueueLimit     = 2,
        }));

        var task1 = stack.TryEnterAsync();

        Assert.True(task1.IsCompleted && task1.Result);

        var task2 = stack.TryEnterAsync();

        Assert.False(task2.IsCompleted);

        stack.OnExit();  // t1 exits, should free t2 to return
        Assert.True(task2.IsCompleted && task2.Result);

        stack.OnExit();  // t2 exists, there's now a free spot in server

        var task3 = stack.TryEnterAsync();

        Assert.True(task3.IsCompleted && task3.Result);
    }
Exemplo n.º 2
0
    public async Task StaleRequestsAreProperlyOverwritten()
    {
        var stack = new StackPolicy(Options.Create(new QueuePolicyOptions
        {
            MaxConcurrentRequests = 1,
            RequestQueueLimit     = 4,
        }));

        var task0 = stack.TryEnterAsync();

        Assert.True(task0.IsCompleted && await task0);

        var task1 = stack.TryEnterAsync();

        Assert.False(task1.IsCompleted);

        stack.OnExit();
        Assert.True(await task1);

        var task2 = stack.TryEnterAsync();

        Assert.False(task2.IsCompleted);

        stack.OnExit();
        Assert.True(await task2);

        stack.OnExit();
    }
Exemplo n.º 3
0
    public static async Task OneTryEnterAsyncOneOnExit()
    {
        var stack = new StackPolicy(Options.Create(new QueuePolicyOptions
        {
            MaxConcurrentRequests = 1,
            RequestQueueLimit     = 4,
        }));

        Assert.Throws <InvalidOperationException>(() => stack.OnExit());

        await stack.TryEnterAsync();

        stack.OnExit();

        Assert.Throws <InvalidOperationException>(() => stack.OnExit());
    }
Exemplo n.º 4
0
    public static void StaleRequestsAreProperlyOverwritten()
    {
        var stack = new StackPolicy(Options.Create(new QueuePolicyOptions
        {
            MaxConcurrentRequests = 0,
            RequestQueueLimit     = 4,
        }));

        var task1 = stack.TryEnterAsync();

        stack.OnExit();
        Assert.True(task1.IsCompleted);

        var task2 = stack.TryEnterAsync();

        stack.OnExit();
        Assert.True(task2.IsCompleted);
    }
Exemplo n.º 5
0
    public async Task BaseFunctionality()
    {
        var stack = new StackPolicy(Options.Create(new QueuePolicyOptions
        {
            MaxConcurrentRequests = 1,
            RequestQueueLimit     = 2,
        }));

        var task1 = stack.TryEnterAsync();

        Assert.True(task1.IsCompleted);
        Assert.True(await task1);

        var task2 = stack.TryEnterAsync();

        Assert.False(task2.IsCompleted);

        stack.OnExit();

        Assert.True(await task2);

        stack.OnExit();
    }
Exemplo n.º 6
0
        public static void BaseFunctionality()
        {
            var stack = new StackPolicy(Options.Create(new QueuePolicyOptions {
                MaxConcurrentRequests = 0,
                RequestQueueLimit     = 2,
            }));

            var task1 = stack.TryEnterAsync();

            Assert.False(task1.IsCompleted);

            stack.OnExit();

            Assert.True(task1.IsCompleted && task1.Result);
        }