Sha256: 176fe3736b62727894b445d49b5d023b886bc9e2f1267689ed57830cb484acfb

Contents?: true

Size: 1.27 KB

Versions: 2

Compression:

Stored size: 1.27 KB

Contents

require "helper"
require "logger"
require "twirl/instrumentation/log_subscriber"

class LogSubscriberInstrumentationTest < Minitest::Test
  def setup
    @cluster = build(:cluster, {
      instrumenter: ActiveSupport::Notifications,
      queues: %w(testing),
    })
    @io = StringIO.new
    logger = Logger.new(@io)
    logger.formatter = proc { |severity, datetime, progname, msg| "#{msg}\n" }
    Twirl::Instrumentation::LogSubscriber.logger = logger
  end

  def log
    @io.string
  end

  def teardown
    Twirl::Instrumentation::LogSubscriber.logger = nil
  end

  def test_set
    @cluster.set "testing", "data"
    line = find_line("Twirl op(set)")
    assert_match %r{queue_name=testing bytes=4}, line
  end

  def test_get
    @cluster.set "testing", "data"
    @cluster.get "testing"
    line = find_line("Twirl op(get)")
    assert_match %r{queue_name=testing bytes=4}, line
  end

  def test_reserve
    @cluster.set "testing", "data"
    @cluster.reserve "testing"
    line = find_line("Twirl op(reserve)")
    assert_match %r{queue_name=testing bytes=4}, line
  end

  def find_line(str)
    regex = /#{Regexp.escape(str)}/
    lines = log.split("\n")
    lines.detect { |line| line =~ regex } ||
      raise("Could not find line matching #{str.inspect} in #{lines.inspect}")
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
twirl-0.2.0 test/instrumentation/log_subscriber_test.rb
twirl-0.1.0 test/instrumentation/log_subscriber_test.rb