<commit_before>require 'spec_helper'
require 'timeout'

describe 'websocket-server' do
  # Why not Rails.root.join here?
  # Because it's not avaialable in this spec (no 'rails_helper' = faster start-up)
  let(:app_root)   { File.expand_path('../..', __dir__) }
  let(:ws_server)  { File.expand_path('script/websocket-server.rb', app_root) }
  let(:pidfile)    { File.expand_path('tmp/pids/websocket.pid', app_root) }
  let(:output_log) { File.expand_path('log/websocket-server_out.log', app_root) }
  let(:error_log)  { File.expand_path('log/websocket-server_err.log', app_root) }

  context 'with IPv6 bind address (via -b option)' do
    # This error is raised for invalid bind addresses
    let(:error_msg) { "`start_tcp_server': no acceptor" }
    let(:ipv6_addr) { '::1/128' }
    # Prevent port assignment conflicts during parallel test execution
    let(:port)      { rand(60_000..65_000) }

    # Flush logs
    before do
      File.write(output_log, '')
      File.write(error_log, '')
    end

    it 'starts up successfully' do
      begin
        system("RAILS_ENV=test #{ws_server} start -db #{ipv6_addr} -p #{port}")

        # Wait for daemon to start
        Timeout.timeout(20, Timeout::Error, 'WebSocket Server startup timed out') do
          loop { break if File.size(output_log) + File.size(error_log) > 0 }
        end

        expect(File.read(error_log)).not_to include(error_msg)
      ensure
        system("#{ws_server} stop >/dev/null 2>&1") if File.exist?(pidfile)
      end
    end
  end
end<commit_msg>Disable websocket server spec IPv6 example on systems without IPv6 support<commit_after>require 'spec_helper'
require 'timeout'

describe 'websocket-server' do
  # Why not Rails.root.join here?
  # Because it's not avaialable in this spec (no 'rails_helper' = faster start-up)
  let(:app_root)   { File.expand_path('../..', __dir__) }
  let(:ws_server)  { File.expand_path('script/websocket-server.rb', app_root) }
  let(:pidfile)    { File.expand_path('tmp/pids/websocket.pid', app_root) }
  let(:output_log) { File.expand_path('log/websocket-server_out.log', app_root) }
  let(:error_log)  { File.expand_path('log/websocket-server_err.log', app_root) }

  context 'with IPv6 bind address (via -b option)', if: File.exist?('/proc/net/if_inet6') do
    # This error is raised for invalid bind addresses
    let(:error_msg) { "`start_tcp_server': no acceptor" }
    let(:ipv6_addr) { '::1/128' }
    # Prevent port assignment conflicts during parallel test execution
    let(:port)      { rand(60_000..65_000) }

    # Flush logs
    before do
      File.write(output_log, '')
      File.write(error_log, '')
    end

    it 'starts up successfully' do
      begin
        system("RAILS_ENV=test #{ws_server} start -db #{ipv6_addr} -p #{port} >/dev/null 2>&1")

        # Wait for daemon to start
        Timeout.timeout(20, Timeout::Error, 'WebSocket Server startup timed out') do
          loop { break if File.size(output_log) + File.size(error_log) > 0 }
        end

        expect(File.read(error_log)).not_to include(error_msg)
      ensure
        system("#{ws_server} stop >/dev/null 2>&1") if File.exist?(pidfile)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.13379396984924624, 'fraction_numerical': 0.015389447236180905, 'mean_word_length': 3.3333333333333335, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '959242', 'n_tokens_mistral': 1120, 'n_tokens_neox': 1061, 'n_words': 259}