Commit 2aa4570a authored by Nicolas Dular's avatar Nicolas Dular

Stop overriding tracking check in experiment stub

With `gitlab-experiment` 0.5.2 a bug got fixed where stubbing
experiments in tests didn't work. With that fix, we can get rid of
overriding the `should_track?` method to always return true, since
we can now rely on the actual implemention, where it can exclude
actors.
parent 6abd47a3
...@@ -8,36 +8,42 @@ RSpec.describe EmptyRepoUploadExperiment, :experiment do ...@@ -8,36 +8,42 @@ RSpec.describe EmptyRepoUploadExperiment, :experiment do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
describe '#track_initial_write' do describe '#track_initial_write' do
it "tracks an event for the first commit on a project" do context 'when experiment is turned on' do
expect(subject).to receive(:commit_count_for).with(project, max_count: described_class::INITIAL_COMMIT_COUNT, experiment: 'empty_repo_upload').and_return(1) before do
stub_experiments(empty_repo_upload: :control)
end
expect(subject).to receive(:track).with(:initial_write, project: project).and_call_original it "tracks an event for the first commit on a project" do
expect(subject).to receive(:commit_count_for).with(project, max_count: described_class::INITIAL_COMMIT_COUNT, experiment: 'empty_repo_upload').and_return(1)
subject.track_initial_write expect(subject).to receive(:track).with(:initial_write, project: project).and_call_original
end
it "doesn't track an event for projects with a commit count more than 1" do subject.track_initial_write
expect(subject).to receive(:commit_count_for).and_return(2) end
expect(subject).not_to receive(:track) it "doesn't track an event for projects with a commit count more than 1" do
expect(subject).to receive(:commit_count_for).and_return(2)
subject.track_initial_write expect(subject).not_to receive(:track)
end
it "doesn't track when we generally shouldn't" do subject.track_initial_write
allow(subject).to receive(:should_track?).and_return(false) end
expect(subject).not_to receive(:track) it "doesn't track if the project is older" do
expect(project).to receive(:created_at).and_return(described_class::TRACKING_START_DATE - 1.minute)
subject.track_initial_write expect(subject).not_to receive(:track)
end
it "doesn't track if the project is older" do subject.track_initial_write
expect(project).to receive(:created_at).and_return(described_class::TRACKING_START_DATE - 1.minute) end
end
expect(subject).not_to receive(:track) context 'when experiment is turned off' do
it "doesn't track when we generally shouldn't" do
expect(subject).not_to receive(:track)
subject.track_initial_write subject.track_initial_write
end
end end
end end
end end
...@@ -29,6 +29,10 @@ RSpec.describe NewProjectReadmeExperiment, :experiment do ...@@ -29,6 +29,10 @@ RSpec.describe NewProjectReadmeExperiment, :experiment do
context "when tracking initial writes" do context "when tracking initial writes" do
let!(:project) { create(:project, :repository) } let!(:project) { create(:project, :repository) }
before do
stub_experiments(new_project_readme: :control)
end
it "tracks an event for the first commit on a project with a repository" do it "tracks an event for the first commit on a project with a repository" do
expect(subject).to receive(:commit_count_for).with(project, default_count: described_class::INITIAL_WRITE_LIMIT, max_count: described_class::INITIAL_WRITE_LIMIT, experiment: 'new_project_readme').and_return(1) expect(subject).to receive(:commit_count_for).with(project, default_count: described_class::INITIAL_WRITE_LIMIT, max_count: described_class::INITIAL_WRITE_LIMIT, experiment: 'new_project_readme').and_return(1)
expect(subject).to receive(:track).with(:write, property: project.created_at.to_s, value: 1).and_call_original expect(subject).to receive(:track).with(:write, property: project.created_at.to_s, value: 1).and_call_original
......
...@@ -12,10 +12,6 @@ class ApplicationExperiment # rubocop:disable Gitlab/NamespacedClass ...@@ -12,10 +12,6 @@ class ApplicationExperiment # rubocop:disable Gitlab/NamespacedClass
super(...) super(...)
Feature.persist_used!(feature_flag_name) Feature.persist_used!(feature_flag_name)
end end
def should_track?
true
end
end end
RSpec.configure do |config| RSpec.configure do |config|
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment