repo-updater: Fix flaky test & make Github client consistent
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:
And sometimes it returned the github.ErrNotFound
error:
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
:
So, I did two things in this PR:
- Clear the cache before we run the tests
- Make sure
getRepositoryFromAPI
checks the status code and if it's a 404 it also returnsErrNotFound
Test plan: go test && running the tests on CI