Skip to content

Commit

Permalink
git/e2e: run initial push operations inside Eventually()
Browse files Browse the repository at this point in the history
GitHub sometimes fails to push things using SSH due to weird and
mysterious deploy key errors, like
"unknown error: ERROR: Unknown public SSH key".

As a workaround, the intial push operation for each test case is
retried on failure for 20 seconds.

Signed-off-by: Sanskar Jaiswal <[email protected]>
  • Loading branch information
aryan9600 committed Aug 3, 2023
1 parent 1152551 commit 926f56f
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions git/internal/e2e/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ import (

var letterRunes = []rune("abcdefghijklmnopqrstuvwxyz1234567890")

const timeout = time.Second * 20

func testUsingClone(g *WithT, client repository.Client, repoURL *url.URL, upstreamRepo upstreamRepoInfo) {
// clone repo
_, err := client.Clone(context.TODO(), repoURL.String(), repository.CloneConfig{
Expand All @@ -62,8 +64,16 @@ func testUsingClone(g *WithT, client repository.Client, repoURL *url.URL, upstre
)
g.Expect(err).ToNot(HaveOccurred(), "first commit")

err = client.Push(context.TODO(), repository.PushConfig{})
g.Expect(err).ToNot(HaveOccurred())
// GitHub sometimes takes a long time to propogate its deploy key and this leads
// to mysterious push errors like "unknown error: ERROR: Unknown public SSH key".
// This helps us get around that by retrying for a fixed amount of time.
g.Eventually(func() bool {
err = client.Push(context.TODO(), repository.PushConfig{})
if err != nil {
return false
}
return true
}, timeout).Should(BeTrue())

headCommit, _, err := headCommitWithBranch(upstreamRepo.url, "main", upstreamRepo.username, upstreamRepo.password)
g.Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -120,8 +130,13 @@ func testUsingInit(g *WithT, client repository.Client, repoURL *url.URL, upstrea
)
g.Expect(err).ToNot(HaveOccurred(), "first commit")

err = client.Push(context.TODO(), repository.PushConfig{})
g.Expect(err).ToNot(HaveOccurred())
g.Eventually(func() bool {
err = client.Push(context.TODO(), repository.PushConfig{})
if err != nil {
return false
}
return true
}, timeout).Should(BeTrue())

headCommit, _, err := headCommitWithBranch(upstreamRepo.url, "main", upstreamRepo.username, upstreamRepo.password)
g.Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -157,6 +172,7 @@ func testUsingInit(g *WithT, client repository.Client, repoURL *url.URL, upstrea
g.Expect(err).ToNot(HaveOccurred(), "third commit")
err = client.Push(context.TODO(), repository.PushConfig{})
g.Expect(err).ToNot(HaveOccurred())

headCommit, _, err = headCommitWithBranch(upstreamRepo.url, "new", upstreamRepo.username, upstreamRepo.password)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(headCommit).To(Equal(cc))
Expand Down

0 comments on commit 926f56f

Please sign in to comment.