diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-31 15:11:01 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-31 15:11:01 +0300 |
commit | f52f8542b47c9e00ddf420abaf2263de168988f9 (patch) | |
tree | 568225882da5cc4deb746d2d4fc362c6076fb708 /spec/lib | |
parent | 6a5ef9b75d38f39cd2a6a2392fadfbd3b966b884 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/ci/yaml_processor/dag_spec.rb | 12 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/yaml_processor_spec.rb | 17 | ||||
-rw-r--r-- | spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb | 88 | ||||
-rw-r--r-- | spec/lib/gitlab/usage_data_counters/redis_counter_spec.rb | 48 |
4 files changed, 72 insertions, 93 deletions
diff --git a/spec/lib/gitlab/ci/yaml_processor/dag_spec.rb b/spec/lib/gitlab/ci/yaml_processor/dag_spec.rb index d688937f997..3c1e0264ff1 100644 --- a/spec/lib/gitlab/ci/yaml_processor/dag_spec.rb +++ b/spec/lib/gitlab/ci/yaml_processor/dag_spec.rb @@ -23,9 +23,19 @@ RSpec.describe Gitlab::Ci::YamlProcessor::Dag do { 'job_a' => %w[job_c], 'job_b' => %w[job_a], 'job_c' => %w[job_b] } end - it 'raises TSort::Cyclic' do + it 'raises TSort::Cyclic error' do expect { result }.to raise_error(TSort::Cyclic, /topological sort failed/) end + + context 'when a job has a self-dependency' do + let(:nodes) do + { 'job_a' => %w[job_a] } + end + + it 'raises TSort::Cyclic error' do + expect { result }.to raise_error(TSort::Cyclic, /topological sort failed/) + end + end end context 'when there are some missing jobs' do diff --git a/spec/lib/gitlab/ci/yaml_processor_spec.rb b/spec/lib/gitlab/ci/yaml_processor_spec.rb index 615a0098a4d..326515883b2 100644 --- a/spec/lib/gitlab/ci/yaml_processor_spec.rb +++ b/spec/lib/gitlab/ci/yaml_processor_spec.rb @@ -3434,6 +3434,23 @@ module Gitlab end it_behaves_like 'returns errors', 'The pipeline has circular dependencies' + + context 'when a job has a self-dependency' do + let(:config) do + <<~YAML + job_0: + stage: test + script: build + + job: + stage: test + script: build + needs: [job_0, job] + YAML + end + + it_behaves_like 'returns errors', 'The pipeline has circular dependencies' + end end end diff --git a/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb index 7bef14d5f7a..a7dc0b6a060 100644 --- a/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb +++ b/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb @@ -113,73 +113,57 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s end end - context 'when usage_ping is disabled' do - it 'does not track the event' do - allow(::ServicePing::ServicePingSettings).to receive(:enabled?).and_return(false) + it 'tracks event when using symbol' do + expect(Gitlab::Redis::HLL).to receive(:add) - described_class.track_event(weekly_event, values: entity1, time: Date.current) - - expect(Gitlab::Redis::HLL).not_to receive(:add) - end + described_class.track_event(:g_analytics_contribution, values: entity1) end - context 'when usage_ping is enabled' do - before do - allow(::ServicePing::ServicePingSettings).to receive(:enabled?).and_return(true) - end + it 'tracks events with multiple values' do + values = [entity1, entity2] + expect(Gitlab::Redis::HLL).to receive(:add).with(key: /g_analytics_contribution/, value: values, + expiry: described_class::KEY_EXPIRY_LENGTH) - it 'tracks event when using symbol' do - expect(Gitlab::Redis::HLL).to receive(:add) - - described_class.track_event(:g_analytics_contribution, values: entity1) - end - - it 'tracks events with multiple values' do - values = [entity1, entity2] - expect(Gitlab::Redis::HLL).to receive(:add).with(key: /g_analytics_contribution/, value: values, - expiry: described_class::KEY_EXPIRY_LENGTH) + described_class.track_event(:g_analytics_contribution, values: values) + end - described_class.track_event(:g_analytics_contribution, values: values) - end + it 'raise error if metrics of unknown event' do + expect { described_class.track_event('unknown', values: entity1, time: Date.current) }.to raise_error(Gitlab::UsageDataCounters::HLLRedisCounter::UnknownEvent) + end - it 'raise error if metrics of unknown event' do - expect { described_class.track_event('unknown', values: entity1, time: Date.current) }.to raise_error(Gitlab::UsageDataCounters::HLLRedisCounter::UnknownEvent) + context 'when Rails environment is production' do + before do + allow(Rails.env).to receive(:development?).and_return(false) + allow(Rails.env).to receive(:test?).and_return(false) end - context 'when Rails environment is production' do - before do - allow(Rails.env).to receive(:development?).and_return(false) - allow(Rails.env).to receive(:test?).and_return(false) - end - - it 'reports only UnknownEvent exception' do - expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception) - .with(Gitlab::UsageDataCounters::HLLRedisCounter::UnknownEvent) - .once - .and_call_original + it 'reports only UnknownEvent exception' do + expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception) + .with(Gitlab::UsageDataCounters::HLLRedisCounter::UnknownEvent) + .once + .and_call_original - expect { described_class.track_event('unknown', values: entity1, time: Date.current) }.not_to raise_error - end + expect { described_class.track_event('unknown', values: entity1, time: Date.current) }.not_to raise_error end + end - it 'reports an error if Feature.enabled raise an error' do - expect(Feature).to receive(:enabled?).and_raise(StandardError.new) - expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception) + it 'reports an error if Feature.enabled raise an error' do + expect(Feature).to receive(:enabled?).and_raise(StandardError.new) + expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception) - described_class.track_event(:g_analytics_contribution, values: entity1, time: Date.current) - end + described_class.track_event(:g_analytics_contribution, values: entity1, time: Date.current) + end - context 'for weekly events' do - it 'sets the keys in Redis to expire' do - described_class.track_event("g_compliance_dashboard", values: entity1) + context 'for weekly events' do + it 'sets the keys in Redis to expire' do + described_class.track_event("g_compliance_dashboard", values: entity1) - Gitlab::Redis::SharedState.with do |redis| - keys = redis.scan_each(match: "{#{described_class::REDIS_SLOT}}_g_compliance_dashboard-*").to_a - expect(keys).not_to be_empty + Gitlab::Redis::SharedState.with do |redis| + keys = redis.scan_each(match: "{#{described_class::REDIS_SLOT}}_g_compliance_dashboard-*").to_a + expect(keys).not_to be_empty - keys.each do |key| - expect(redis.ttl(key)).to be_within(5.seconds).of(described_class::KEY_EXPIRY_LENGTH) - end + keys.each do |key| + expect(redis.ttl(key)).to be_within(5.seconds).of(described_class::KEY_EXPIRY_LENGTH) end end end diff --git a/spec/lib/gitlab/usage_data_counters/redis_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/redis_counter_spec.rb index 753e09731bf..39d48b7b938 100644 --- a/spec/lib/gitlab/usage_data_counters/redis_counter_spec.rb +++ b/spec/lib/gitlab/usage_data_counters/redis_counter_spec.rb @@ -7,51 +7,19 @@ RSpec.describe Gitlab::UsageDataCounters::RedisCounter, :clean_gitlab_redis_shar subject { Class.new.extend(described_class) } - before do - allow(::ServicePing::ServicePingSettings).to receive(:enabled?).and_return(service_ping_enabled) - end - describe '.increment' do - context 'when usage_ping is disabled' do - let(:service_ping_enabled) { false } - - it 'counter is not increased' do - expect do - subject.increment(redis_key) - end.not_to change { subject.total_count(redis_key) } - end - end - - context 'when usage_ping is enabled' do - let(:service_ping_enabled) { true } - - it 'counter is increased' do - expect do - subject.increment(redis_key) - end.to change { subject.total_count(redis_key) }.by(1) - end + it 'counter is increased' do + expect do + subject.increment(redis_key) + end.to change { subject.total_count(redis_key) }.by(1) end end describe '.increment_by' do - context 'when usage_ping is disabled' do - let(:service_ping_enabled) { false } - - it 'counter is not increased' do - expect do - subject.increment_by(redis_key, 3) - end.not_to change { subject.total_count(redis_key) } - end - end - - context 'when usage_ping is enabled' do - let(:service_ping_enabled) { true } - - it 'counter is increased' do - expect do - subject.increment_by(redis_key, 3) - end.to change { subject.total_count(redis_key) }.by(3) - end + it 'counter is increased' do + expect do + subject.increment_by(redis_key, 3) + end.to change { subject.total_count(redis_key) }.by(3) end end end |