<commit_before># -*- coding: utf-8 -*-

require 'spec_helper'

describe WebsocketSequentialClient do
  URL = test_url

  after :each do
    stop_ws_server
    stop_tcp_server
  end

  def start_ws_server(&block)
    @ws_thread = Thread.start do
      EM.run do
        param = {
          host: URL.host,
          port: URL.port
        }
        EM::WebSocket.start(param) do |ws|
          ws.onmessage do |msg|
            block.call ws, :onmessage, msg
          end

          ws.onbinary do |msg|
            block.call ws, :onbinary, msg
          end

          ws.onclose do |msg|
            block.call ws, :onclose, msg
          end

          ws.onping do
            block.call ws, :onping
          end
        end
      end
    end
  end

  def stop_ws_server
    return unless @ws_thread
<commit_msg>Make spec more robust.<commit_after># -*- coding: utf-8 -*-

require 'spec_helper'

describe WebsocketSequentialClient do
  URL = test_url

  after :each do
    stop_ws_server
    stop_tcp_server
  end

  def start_ws_server(&block)
    mutex = Mutex.new
    cond_var = ConditionVariable.new
    started = false

    @ws_thread = Thread.start do
      EM.run do
        param = {
          host: URL.host,
          port: URL.port
        }
        EM::WebSocket.start(param) do |ws|
          ws.onmessage do |msg|
            block.call ws, :onmessage, msg
          end

          ws.onbinary do |msg|
            block.call ws, :onbinary, msg
          end

          ws.onclose do |msg|
            block.call ws, :onclose, msg
          end

          ws.onping do
            block.call ws, :onping
          end
        end

        mutex.synchronize do
          started = true
          cond_var.signal
        end
      end
    end

    mutex.synchronize do
      cond_var.wait mutex until started
    end
  end

  def stop_ws_server
    return unless @ws_thread

{'fraction_non_alphanumeric': 0.07346723044397463, 'fraction_numerical': 0.0010570824524312897, 'mean_word_length': 1.5139442231075697, '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': '399259', 'n_tokens_mistral': 616, 'n_tokens_neox': 579, 'n_words': 162}