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



188
189
190
191
# File 'lib/repla/logger/test/tc_logger.rb', line 188

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

#teardownObject



193
194
195
196
# File 'lib/repla/logger/test/tc_logger.rb', line 193

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

#test_multiple_threadsObject



198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/repla/logger/test/tc_logger.rb', line 198

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_index(0)
  assert(result == message_text || result_two == message_text)
  assert(result == error_text || result_two == error_text)
end