<commit_before>def process_titles_in_directory(data_directory)
  q, ch = connect_to_rabbitmq_queue
  Dir.foreach('data/' + data_directory) do |item|
    next if File.extname(item) != '.json'
    data = File.read('data/' + data_directory + '/' + item)
    ch.default_exchange.publish(data, routing_key: q.name, content_type: 'application/json')
  end
end

def process_titles_from_data(title_data)
  q, ch = connect_to_rabbitmq_queue
  ch.default_exchange.publish(title_data, routing_key: q.name, content_type: 'application/json')
end

def connect_to_rabbitmq_queue
  conn = Bunny.new(ENV['INCOMING_QUEUE_HOSTNAME'])
  conn.start
  ch = conn.create_channel
  q = ch.queue(ENV['INCOMING_QUEUE'], durable: true)
  [q, ch]
end
<commit_msg>Make acceptance tests wait for the queue to be consumed before making assertions<commit_after>def process_titles_in_directory(data_directory)
  queue, channel = connect_to_rabbitmq_queue
  Dir.foreach('data/' + data_directory) do |item|
    next if File.extname(item) != '.json'
    data = File.read('data/' + data_directory + '/' + item)
    channel.default_exchange.publish(data, routing_key: queue.name, content_type: 'application/json')
  end

  wait_for_queue_to_be_consumed(channel, queue.name)
end

def process_titles_from_data(title_data)
  queue, channel = connect_to_rabbitmq_queue
  channel.default_exchange.publish(title_data, routing_key: queue.name, content_type: 'application/json')
  wait_for_queue_to_be_consumed(channel, queue.name)
end

def wait_for_queue_to_be_consumed(channel, queue_name)
  consumed = false

  while not consumed
    response = channel.queue_declare(queue=queue_name, opts={passive: true})
    consumed = response.message_count == 0
    sleep(0.5)
  end
end

def connect_to_rabbitmq_queue
  conn = Bunny.new(ENV['INCOMING_QUEUE_HOSTNAME'])
  conn.start
  ch = conn.create_channel
  q = ch.queue(ENV['INCOMING_QUEUE'], durable: true)
  [q, ch]
end

{'fraction_non_alphanumeric': 0.1078125, 'fraction_numerical': 0.0015625, 'mean_word_length': 5.468013468013468, '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': '2169', 'n_tokens_mistral': 677, 'n_tokens_neox': 659, 'n_words': 132}