<commit_before>require 'spec_helper'

describe GH::Parallel do
  before do
    stub_request(:get, "https://api.github.com/users/rkh").to_return(:status => 200, :body => '{"name": "<NAME>"}')
    stub_request(:get, "https://api.github.com/users/svenfuchs").to_return(:status => 200, :body => '{"name": "<NAME>"}')
    stub_request(:get, "https://api.github.com/users/rkh?per_page=100").to_return(:status => 200, :body => '{"name": "<NAME>"}')
    stub_request(:get, "https://api.github.com/users/svenfuchs?per_page=100").to_return(:status => 200, :body => '{"name": "<NAME>"}')
  end

  it 'allows normal requests' do
    GH['users/rkh']['name'].should be == '<NAME>'
  end

  it 'sets in_parallel?' do
    GH.should_not be_in_parallel
    GH.in_parallel { GH.should be_in_parallel }
    GH.should_not be_in_parallel
  end

  it 'runs requests in parallel' do
    GH::DefaultStack.replace GH::MockBackend, GH::Remote
    GH.current = nil
    GH.should_not be_in_parallel

    a = b = nil
    GH.in_parallel do
      GH.should be_in_parallel

      a = GH['users/rkh']
      b = GH['users/svenfuchs']

      expect { a['name'] }.to raise_error(RuntimeError)
      expect { b['name'] }.to raise_error(RuntimeError)
    end

    a['name'].should be == "<NAME>"
    b['name'].should be == "<NAME>"

    a.should respond_to('to_hash')
    b.should respond_to('to_hash')
<commit_msg>WebMock does not like pipelining :(<commit_after>require 'spec_helper'

describe GH::Parallel do
  before do
    stub_request(:get, "https://api.github.com/users/rkh").to_return(:status => 200, :body => '{"name": "<NAME>"}')
    stub_request(:get, "https://api.github.com/users/svenfuchs").to_return(:status => 200, :body => '{"name": "<NAME>"}')
    stub_request(:get, "https://api.github.com/users/rkh?per_page=100").to_return(:status => 200, :body => '{"name": "<NAME>"}')
    stub_request(:get, "https://api.github.com/users/svenfuchs?per_page=100").to_return(:status => 200, :body => '{"name": "<NAME>"}')
  end

  it 'allows normal requests' do
    GH['users/rkh']['name'].should be == '<NAME>'
  end

  it 'sets in_parallel?' do
    GH.should_not be_in_parallel
    GH.in_parallel { GH.should be_in_parallel }
    GH.should_not be_in_parallel
  end

  it 'runs requests in parallel' do
    WebMock.allow_net_connect!
    GH::DefaultStack.replace GH::MockBackend, GH::Remote
    GH.current = nil
    GH.should_not be_in_parallel

    a = b = nil
    GH.in_parallel do
      GH.should be_in_parallel

      a = GH['users/rkh']
      b = GH['users/svenfuchs']

      expect { a['name'] }.to raise_error(RuntimeError)
      expect { b['name'] }.to raise_error(RuntimeError)
    end

    a['name'].should be == "<NAME>"
    b['name'].should be == "<NAME>"

    a.should respond_to('to_hash')
    b.should respond_to('to_hash')

{'fraction_non_alphanumeric': 0.18181818181818182, 'fraction_numerical': 0.012834224598930482, 'mean_word_length': 3.772108843537415, 'pattern_counts': {'":': 8, '<': 17, '<?xml version=': 0, '>': 33, 'https://': 8, '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': '881611', 'n_tokens_mistral': 1069, 'n_tokens_neox': 991, 'n_words': 198}