Sha256: dcdcbfc45d02046b9ebbc93fbc3bee01ad25ab82cdc17f21d400e5766537eb88

Contents?: true

Size: 1.01 KB

Versions: 15

Compression:

Stored size: 1.01 KB

Contents

require 'spec_helper'
require 'rom/memory/storage'

describe ROM::Memory::Storage do
  describe 'thread safe' do
    let(:threads) { 4 }
    let(:operations) { 5000 }

    describe 'data' do
      it 'create datasets properly' do
        storage = ROM::Memory::Storage.new

        threaded_operations do |thread, operation|
          key = "#{thread}:#{operation}"
          storage.create_dataset(key)
        end

        expect(storage.size).to eql(threads * operations)
      end
    end

    describe 'dataset' do
      it 'inserts data in proper order' do
        storage = ROM::Memory::Storage.new
        dataset = storage.create_dataset(:ary)

        threaded_operations do
          dataset << :data
        end

        expect(dataset.size).to eql(threads * operations)
      end
    end

    def threaded_operations
      threads.times.map { |thread|
        Thread.new do
          operations.times do |operation|
            yield thread, operation
          end
        end
      }.each(&:join)
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rom-2.0.2 spec/unit/rom/memory/storage_spec.rb
rom-2.0.1 spec/unit/rom/memory/storage_spec.rb
rom-2.0.0 spec/unit/rom/memory/storage_spec.rb
rom-1.0.0 spec/unit/rom/memory/storage_spec.rb
rom-1.0.0.rc1 spec/unit/rom/memory/storage_spec.rb
rom-1.0.0.beta2 spec/unit/rom/memory/storage_spec.rb
rom-1.0.0.beta1 spec/unit/rom/memory/storage_spec.rb
rom-0.9.1 spec/unit/rom/memory/storage_spec.rb
rom-0.9.0 spec/unit/rom/memory/storage_spec.rb
rom-0.9.0.rc1 spec/unit/rom/memory/storage_spec.rb
rom-0.9.0.beta1 spec/unit/rom/memory/storage_spec.rb
rom-0.8.1 spec/unit/rom/memory/storage_spec.rb
rom-0.8.0 spec/unit/rom/memory/storage_spec.rb
rom-0.7.1 spec/unit/rom/memory/storage_spec.rb
rom-0.7.0 spec/unit/rom/memory/storage_spec.rb