Skip to content

Conversation

@darrelmiller
Copy link
Contributor

@darrelmiller darrelmiller commented Oct 22, 2019

Added ChaosHandler middleware for simulating server failures

This example shows how to create a GraphServiceClient with the ChaosHandler in the pipeline

            var handlers = GraphClientFactory.CreateDefaultHandlers(authProvider);
            handlers.Add(new ChaosHandler());

            // Create a customized HttpClient based on these handlers
            HttpClient client = GraphClientFactory.Create(handlers);

            // Create a GraphServiceClient based on the HttpClient
            var graphClient = new GraphServiceClient(client);

ChaosHandler can also be created with a customized set of known failures.

var handler = new ChaosHandler(new ChaosHandlerOption()
            {
                KnownChaos = new List<HttpResponseMessage>()
                {
                    ChaosHandler.Create429TooManyRequestsResponse(new TimeSpan(0,0,5)),
                    ChaosHandler.Create500InternalServerErrorResponse(),
                    ChaosHandler.Create503Response(new TimeSpan(0,0,5)),
                    ChaosHandler.Create502BadGatewayResponse()
                }
            });

Once a problem has been identified, it is possible to plan to have certain failures be returned for specific requests.

           Func<HttpRequestMessage, HttpResponseMessage> plannedChaos = (req) =>
             {
                 if (req.RequestUri.OriginalString.Contains("/fail"))
                 {
                     return ChaosHandler.Create429TooManyRequestsResponse(new TimeSpan(0, 0, 5));
                 }
                return null;
             };

            var handler = new ChaosHandler(new ChaosHandlerOption()
            {
                PlannedChaosFactory = plannedChaos
            });

pschaeflein
pschaeflein previously approved these changes Oct 23, 2019
peombwa
peombwa previously approved these changes Oct 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants