<commit_before>proc { |p| $:.unshift(p) unless $:.any? { |lp| File.expand_path(lp) == p } }.call(File.expand_path('.', File.dirname(__FILE__)))
require 'helper'

describe(Zy::Server) do
  before do
    server = TCPServer.new('127.0.0.1', 0)
    @server_port = server_port = server.addr[1]
    server.close

    STDERR.puts "firing server"
    Thread.abort_on_exception = true
    @server_thread = Thread.new do
      Zy::Server.new(
        :app => proc { |request| {} },
        :bind => "tcp://*:#{server_port}",
      ).start
    end
    STDERR.puts "fired server"
  end
  after do
    @server_thread.kill
  end

  let(:client_socket) do
    Zy.zmq_context.socket(ZMQ::REQ).tap do |client_socket|
      client_socket.connect("tcp://localhost:#{@server_port}")
    end
  end

  it('connects') do
    send_rc = client_socket.send_string('{}')
    assert(send_rc >= 0)
    reply_s = ''
    recv_rc = client_socket.recv_string(reply_s)
    assert(recv_rc >= 0)
    reply = JSON.parse(reply_s)
  end
end<commit_msg>small test refactor<commit_after>proc { |p| $:.unshift(p) unless $:.any? { |lp| File.expand_path(lp) == p } }.call(File.expand_path('.', File.dirname(__FILE__)))
require 'helper'

describe(Zy::Server) do
  before do
    server = TCPServer.new('127.0.0.1', 0)
    @server_port = server_port = server.addr[1]
    server.close

    STDERR.puts "firing server"
    Thread.abort_on_exception = true
    @server_thread = Thread.new do
      Zy::Server.new(
        :app => proc { |request| {} },
        :bind => "tcp://*:#{server_port}",
      ).start
    end
    STDERR.puts "fired server"
  end
  after do
    @server_thread.kill
  end

  let(:client_socket) do
    Zy.zmq_context.socket(ZMQ::REQ).tap do |client_socket|
      client_socket.connect("tcp://localhost:#{@server_port}")
    end
  end

  def request_s(request_s)
    send_rc = client_socket.send_string(request_s)
    assert(send_rc >= 0)
    reply_s = ''
    recv_rc = client_socket.recv_string(reply_s)
    assert(recv_rc >= 0)
    reply_s
  end

  it 'requests and replies' do
    reply_s = request_s '{}'
    reply = JSON.parse(reply_s)
  end
end
{'fraction_non_alphanumeric': 0.15120113047574188, 'fraction_numerical': 0.009420631182289214, 'mean_word_length': 3.1403508771929824, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '1661151', 'n_tokens_mistral': 806, 'n_tokens_neox': 777, 'n_words': 150}