DEV: Speed up /admin/docker/repos.json spec (#237)

Requesting /admin/docker/repos.json with a lot of plugins installed can
take a lot of time because of the large number of calls to the 'git'
CLI that are used to retrieve various information about the plugin
(eg. branch, latest commit, remote URL, etc).

This is not a problem in production because of memoization and the
much lower number of installed plugins, but it is a problem in test
environment where specs requesting this page can take 10+ seconds with
~100 installed plugins.

This commit speeds up by stubbing the `find_all` method to return only
the first few repositories.
This commit is contained in:
Bianca Nenciu 2024-09-04 13:58:00 +03:00 committed by GitHub
parent f16f400b33
commit 3a43aa6be7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 0 deletions

View File

@ -38,6 +38,12 @@ RSpec.describe DockerManager::AdminController do
end
describe "#repos" do
before do
# Return only the first 3 repos to reduce the number of calls to 'git' CLI
repos = DockerManager::GitRepo.find_all
DockerManager::GitRepo.stubs(:find_all).returns(repos[0...3])
end
it "should return the right response" do
sign_in(Fabricate(:admin))