<commit_before>require 'spec_helper'

require 'combi/service_bus'
require 'combi/buses/web_socket'

describe 'Combi::WebSocket' do
  context 'can be instanitated via ServiceBus' do
    When(:bus) { Combi::ServiceBus.init_for(:web_socket, {}) }
    Then { Combi::WebSocket === bus }
  end
  Given(:handler) { double('handler', on_open: nil) }
  Given(:client_options) do
    { remote_api: 'ws://localhost:9292/',
      handler: handler }
  end
  Given(:ws_server) { Combi::ServiceBus.init_for(:web_socket, {} )}
  Given(:subject) { Combi::ServiceBus.init_for(:web_socket, client_options) }
  Given!("webserver is running") do
    # TODO: poll the server
    sleep 1
  end

  it_behaves_like 'standard_bus' do
    Given(:provider) { ws_server }
    Given(:consumer) { subject }
    Given(:webserver) do
      puts "Running webserver with #{service.map(&:actions).join ','} registered"
      start_websocket_server ws_server
    end
    Given!("consumer started") do
      webserver && provider_started && sleep(1) && consumer_started
    end
    after :each do
      stop_websocket_server(webserver)
    end<commit_msg>remove "pauses", new web socket server is fast<commit_after>require 'spec_helper'

require 'combi/service_bus'
require 'combi/buses/web_socket'

describe 'Combi::WebSocket' do
  context 'can be instanitated via ServiceBus' do
    When(:bus) { Combi::ServiceBus.init_for(:web_socket, {}) }
    Then { Combi::WebSocket === bus }
  end
  Given(:handler) { double('handler', on_open: nil) }
  Given(:client_options) do
    { remote_api: 'ws://localhost:9292/',
      handler: handler }
  end
  Given(:ws_server) { Combi::ServiceBus.init_for(:web_socket, {} )}
  Given(:subject) { Combi::ServiceBus.init_for(:web_socket, client_options) }

  it_behaves_like 'standard_bus' do
    Given(:provider) { ws_server }
    Given(:consumer) { subject }
    Given(:webserver) do
      puts "Running webserver with #{service.map(&:actions).join ','} registered"
      start_websocket_server ws_server
    end
    Given!("consumer started") do
      webserver && provider_started && consumer_started
    end
    after :each do
      stop_websocket_server(webserver)
    end
{'fraction_non_alphanumeric': 0.12793373216751036, 'fraction_numerical': 0.004601932811780948, 'mean_word_length': 4.1761904761904765, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4215025', 'n_tokens_mistral': 722, 'n_tokens_neox': 701, 'n_words': 154}