Sha256: 70ace5f3f9c489e42204567e628f8faf36f0090612b0b41d8b24846c48dd705d

Contents?: true

Size: 796 Bytes

Versions: 1

Compression:

Stored size: 796 Bytes

Contents

# encoding: utf-8
require "logstash/devutils/rspec/spec_helper"
require 'logstash/inputs/udp'

# expose the udp socket so that we can assert, during
# a spec, that it is open and we can start sending data
class LogStash::Inputs::Udp
  attr_reader :udp
end

module UdpHelpers

  def input(plugin, size, &block)
    queue = Queue.new
    input_thread = Thread.new do
      plugin.run(queue)
    end
    # because the udp socket is created and bound during #run
    # we must ensure that it is open before sending data
    sleep 0.1 until (plugin.udp && !plugin.udp.closed?)
    block.call
    sleep 0.1 while queue.size != size
    result = nevents.times.inject([]) do |acc|
      acc << queue.pop
    end
    plugin.do_stop
    result
  end

end

RSpec.configure do |c|
  c.include UdpHelpers
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
logstash-input-udp-2.0.1 spec/spec_helper.rb