Skip to content

repo-updater: Fix flaky test & make Github client consistent

Warren Gifford requested to merge core/fix-flaky-test into master

Created by: mrnugget

This fixes #4002 (closed) by clearing the Redis cache, that's used by the underlying github.Client, before running the tests.

The flaky test failed because sometimes the error returned by the GithubSource (which uses the github.Client) was the generic github.APIError "request to xxx resulted in 404" error message that we expect in the tests:

https://github.com/sourcegraph/sourcegraph/blob/9ecfe95dd5ea073dc05cd6ea962e4e588829d767/cmd/repo-updater/repos/sources_test.go#L793

And sometimes it returned the github.ErrNotFound error:

https://github.com/sourcegraph/sourcegraph/blob/9ecfe95dd5ea073dc05cd6ea962e4e588829d767/pkg/extsvc/github/client.go#L308

I found out that the ErrNotFound error is only returned when the Github client looked into the cache and found a "repository not found"-cache-entry there: https://github.com/sourcegraph/sourcegraph/blob/9ecfe95dd5ea073dc05cd6ea962e4e588829d767/pkg/extsvc/github/repos.go#L139-L145

But if there is no cache hit, then the no ErrNotFound is ever returned. Neither in the getRepositoryFromAPI method: https://github.com/sourcegraph/sourcegraph/blob/9ecfe95dd5ea073dc05cd6ea962e4e588829d767/pkg/extsvc/github/repos.go#L253-L256

Nor in underlying method where the response is turned into a github.APIError:

https://github.com/sourcegraph/sourcegraph/blob/9ecfe95dd5ea073dc05cd6ea962e4e588829d767/pkg/extsvc/github/client.go#L219-L227

So, I did two things in this PR:

  1. Clear the cache before we run the tests
  2. Make sure getRepositoryFromAPI checks the status code and if it's a 404 it also returns ErrNotFound

Test plan: go test && running the tests on CI

Merge request reports

Loading