File: wrapping_executor_loaded_manualy.rb

package info (click to toggle)
ruby-concurrent 1.1.6%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 30,284 kB
  • sloc: ruby: 30,875; java: 6,117; ansic: 288; makefile: 9; sh: 6
file content (48 lines) | stat: -rw-r--r-- 1,553 bytes parent folder | download | duplicates (2)
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
module Concurrent
  RSpec.describe WrappingExecutor do

    let(:wrapping_executor) { WrappingExecutor.new(executor, &wrapper) }
    let(:executor) { Concurrent.global_fast_executor }
    let(:wrapper) { nil }
    let(:args) { { foo: 'bar', baz: 42 } }
    let(:task) { -> (*args) { return nil } }

    subject { wrapping_executor }

    it { is_expected.to be_kind_of(WrappingExecutor) }
    it { is_expected.to respond_to(:post) }
    it { is_expected.to respond_to(:can_overflow?) }
    it { is_expected.to respond_to(:serialized?) }

    describe '#post' do
      context 'with passthrough wrapper' do
        let(:wrapper) { -> (*args, &task) { return *args, task } }

        it {
          expect(executor).to receive(:post).with(args) { |&block| expect(block).to be(task) }
          wrapping_executor.post(args, &task)
        }
      end

      context 'with wrapper modifying args' do
        let(:wrapper) { -> (*args, &task) { return *args, { xyz: 'abc' }, task } }

        it {
          expect(executor).to receive(:post).with(args, { xyz: 'abc' }) { |&block| expect(block).to be(task) }
          wrapping_executor.post(args, &task)
        }
      end

      context 'with wrapper modifying task' do
        let(:wrapper) { -> (*args, &task) { return *args, another_task } }
        let(:another_task) { -> (*args) { return true } }

        it {
          expect(executor).to receive(:post).with(args) { |&block| expect(block).to be(another_task) }
          wrapping_executor.post(args, &task)
        }
      end

    end
  end
end