<commit_before>describe 'request and response', integration: true do
  let(:consumer) { AdderConsumer }

  it 'requesting returns a future and in time we get a value' do
    hsh    = { numbers: [1, 2, 3], sleep_time: 5 }
    future = Tiki::Torch.request consumer.topic, hsh, timeout: 15

    expect(future).to be_a Concurrent::Future
    expect(future.state).to eq :processing
    expect(future.value(0)).to be_nil

    $lines.wait_for_size 1

    expect(future.value).to eq 6
    expect(future.state).to eq :fulfilled
  end

  it 'requesting returns a future that times out' do
    hsh    = { numbers: [1, 2, 3], sleep_time: 5 }
    future = Tiki::Torch.request consumer.topic, hsh, timeout: 2

    expect(future).to be_a Concurrent::Future
    expect([:pending, :processing]).to include(future.state)
    expect(future.value(0)).to be_nil

    sleep 2.5

    expect(future.value).to be_nil
    expect(future.state).to eq :rejected

    reason = future.reason
    expect(reason).to be_a Tiki::Torch::RequestTimedOutError
    expect(reason.timeout).to eq 2
    expect(reason.message_id).to be_a String
    expect(reason.topic_name).to eq consumer.topic
    expect(reason.payload).to eq hsh
    expect(reason.properties).to be_a Hash
  end

end<commit_msg>Fixing issues with some tests. Added test for mutiple requests concurrently.<commit_after>describe 'request and response', integration: true do
  let(:consumer) { AdderConsumer }

  it 'requesting returns a future and in time we get a value' do
    hsh    = { numbers: [1, 2, 3], sleep_time: 5 }
    future = Tiki::Torch.request consumer.topic, hsh, timeout: 15

    expect(future).to be_a Concurrent::Future
    expect([:pending, :processing]).to include(future.state)
    expect(future.value(0)).to be_nil

    $lines.wait_for_size 1

    expect(future.value).to eq 6
    expect(future.state).to eq :fulfilled
  end

  it 'requesting returns a future that times out' do
    hsh    = { numbers: [1, 2, 3], sleep_time: 5 }
    future = Tiki::Torch.request consumer.topic, hsh, timeout: 2

    expect(future).to be_a Concurrent::Future
    expect([:pending, :processing]).to include(future.state)
    expect(future.value(0)).to be_nil

    sleep 2.5

    expect(future.value).to be_nil
    expect(future.state).to eq :rejected

    reason = future.reason
    expect(reason).to be_a Tiki::Torch::RequestTimedOutError
    expect(reason.timeout).to eq 2
    expect(reason.message_id).to be_a String
    expect(reason.topic_name).to eq consumer.topic
    expect(reason.payload).to eq hsh
    expect(reason.properties).to be_a Hash
  end

  it 'multiple requests concurrently' do
    futures = 3.times.map do |nr|
      hsh = { numbers: [1, nr], sleep_time: 1 }
      Tiki::Torch.request consumer.topic, hsh, timeout: 15
    end
    start_time = Time.now
    values = futures.map { |future| future.value }
    secs = Time.now - start_time

    expect(values).to eq [1,2,3]
    expect(secs).to be < 2.0
  end

end
{'fraction_non_alphanumeric': 0.1138129010469436, 'fraction_numerical': 0.015535292131036813, 'mean_word_length': 3.4143070044709387, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6416801', 'n_tokens_mistral': 1013, 'n_tokens_neox': 952, 'n_words': 268}