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

client_pool_spec.rb « github_import « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: aabb47c2cf1f642fe6f90493e727ae9ea5a68b5d (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::GithubImport::ClientPool, feature_category: :importers do
  subject(:pool) { described_class.new(token_pool: %w[foo bar], per_page: 1, parallel: true) }

  describe '#best_client' do
    it 'returns the client with the most remaining requests' do
      allow(Gitlab::GithubImport::Client).to receive(:new).and_return(
        instance_double(
          Gitlab::GithubImport::Client,
          requests_remaining?: true, remaining_requests: 10, rate_limit_resets_in: 1
        ),
        instance_double(
          Gitlab::GithubImport::Client,
          requests_remaining?: true, remaining_requests: 20, rate_limit_resets_in: 2
        )
      )

      expect(pool.best_client.remaining_requests).to eq(20)
    end

    context 'when all clients are rate limited' do
      it 'returns the client with the closest rate limit reset time' do
        allow(Gitlab::GithubImport::Client).to receive(:new).and_return(
          instance_double(
            Gitlab::GithubImport::Client,
            requests_remaining?: false, remaining_requests: 10, rate_limit_resets_in: 10
          ),
          instance_double(
            Gitlab::GithubImport::Client,
            requests_remaining?: false, remaining_requests: 20, rate_limit_resets_in: 20
          )
        )

        expect(pool.best_client.rate_limit_resets_in).to eq(10)
      end
    end
  end
end