+/// Provide tests with the ability to find out how much time they have to run before being timed out.
+public class TestTimeout
+{
+ private TimeSpan Timeout { get; }
+
+ private DateTime StartTime { get; }
+
+ public bool HaveTimeLeft { get { return DateTime.UtcNow - StartTime < Timeout; } }
+
+ public static bool IsStressTest { get { return Environment.GetEnvironmentVariable("MONO_TESTS_STRESS") == "1"; } }
+
+ private TestTimeout (TimeSpan timeout)
+ {
+ Timeout = timeout;
+ StartTime = DateTime.UtcNow;
+ }
+
+ public static TestTimeout Start(TimeSpan timeout)
+ {
+ if (timeout.Ticks < 0)
+ {
+ throw new ArgumentException("timeout");
+ }
+
+ return new TestTimeout(timeout);
+ }
+}