Sha256: 0e485ed098f3e8b2e9db7476e12c7cc1634a196b6462b9082d9e8155e9235154

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

require File.expand_path('../../test_helper', __FILE__)

module Filum

  class Worker
    def self.process
      Filum.logger.info "Processing"
    end
  end

  class LoggerTest < IntegrationTest
    def test_one_logline
      test_thread = Thread.new do
        Filum.logger.context_id = "123456"
        Worker.process
      end
      test_thread.join
      assert_logged(/\[123456\]/)
    end

    def test_multiple_threads
      test_thread1 = Thread.new do
        Filum.logger.context_id = "23456a"
        Worker.process
      end
      test_thread2 = Thread.new do
        Filum.logger.context_id = "34567a"
        Worker.process
      end
      test_thread1.join
      test_thread2.join
      assert_logged(/\[23456a\]/)
      assert_logged(/\[34567a\]/)
    end

    def test_info_string_is_correct
      random_string = [*'a'..'z'].sample(10).join
      Filum.logger.info "Foobar #{random_string}"
      assert_logged(/Foobar #{random_string}$/)
    end

    def test_caller_line_is_correct
      expected_file = 'logger_test.rb'
      expected_line = __LINE__+1
      Filum.logger.info "Foobar"
      assert_logged(/#{expected_file}:#{expected_line}/)
    end

    private
    def assert_logged(regex)
      assert File.readlines(Filum.logger.logfile).grep(regex).size == 1
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
filum-2.0.0 test/integration/logger_test.rb