Sha256: 3363b43b2d9fe74c761e728c43a3c60170b717767907edb8b8a581a8122abf1e

Contents?: true

Size: 1.28 KB

Versions: 3

Compression:

Stored size: 1.28 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.config.logfile).grep(regex).size == 1
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
filum-1.0.3 test/integration/logger_test.rb
filum-1.0.2 test/integration/logger_test.rb
filum-1.0.1 test/integration/logger_test.rb