Class: TestLoggerThreads

Inherits:
Minitest::Test
  • Object
show all
Defined in:
lib/repla/logger/test/tc_logger.rb

Overview

Test logger threads

Instance Method Summary collapse

Instance Method Details

#setupObject



152
153
154
155
# File 'lib/repla/logger/test/tc_logger.rb', line 152

def setup
  @logger = Repla::Logger.new
  @logger.show
end

#teardownObject



157
158
159
160
# File 'lib/repla/logger/test/tc_logger.rb', line 157

def teardown
  window = Repla::Window.new(@logger.window_id)
  window.close
end

#test_multiple_threadsObject



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/repla/logger/test/tc_logger.rb', line 162

def test_multiple_threads
  error_text = 'Error line'
  message_text = 'Info line'
  message_called = false
  message_thread = Thread.new do
    @logger.info(message_text)
    message_called = true
  end

  error_called = false
  error_thread = Thread.new do
    @logger.error(error_text)
    error_called = true
  end

  message_thread.join
  error_thread.join

  assert(error_called)
  assert(message_called)
  @test_log_helper = Repla::Test::LogHelper.new(@logger.window_id,
                                                @logger.view_id)
  Repla::Test.block_until { @test_log_helper.number_of_log_messages >= 2 }
  result = @test_log_helper.last_log_message
  result_two = @test_log_helper.log_message_at(0)
  assert(result == message_text || result_two == message_text)
  assert(result == error_text || result_two == error_text)
end