tests: remove unnecessary cache clearing

This PR removes all remaining unnecessary cache clearing in tests
from the codebase since we now clear all cachable classes between
tests making this functionally unnecessary.

Original PR to automatically clear caches:
- https://github.com/Homebrew/brew/pull/16746

I also moved the `Utils::Analytics` module to use cachable so
that we don't have to clear caches specifically in tests anymore.
This commit is contained in:
apainintheneck 2024-03-31 18:38:03 -07:00
parent 9ae51618b9
commit 226239da4c
7 changed files with 4 additions and 27 deletions

View File

@ -7,8 +7,6 @@ RSpec.describe Homebrew::API::Cask do
before do before do
stub_const("Homebrew::API::HOMEBREW_CACHE_API", cache_dir) stub_const("Homebrew::API::HOMEBREW_CACHE_API", cache_dir)
Homebrew::API.clear_cache
described_class.clear_cache
end end
def mock_curl_download(stdout:) def mock_curl_download(stdout:)

View File

@ -7,7 +7,6 @@ RSpec.describe Homebrew::API::Formula do
before do before do
stub_const("Homebrew::API::HOMEBREW_CACHE_API", cache_dir) stub_const("Homebrew::API::HOMEBREW_CACHE_API", cache_dir)
described_class.clear_cache
end end
def mock_curl_download(stdout:) def mock_curl_download(stdout:)

View File

@ -44,12 +44,6 @@ RSpec.describe "Internal Tap JSON -- Formula" do
# To allow `formula_names.txt` to be written to the cache. # To allow `formula_names.txt` to be written to the cache.
(HOMEBREW_CACHE/"api").mkdir (HOMEBREW_CACHE/"api").mkdir
Homebrew::API::Formula.clear_cache
end
after do
Homebrew::API::Formula.clear_cache
end end
it "loads tap aliases" do it "loads tap aliases" do

View File

@ -8,10 +8,6 @@ RSpec.describe Homebrew::API do
let(:json_hash) { JSON.parse(json) } let(:json_hash) { JSON.parse(json) }
let(:json_invalid) { '{"foo":"bar"' } let(:json_invalid) { '{"foo":"bar"' }
before do
described_class.clear_cache
end
def mock_curl_output(stdout: "", success: true) def mock_curl_output(stdout: "", success: true)
curl_output = instance_double(SystemCommand::Result, stdout:, success?: success) curl_output = instance_double(SystemCommand::Result, stdout:, success?: success)
allow(Utils::Curl).to receive(:curl_output).and_return curl_output allow(Utils::Curl).to receive(:curl_output).and_return curl_output

View File

@ -81,8 +81,6 @@ RSpec.describe Formulary do
end end
context "with sharded Formula directory" do context "with sharded Formula directory" do
before { CoreTap.instance.clear_cache }
let(:formula_name) { "testball_sharded" } let(:formula_name) { "testball_sharded" }
let(:formula_path) do let(:formula_path) do
core_tap = CoreTap.instance core_tap = CoreTap.instance
@ -236,7 +234,6 @@ RSpec.describe Formulary do
before do before do
alias_dir.mkpath alias_dir.mkpath
FileUtils.ln_s formula_path, alias_path FileUtils.ln_s formula_path, alias_path
tap.clear_cache
end end
it "returns a Formula when given a name" do it "returns a Formula when given a name" do

View File

@ -4,10 +4,6 @@ require "utils/analytics"
require "formula_installer" require "formula_installer"
RSpec.describe Utils::Analytics do RSpec.describe Utils::Analytics do
before do
described_class.clear_cache
end
describe "::default_package_tags" do describe "::default_package_tags" do
let(:ci) { ", CI" if ENV["CI"] } let(:ci) { ", CI" if ENV["CI"] }

View File

@ -16,6 +16,8 @@ module Utils
INFLUX_HOST = "https://eu-central-1-1.aws.cloud2.influxdata.com" INFLUX_HOST = "https://eu-central-1-1.aws.cloud2.influxdata.com"
INFLUX_ORG = "d81a3e6d582d485f" INFLUX_ORG = "d81a3e6d582d485f"
extend Cachable
class << self class << self
include Context include Context
@ -277,14 +279,9 @@ module Utils
nil nil
end end
def clear_cache
remove_instance_variable(:@default_package_tags) if instance_variable_defined?(:@default_package_tags)
remove_instance_variable(:@default_package_fields) if instance_variable_defined?(:@default_package_fields)
end
sig { returns(T::Hash[Symbol, String]) } sig { returns(T::Hash[Symbol, String]) }
def default_package_tags def default_package_tags
@default_package_tags ||= begin cache[:default_package_tags] ||= begin
# Only display default prefixes to reduce cardinality and improve privacy # Only display default prefixes to reduce cardinality and improve privacy
prefix = Homebrew.default_prefix? ? HOMEBREW_PREFIX.to_s : "custom-prefix" prefix = Homebrew.default_prefix? ? HOMEBREW_PREFIX.to_s : "custom-prefix"
@ -305,7 +302,7 @@ module Utils
# remove macOS patch release # remove macOS patch release
sig { returns(T::Hash[Symbol, String]) } sig { returns(T::Hash[Symbol, String]) }
def default_package_fields def default_package_fields
@default_package_fields ||= begin cache[:default_package_fields] ||= begin
version = if (match_data = HOMEBREW_VERSION.match(/^[\d.]+/)) version = if (match_data = HOMEBREW_VERSION.match(/^[\d.]+/))
suffix = "-dev" if HOMEBREW_VERSION.include?("-") suffix = "-dev" if HOMEBREW_VERSION.include?("-")
match_data[0] + suffix.to_s match_data[0] + suffix.to_s