LongRunningTest skips the test if running in -short mode, and logs if the test completed quickly under other circumstances.
(t *testing.T)
| 876 | |
| 877 | // LongRunningTest skips the test if running in -short mode, and logs if the test completed quickly under other circumstances. |
| 878 | func LongRunningTest(t *testing.T) { |
| 879 | const ( |
| 880 | shortTestThreshold = time.Second |
| 881 | ) |
| 882 | if testing.Short() { |
| 883 | t.Skip("skipping long running test in short mode") |
| 884 | return |
| 885 | } |
| 886 | start := time.Now() |
| 887 | t.Cleanup(func() { |
| 888 | testDuration := time.Since(start) |
| 889 | if !t.Failed() && !t.Skipped() && testDuration < shortTestThreshold { |
| 890 | t.Logf("TEST: %q was marked as long running, but finished in %v (less than %v) - consider removing LongRunningTest", t.Name(), testDuration, shortTestThreshold) |
| 891 | } |
| 892 | }) |
| 893 | } |
| 894 | |
| 895 | func AssertTimeGreaterThan(t *testing.T, e1, e2 time.Time, msgAndArgs ...interface{}) bool { |
| 896 | return AssertTimestampGreaterThan(t, e1.UnixNano(), e2.UnixNano(), msgAndArgs...) |