<commit_before>class DummyActor; include Celluloid; end

class TestProbeClient
  include Celluloid
  include Celluloid::Notifications

  attr_reader :buffer

  def initialize()
    @condition = Condition.new
    subscribe(/celluloid\.events\..+/, :event_received)
    @buffer = []
  end

  def wait
    @condition.wait
  end

  def wait_event(topic, expected_actor1 = nil, expected_actor2 = nil)
    loop do
      wait
      while ev = @buffer.shift()
        if (ev[0] == topic) && (ev[1].mailbox.address == expected_actor1.mailbox.address) &&
           (expected_actor2.nil? || (ev[2].mailbox.address == expected_actor2.mailbox.address) )
          return ev
        end
      end
    end
  end

  def event_received(topic, args)
    @buffer << [topic, args[0], args[1]]
    @condition.signal
  end
end

RSpec.describe "Probe", actor_system: :global do
  describe 'on boot' do
    it 'should capture system actor spawn' do
      client = TestProbeClient.new
      Celluloid::Probe.run
      create_events = []
      received_named_events = {
        :default_incident_reporter => nil,
        :notifications_fanout      => nil
      }
      # wait for the events we seek
      Timeout.timeout(5) do
        loop do
          client.wait
          while ev = client.buffer.shift
            if ev[0] == 'celluloid.events.actor_created'
              create_events << ev
            elsif ev[0] == 'celluloid.events.actor_named'
              if received_named_events.keys.include?(ev[1].name)
                received_named_events[ev[1].name] = ev[1].mailbox.address
              end
            end
          end
          if received_named_events.all?{|_, v| v != nil }
            break
          end
        end<commit_msg>Fix flaky test with extra delay? #524<commit_after>class DummyActor; include Celluloid; end

class TestProbeClient
  include Celluloid
  include Celluloid::Notifications

  attr_reader :buffer

  def initialize()
    @condition = Condition.new
    subscribe(/celluloid\.events\..+/, :event_received)
    @buffer = []
  end

  def wait
    @condition.wait
  end

  def wait_event(topic, expected_actor1 = nil, expected_actor2 = nil)
    loop do
      wait
      while ev = @buffer.shift()
        if (ev[0] == topic) && (ev[1].mailbox.address == expected_actor1.mailbox.address) &&
           (expected_actor2.nil? || (ev[2].mailbox.address == expected_actor2.mailbox.address) )
          return ev
        end
      end
    end
  end

  def event_received(topic, args)
    @buffer << [topic, args[0], args[1]]
    @condition.signal
  end
end

RSpec.describe "Probe", actor_system: :global do
  describe 'on boot' do
    it 'should capture system actor spawn', flaky: true do
      client = TestProbeClient.new
      Celluloid::Probe.run
      create_events = []
      received_named_events = {
        :default_incident_reporter => nil,
        :notifications_fanout      => nil
      }
      # wait for the events we seek
      Timeout.timeout(5) do
        loop do
          client.wait
          sleep 0.9
          while ev = client.buffer.shift
            if ev[0] == 'celluloid.events.actor_created'
              create_events << ev
            elsif ev[0] == 'celluloid.events.actor_named'
              if received_named_events.keys.include?(ev[1].name)
                received_named_events[ev[1].name] = ev[1].mailbox.address
              end
            end
          end
          if received_named_events.all?{|_, v| v != nil }
            break
          end
        end
{'fraction_non_alphanumeric': 0.10093829968723343, 'fraction_numerical': 0.010520329826556724, 'mean_word_length': 2.152329749103943, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, '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': '1181226', 'n_tokens_mistral': 1091, 'n_tokens_neox': 1063, 'n_words': 255}