예제 #1
0
 private static void Fail(ChaosScenario scenario)
 {
     if (ShouldFail(scenario.FailureRate))
     {
         throw new ChaosException($"The chaos monkey was naughty and injected this exception! ({scenario.Name})");
     }
 }
예제 #2
0
        private static async Task DoChaosAsync(ChaosScenario scenario)
        {
            if (IsEnabled)
            {
                if (scenario.Delay > 0)
                {
                    await DelayAsync(scenario);
                }

                Fail(scenario);
            }
        }
예제 #3
0
        /// <summary>
        /// Potentially introduce chaos in the system, for a given chaos scenario.
        /// </summary>
        /// <param name="scenario">The scenario.</param>
        public static Task ChaosAsync(ChaosScenario scenario)
        {
            // TODO: Assert.ParamIsNotNull(scenario, nameof(scenario));

            if (IsEnabled)
            {
                return(DoChaosAsync(scenario));
            }
            else
            {
                return(NullTask);
            }
        }
예제 #4
0
        /// <summary>
        /// Potentially introduce chaos in the system, for a given chaos scenario.
        /// </summary>
        /// <param name="scenario">The scenario.</param>
        public static void Chaos(ChaosScenario scenario)
        {
            // TODO: Assert.ParamIsNotNull(scenario, nameof(scenario));

            if (IsEnabled)
            {
                if (scenario.Delay > 0)
                {
                    DelayAsync(scenario).Wait();
                }

                Fail(scenario);
            }
        }
예제 #5
0
 private static Task DelayAsync(ChaosScenario scenario)
 {
     Logger.Info($"Delaying {scenario.Delay}ms for chaos scenario '{scenario.Name}'");
     return(Task.Delay(scenario.Delay));
 }