Advertisement
Guest User

Untitled

a guest
May 28th, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. [Serializable]
  2. [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly,
  3. AllowMultiple = false)]
  4. [MulticastAttributeUsage(MulticastTargets.Method)]
  5. public class InjectLatencyAttribute : OnMethodBoundaryAspect
  6. {
  7. Random random = new Random((int)DateTime.UtcNow.Ticks);
  8.  
  9. public override void OnEntry(MethodExecutionArgs args)
  10. {
  11. // you need a mechanism to turn latency injection, preferably via a
  12. // configuration mechanism that allows you to update on the fly
  13. if (LatencyInjectionConfig.Enabled)
  14. {
  15. var lagSeconds = random.Next(LatencyInjectionConfig.MaxLatencyLagSeconds);
  16. var latencyLag = TimeSpan.FromSeconds(lagSeconds);
  17. Thread.Sleep(latencyLag);
  18. }
  19.  
  20. // execute the underlying method
  21. base.OnEntry(args);
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement