示例#1
0
    public async Task Invoke_PassiveHealthCheckIsEnabled_CallPolicy()
    {
        var policies    = new[] { GetPolicy("policy0"), GetPolicy("policy1") };
        var cluster0    = GetClusterInfo("cluster0", "policy0");
        var cluster1    = GetClusterInfo("cluster1", "policy1");
        var nextInvoked = false;
        var middleware  = new PassiveHealthCheckMiddleware(c =>
        {
            nextInvoked = true;
            return(Task.CompletedTask);
        }, policies.Select(p => p.Object));

        var context0 = GetContext(cluster0, selectedDestination: 1, error: null);
        await middleware.Invoke(context0);

        Assert.True(nextInvoked);
        policies[0].Verify(p => p.RequestProxied(context0, cluster0, cluster0.DestinationsState.AllDestinations[1]), Times.Once);
        policies[0].VerifyGet(p => p.Name, Times.Once);
        policies[0].VerifyNoOtherCalls();
        policies[1].VerifyGet(p => p.Name, Times.Once);
        policies[1].VerifyNoOtherCalls();

        nextInvoked = false;

        var error    = new ForwarderErrorFeature(ForwarderError.Request, null);
        var context1 = GetContext(cluster1, selectedDestination: 0, error);
        await middleware.Invoke(context1);

        Assert.True(nextInvoked);
        policies[1].Verify(p => p.RequestProxied(context1, cluster1, cluster1.DestinationsState.AllDestinations[0]), Times.Once);
        policies[1].VerifyNoOtherCalls();
        policies[0].VerifyNoOtherCalls();
    }
示例#2
0
        private HttpContext GetFailedRequestContext(ForwarderError error)
        {
            var errorFeature = new ForwarderErrorFeature(error, null);
            var context      = new DefaultHttpContext();

            context.Features.Set <IForwarderErrorFeature>(errorFeature);
            return(context);
        }