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

worker_matcher_spec.rb « sidekiq_config « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 75e9c8c100b48bdc4fb0b109a7aebc77c119024c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# frozen_string_literal: true

require 'fast_spec_helper'
require 'rspec-parameterized'

RSpec.describe Gitlab::SidekiqConfig::WorkerMatcher do
  describe '#match?' do
    using RSpec::Parameterized::TableSyntax

    let(:worker_metadatas) do
      [
        {
          name: 'a',
          feature_category: :category_a,
          has_external_dependencies: false,
          urgency: :low,
          resource_boundary: :cpu,
          tags: [:no_disk_io, :git_access]
        },
        {
          name: 'a:2',
          feature_category: :category_a,
          has_external_dependencies: false,
          urgency: :high,
          resource_boundary: :none,
          tags: [:git_access]
        },
        {
          name: 'b',
          feature_category: :category_b,
          has_external_dependencies: true,
          urgency: :high,
          resource_boundary: :memory,
          tags: [:no_disk_io]
        },
        {
          name: 'c',
          feature_category: :category_c,
          has_external_dependencies: false,
          urgency: :throttled,
          resource_boundary: :memory,
          tags: []
        }
      ]
    end

    context 'with valid input' do
      where(:query, :expected_metadatas) do
        # feature_category
        'feature_category=category_a' | %w(a a:2)
        'feature_category=category_a,category_c' | %w(a a:2 c)
        'feature_category=category_a|feature_category=category_c' | %w(a a:2 c)
        'feature_category!=category_a' | %w(b c)

        # has_external_dependencies
        'has_external_dependencies=true' | %w(b)
        'has_external_dependencies=false' | %w(a a:2 c)
        'has_external_dependencies=true,false' | %w(a a:2 b c)
        'has_external_dependencies=true|has_external_dependencies=false' | %w(a a:2 b c)
        'has_external_dependencies!=true' | %w(a a:2 c)

        # urgency
        'urgency=high' | %w(a:2 b)
        'urgency=low' | %w(a)
        'urgency=high,low,throttled' | %w(a a:2 b c)
        'urgency=low|urgency=throttled' | %w(a c)
        'urgency!=high' | %w(a c)

        # name
        'name=a' | %w(a)
        'name=a,b' | %w(a b)
        'name=a,a:2|name=b' | %w(a a:2 b)
        'name!=a,a:2' | %w(b c)

        # resource_boundary
        'resource_boundary=memory' | %w(b c)
        'resource_boundary=memory,cpu' | %w(a b c)
        'resource_boundary=memory|resource_boundary=cpu' | %w(a b c)
        'resource_boundary!=memory,cpu' | %w(a:2)

        # tags
        'tags=no_disk_io' | %w(a b)
        'tags=no_disk_io,git_access' | %w(a a:2 b)
        'tags=no_disk_io|tags=git_access' | %w(a a:2 b)
        'tags=no_disk_io&tags=git_access' | %w(a)
        'tags!=no_disk_io' | %w(a:2 c)
        'tags!=no_disk_io,git_access' | %w(c)
        'tags=unknown_tag' | []
        'tags!=no_disk_io' | %w(a:2 c)
        'tags!=no_disk_io,git_access' | %w(c)
        'tags!=unknown_tag' | %w(a a:2 b c)

        # combinations
        'feature_category=category_a&urgency=high' | %w(a:2)
        'feature_category=category_a&urgency=high|feature_category=category_c' | %w(a:2 c)

        # Match all
        '*' | %w(a a:2 b c)
      end

      with_them do
        it do
          matched_metadatas = worker_metadatas.select do |metadata|
            described_class.new(query).match?(metadata)
          end
          expect(matched_metadatas.map { |m| m[:name] }).to match_array(expected_metadatas)
        end
      end
    end

    context 'with invalid input' do
      where(:query, :error) do
        'feature_category="category_a"' | described_class::InvalidTerm
        'feature_category=' | described_class::InvalidTerm
        'feature_category~category_a' | described_class::InvalidTerm
        'worker_name=a' | described_class::UnknownPredicate
      end

      with_them do
        it do
          worker_metadatas.each do |metadata|
            expect { described_class.new(query).match?(metadata) }
              .to raise_error(error)
          end
        end
      end
    end
  end
end