Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/experiments')
-rw-r--r--spec/experiments/application_experiment_spec.rb6
-rw-r--r--spec/experiments/concerns/project_commit_count_spec.rb41
-rw-r--r--spec/experiments/empty_repo_upload_experiment_spec.rb49
-rw-r--r--spec/experiments/in_product_guidance_environments_webide_experiment_spec.rb22
-rw-r--r--spec/experiments/members/invite_email_experiment_spec.rb10
-rw-r--r--spec/experiments/new_project_readme_experiment_spec.rb22
6 files changed, 132 insertions, 18 deletions
diff --git a/spec/experiments/application_experiment_spec.rb b/spec/experiments/application_experiment_spec.rb
index 424a3af20a3..2ff16604c33 100644
--- a/spec/experiments/application_experiment_spec.rb
+++ b/spec/experiments/application_experiment_spec.rb
@@ -25,6 +25,12 @@ RSpec.describe ApplicationExperiment, :experiment do
described_class.new('namespaced/stub')
end
+ it "doesn't raise an exception without a defined control" do
+ # because we have a default behavior defined
+
+ expect { experiment('namespaced/stub') { } }.not_to raise_error
+ end
+
describe "enabled" do
before do
allow(subject).to receive(:enabled?).and_call_original
diff --git a/spec/experiments/concerns/project_commit_count_spec.rb b/spec/experiments/concerns/project_commit_count_spec.rb
new file mode 100644
index 00000000000..5616f167cb4
--- /dev/null
+++ b/spec/experiments/concerns/project_commit_count_spec.rb
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe ProjectCommitCount do
+ let(:klass) { Class.include(ProjectCommitCount) }
+ let(:instance) { klass.new }
+
+ describe '#commit_count_for' do
+ subject { instance.commit_count_for(project, default_count: 42, caller_info: :identifiable) }
+
+ let(:project) { create(:project, :repository) }
+
+ context 'when a root_ref exists' do
+ it 'returns commit count from GitlayClient' do
+ allow(Gitlab::GitalyClient).to receive(:call).and_call_original
+ allow(Gitlab::GitalyClient).to receive(:call).with(anything, :commit_service, :count_commits, anything, anything)
+ .and_return(double(count: 4))
+
+ expect(subject).to eq(4)
+ end
+ end
+
+ context 'when a root_ref does not exist' do
+ let(:project) { create(:project, :empty_repo) }
+
+ it 'returns the default_count' do
+ expect(subject).to eq(42)
+ end
+ end
+
+ it "handles exceptions by logging them with exception_details and returns the default_count" do
+ allow(Gitlab::GitalyClient).to receive(:call).and_call_original
+ allow(Gitlab::GitalyClient).to receive(:call).with(anything, :commit_service, :count_commits, anything, anything).and_raise(e = StandardError.new('_message_'))
+
+ expect(Gitlab::ErrorTracking).to receive(:track_exception).with(e, caller_info: :identifiable)
+
+ expect(subject).to eq(42)
+ end
+ end
+end
diff --git a/spec/experiments/empty_repo_upload_experiment_spec.rb b/spec/experiments/empty_repo_upload_experiment_spec.rb
new file mode 100644
index 00000000000..10cbedbe8ba
--- /dev/null
+++ b/spec/experiments/empty_repo_upload_experiment_spec.rb
@@ -0,0 +1,49 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe EmptyRepoUploadExperiment, :experiment do
+ subject { described_class.new(project: project) }
+
+ let(:project) { create(:project, :repository) }
+
+ describe '#track_initial_write' do
+ context 'when experiment is turned on' do
+ before do
+ stub_experiments(empty_repo_upload: :control)
+ end
+
+ 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)
+
+ expect(subject).to receive(:track).with(:initial_write, project: project).and_call_original
+
+ subject.track_initial_write
+ end
+
+ 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)
+
+ expect(subject).not_to receive(:track)
+
+ subject.track_initial_write
+ end
+
+ 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)
+
+ expect(subject).not_to receive(:track)
+
+ subject.track_initial_write
+ end
+ end
+
+ 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
+ end
+ end
+ end
+end
diff --git a/spec/experiments/in_product_guidance_environments_webide_experiment_spec.rb b/spec/experiments/in_product_guidance_environments_webide_experiment_spec.rb
new file mode 100644
index 00000000000..d616672173e
--- /dev/null
+++ b/spec/experiments/in_product_guidance_environments_webide_experiment_spec.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe InProductGuidanceEnvironmentsWebideExperiment, :experiment do
+ subject { described_class.new(project: project) }
+
+ let(:project) { create(:project, :repository) }
+
+ before do
+ stub_experiments(in_product_guidance_environments_webide: :candidate)
+ end
+
+ it 'excludes projects with environments' do
+ create(:environment, project: project)
+ expect(subject).to exclude(project: project)
+ end
+
+ it 'does not exlude projects without environments' do
+ expect(subject).not_to exclude(project: project)
+ end
+end
diff --git a/spec/experiments/members/invite_email_experiment_spec.rb b/spec/experiments/members/invite_email_experiment_spec.rb
index a9a269347e0..ac4c05e3058 100644
--- a/spec/experiments/members/invite_email_experiment_spec.rb
+++ b/spec/experiments/members/invite_email_experiment_spec.rb
@@ -11,6 +11,16 @@ RSpec.describe Members::InviteEmailExperiment, :clean_gitlab_redis_shared_state
allow(invite_email).to receive(:enabled?).and_return(true)
end
+ describe ".initial_invite_email?" do
+ it "is an initial invite email" do
+ expect(described_class.initial_invite_email?('initial_email')).to be(true)
+ end
+
+ it "is not an initial invite email" do
+ expect(described_class.initial_invite_email?('_bogus_')).to be(false)
+ end
+ end
+
describe "exclusions", :experiment do
it "excludes when created by is nil" do
expect(experiment('members/invite_email')).to exclude(actor: double(created_by: nil))
diff --git a/spec/experiments/new_project_readme_experiment_spec.rb b/spec/experiments/new_project_readme_experiment_spec.rb
index 87446394bff..e5ecc4662f6 100644
--- a/spec/experiments/new_project_readme_experiment_spec.rb
+++ b/spec/experiments/new_project_readme_experiment_spec.rb
@@ -29,24 +29,19 @@ RSpec.describe NewProjectReadmeExperiment, :experiment do
context "when tracking initial writes" do
let!(:project) { create(:project, :repository) }
- def stub_gitaly_count(count = 1)
- allow(Gitlab::GitalyClient).to receive(:call).and_call_original
- allow(Gitlab::GitalyClient).to receive(:call).with(anything, :commit_service, :count_commits, anything, anything)
- .and_return(double(count: count))
- end
-
before do
- stub_gitaly_count
+ stub_experiments(new_project_readme: :control)
end
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(:track).with(:write, property: project.created_at.to_s, value: 1).and_call_original
subject.track_initial_writes(project)
end
it "tracks an event for the second commit on a project with a repository" do
- stub_gitaly_count(2)
+ allow(subject).to receive(:commit_count_for).and_return(2)
expect(subject).to receive(:track).with(:write, property: project.created_at.to_s, value: 2).and_call_original
@@ -54,7 +49,7 @@ RSpec.describe NewProjectReadmeExperiment, :experiment do
end
it "doesn't track if the repository has more then 2 commits" do
- stub_gitaly_count(3)
+ allow(subject).to receive(:commit_count_for).and_return(3)
expect(subject).not_to receive(:track)
@@ -76,14 +71,5 @@ RSpec.describe NewProjectReadmeExperiment, :experiment do
subject.track_initial_writes(project)
end
-
- it "handles exceptions by logging them" do
- allow(Gitlab::GitalyClient).to receive(:call).with(anything, :commit_service, :count_commits, anything, anything)
- .and_raise(e = StandardError.new('_message_'))
-
- expect(Gitlab::ErrorTracking).to receive(:track_exception).with(e, experiment: 'new_project_readme')
-
- subject.track_initial_writes(project)
- end
end
end