Пример #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
        public async Task Invoke_PassiveHealthCheckIsDisabled_DoNothing()
        {
            var policies    = new[] { GetPolicy("policy0"), GetPolicy("policy1") };
            var cluster0    = GetClusterInfo("cluster0", "policy0", enabled: false);
            var nextInvoked = false;
            var middleware  = new PassiveHealthCheckMiddleware(c => {
                nextInvoked = true;
                return(Task.CompletedTask);
            }, policies.Select(p => p.Object));

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

            Assert.True(nextInvoked);
            policies[0].VerifyGet(p => p.Name, Times.Once);
            policies[0].VerifyNoOtherCalls();
            policies[1].VerifyGet(p => p.Name, Times.Once);
            policies[1].VerifyNoOtherCalls();
        }