From 9c645088bf2dc7baea950f39d11ceb02f5eb9721 Mon Sep 17 00:00:00 2001
From: Jesse Duffield <jessedduffield@gmail.com>
Date: Sat, 25 Feb 2023 21:33:52 +1100
Subject: [PATCH] give CI longer wait times before failing assertions

---
 .github/workflows/ci.yml                       |  3 ++-
 pkg/integration/components/assertion_helper.go | 13 +++++++++++--
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index d09b8a53a..646fdde7f 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -98,8 +98,9 @@ jobs:
           restore-keys: |
             ${{runner.os}}-go-
       - name: Test code
+        # LONG_WAIT_BEFORE_FAIL means that for a given test assertion, we'll wait longer before failing
         run: |
-          go test pkg/integration/clients/*.go
+          LONG_WAIT_BEFORE_FAIL=true go test pkg/integration/clients/*.go
   build:
     runs-on: ubuntu-latest
     env:
diff --git a/pkg/integration/components/assertion_helper.go b/pkg/integration/components/assertion_helper.go
index 23539a8d3..b60bda17b 100644
--- a/pkg/integration/components/assertion_helper.go
+++ b/pkg/integration/components/assertion_helper.go
@@ -1,6 +1,7 @@
 package components
 
 import (
+	"os"
 	"time"
 
 	integrationTypes "github.com/jesseduffield/lazygit/pkg/integration/types"
@@ -11,7 +12,15 @@ type assertionHelper struct {
 }
 
 // milliseconds we'll wait when an assertion fails.
-var retryWaitTimes = []int{0, 1, 1, 1, 1, 1, 5, 10, 20, 40, 100, 200, 500, 1000, 2000, 4000}
+func retryWaitTimes() []int {
+	if os.Getenv("LONG_WAIT_BEFORE_FAIL") == "true" {
+		// CI has limited hardware, may be throttled, runs tests in parallel, etc, so we
+		// give it more leeway compared to when we're running things locally.
+		return []int{0, 1, 1, 1, 1, 1, 5, 10, 20, 40, 100, 200, 500, 1000, 2000, 4000}
+	} else {
+		return []int{0, 1, 1, 1, 1, 1, 5, 10, 20, 40, 100}
+	}
+}
 
 func (self *assertionHelper) matchString(matcher *Matcher, context string, getValue func() string) {
 	self.assertWithRetries(func() (bool, string) {
@@ -22,7 +31,7 @@ func (self *assertionHelper) matchString(matcher *Matcher, context string, getVa
 
 func (self *assertionHelper) assertWithRetries(test func() (bool, string)) {
 	var message string
-	for _, waitTime := range retryWaitTimes {
+	for _, waitTime := range retryWaitTimes() {
 		time.Sleep(time.Duration(waitTime) * time.Millisecond)
 
 		var ok bool