Sha256: baa4974bbcb8fee87364fd331668e50f2b2c5a4d35355306641023cd515279f3

Contents?: true

Size: 1.55 KB

Versions: 1

Compression:

Stored size: 1.55 KB

Contents

require 'spec_helper'

describe SnapCI::ParallelTests do
  include SnapCI::ParallelTests

  it 'should create uniform partitions of things based on count and index' do
    things = (1..10).to_a

    partition1 = partition(things: things, total_workers: 3, current_worker_index: 1)
    partition2 = partition(things: things, total_workers: 3, current_worker_index: 2)
    partition3 = partition(things: things, total_workers: 3, current_worker_index: 3)

    expect(partition1 + partition2 + partition3).to contain_exactly(*things)

    expect(partition1).to eq([1, 4, 7, 10])
    expect(partition2).to eq([2, 5, 8])
    expect(partition3).to eq([3, 6, 9])
  end

  it 'should create empty partitions if things are empty' do
    things = []

    partition1 = partition(things: things, total_workers: 3, current_worker_index: 1)
    partition2 = partition(things: things, total_workers: 3, current_worker_index: 2)
    partition3 = partition(things: things, total_workers: 3, current_worker_index: 3)

    expect(partition1).to eq([])
    expect(partition2).to eq([])
    expect(partition3).to eq([])
  end

  it 'should create empty partitions at end if partitions are more than number of things' do
    things = [1, 2]

    partition1 = partition(things: things, total_workers: 3, current_worker_index: 1)
    partition2 = partition(things: things, total_workers: 3, current_worker_index: 2)
    partition3 = partition(things: things, total_workers: 3, current_worker_index: 3)

    expect(partition1).to eq([1])
    expect(partition2).to eq([2])
    expect(partition3).to eq([])
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
snap_ci-parallel_tests-0.0.1 spec/snap_ci/parallel_tests_spec.rb