File: record_sync_context_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (32 lines) | stat: -rw-r--r-- 1,065 bytes parent folder | download
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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ClickHouse::RecordSyncContext, feature_category: :value_stream_management do
  let(:records) { [Issue.new(id: 1), Issue.new(id: 2), Issue.new(id: 3), Issue.new(id: 4)] }

  subject(:sync_context) { described_class.new(last_record_id: 0, max_records_per_batch: 3) }

  it 'allows processing 3 records per batch' do
    records.take(3).each do |record|
      sync_context.last_processed_id = record.id
    end

    expect(sync_context).to be_record_limit_reached
    expect(sync_context.last_processed_id).to eq(3)

    expect { sync_context.new_batch! }.to change { sync_context.record_count_in_current_batch }.from(3).to(0)

    expect(sync_context).not_to be_record_limit_reached

    records.take(3).each do |record|
      sync_context.last_processed_id = record.id
    end

    expect(sync_context).to be_record_limit_reached
  end

  it 'sets the no more records flag' do
    expect { sync_context.no_more_records! }.to change { sync_context.no_more_records? }.from(false).to(true)
  end
end