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(cluster0, cluster0.DynamicState.AllDestinations[1], context0), 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 ProxyErrorFeature(ProxyError.Request, null); var context1 = GetContext(cluster1, selectedDestination: 0, error); await middleware.Invoke(context1); Assert.True(nextInvoked); policies[1].Verify(p => p.RequestProxied(cluster1, cluster1.DynamicState.AllDestinations[0], context1), Times.Once); policies[1].VerifyNoOtherCalls(); policies[0].VerifyNoOtherCalls(); }
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(); }