From 8977655869690f9ff0dab9f4632dbce984f936c9 Mon Sep 17 00:00:00 2001 From: nielash Date: Wed, 17 Apr 2024 05:24:41 -0400 Subject: [PATCH] bisync: avoid starting tests we don't have time to finish To prevent all-or-nothing retries, for tests that take longer (in total) than the -timeout but less than the -timeout * -maxtries https://github.com/rclone/rclone/pull/7743#issuecomment-2057250848 --- cmd/bisync/bisync_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmd/bisync/bisync_test.go b/cmd/bisync/bisync_test.go index 56708e50d..5824a5557 100644 --- a/cmd/bisync/bisync_test.go +++ b/cmd/bisync/bisync_test.go @@ -335,13 +335,23 @@ func testBisync(t *testing.T, path1, path2 string) { } } require.False(t, b.stopAt > 0 && len(testList) > 1, "-stop-at is meaningful only for a single test") + deadline, hasDeadline := t.Deadline() + var maxRunDuration time.Duration for _, testCase := range testList { testCase = strings.ReplaceAll(testCase, "-", "_") testCase = strings.TrimPrefix(testCase, "test_") t.Run(testCase, func(childTest *testing.T) { + startTime := time.Now() + remaining := time.Until(deadline) + if hasDeadline && (remaining < maxRunDuration || remaining < 10*time.Second) { // avoid starting tests we don't have time to finish + childTest.Fatalf("test %v timed out - not enough time to start test (%v remaining, need %v for test)", testCase, remaining, maxRunDuration) + } bCopy := *b bCopy.runTestCase(ctx, childTest, testCase) + if time.Since(startTime) > maxRunDuration { + maxRunDuration = time.Since(startTime) + } }) } }