Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Serializable]
- [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly,
- AllowMultiple = false)]
- [MulticastAttributeUsage(MulticastTargets.Method)]
- public class InjectLatencyAttribute : OnMethodBoundaryAspect
- {
- Random random = new Random((int)DateTime.UtcNow.Ticks);
- public override void OnEntry(MethodExecutionArgs args)
- {
- // you need a mechanism to turn latency injection, preferably via a
- // configuration mechanism that allows you to update on the fly
- if (LatencyInjectionConfig.Enabled)
- {
- var lagSeconds = random.Next(LatencyInjectionConfig.MaxLatencyLagSeconds);
- var latencyLag = TimeSpan.FromSeconds(lagSeconds);
- Thread.Sleep(latencyLag);
- }
- // execute the underlying method
- base.OnEntry(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement