repla 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9bc5ea00c4045bb8df6ebcbeefbe1a54905be15c
4
- data.tar.gz: 9a4875dbab09f1b149051eec2454a1d9ee73ec20
3
+ metadata.gz: 71286d9be60c5f021154d6c3f947a920507cb3e9
4
+ data.tar.gz: 15d263e2d2d59eb1dc61d1000c0ba639d948d850
5
5
  SHA512:
6
- metadata.gz: f905eed133394f281173023f31ad3a3819d5193a52b7d989e15e4dfe9133128daacc85c6b184094508326a4fdc72fe31e453ea008150de16358522558ca60200
7
- data.tar.gz: 58834673b618dffd99d320dfa280819e164393d2cea849b24cd4778712eee6a8585f0bea372d8e7bbf52b6834e8c14833e8ce8eba35bea7aacfd5a3167f3e08d
6
+ metadata.gz: ad06997ab931d826250fb37a7919a5b363321abb1eb6b701cb40f6f1b8fc82f6459bed747e76b64c4744e1795439a3b1bf887fffa1cf9d0f33dc9883c3c58493
7
+ data.tar.gz: fd5dd84d1481fb86843c0944909dae0e413c74291e647da9f057b6bff1b9a3debd9f97441bb4144ebaa8f9759ccac288d0bdd43f2f404af67542ec3a65bf6671
@@ -1,4 +1,4 @@
1
- #!/bin/sh
1
+ #!/bin/bash
2
2
 
3
3
  cd "$(dirname "$0")"
4
4
 
@@ -30,15 +30,18 @@ class TestUnintializedLogger < Minitest::Test
30
30
  # Test Message
31
31
  message = 'Testing log message'
32
32
  @logger.info(message)
33
- sleep Repla::Test::TEST_PAUSE_TIME # Pause for output to be processed
34
-
35
- # Make sure the log messages before accessing the logger's `view_id` and
36
- # `window_id` because those run the logger. This test should test logging a
37
- # message and running the logger itself simultaneously. This is why the
38
- # `LogHelper` is intialized after logging the message.
33
+ # Make sure the log messages appear before accessing the logger's `view_id`
34
+ # and `window_id` because those run the logger. This test should test
35
+ # logging a message and running the logger itself simultaneously. This is
36
+ # why the `LogHelper` is intialized after logging the message.
39
37
  test_log_helper = Repla::Test::LogHelper.new(@logger.window_id,
40
38
  @logger.view_id)
41
- test_message = test_log_helper.last_log_message
39
+ test_message = nil
40
+ Repla::Test.block_until do
41
+ test_message = test_log_helper.last_log_message
42
+ test_message == message
43
+ end
44
+
42
45
  assert_equal(message, test_message, 'The messages should match')
43
46
  test_class = test_log_helper.last_log_class
44
47
  assert_equal('message', test_class, 'The classes should match')
@@ -65,8 +68,11 @@ class TestLogger < Minitest::Test
65
68
  # Test Error
66
69
  message = 'Testing log error'
67
70
  @logger.error(message)
68
- sleep Repla::Test::TEST_PAUSE_TIME # Pause for output to be processed
69
- test_message = @test_log_helper.last_log_message
71
+ test_message = nil
72
+ Repla::Test.block_until do
73
+ test_message = @test_log_helper.last_log_message
74
+ message == test_message
75
+ end
70
76
  assert_equal(message, test_message)
71
77
  test_class = @test_log_helper.last_log_class
72
78
  assert_equal('error', test_class)
@@ -77,8 +83,11 @@ class TestLogger < Minitest::Test
77
83
  # Test Message
78
84
  message = 'Testing log message'
79
85
  @logger.info(message)
80
- sleep Repla::Test::TEST_PAUSE_TIME # Pause for output to be processed
81
- test_message = @test_log_helper.last_log_message
86
+ test_message = nil
87
+ Repla::Test.block_until do
88
+ test_message = @test_log_helper.last_log_message
89
+ message == test_message
90
+ end
82
91
  assert_equal(message, test_message)
83
92
  test_class = @test_log_helper.last_log_class
84
93
  assert_equal('message', test_class)
@@ -90,8 +99,11 @@ class TestLogger < Minitest::Test
90
99
  # Note the trailing whitespace is trimmed
91
100
  message = Repla::Logger::ERROR_PREFIX.rstrip
92
101
  @logger.info(message)
93
- sleep Repla::Test::TEST_PAUSE_TIME # Pause for output to be processed
94
- test_message = @test_log_helper.last_log_message
102
+ test_message = nil
103
+ Repla::Test.block_until do
104
+ test_message = @test_log_helper.last_log_message
105
+ message == test_message
106
+ end
95
107
  assert_equal(message, test_message)
96
108
  test_class = @test_log_helper.last_log_class
97
109
  assert_equal('message', test_class)
@@ -103,8 +115,11 @@ class TestLogger < Minitest::Test
103
115
  # Note the trailing whitespace is trimmed
104
116
  message = Repla::Logger::MESSAGE_PREFIX.rstrip
105
117
  @logger.info(message)
106
- sleep Repla::Test::TEST_PAUSE_TIME # Pause for output to be processed
107
- test_message = @test_log_helper.last_log_message
118
+ test_message = nil
119
+ Repla::Test.block_until do
120
+ test_message = @test_log_helper.last_log_message
121
+ message == test_message
122
+ end
108
123
  assert_equal(message, test_message)
109
124
  test_class = @test_log_helper.last_log_class
110
125
  assert_equal('message', test_class)
@@ -112,16 +127,11 @@ class TestLogger < Minitest::Test
112
127
  test_count += 1
113
128
  assert_equal(test_count, result_count)
114
129
 
115
- # Test Blank Spaces
116
- @logger.info(" \t")
117
- sleep Repla::Test::TEST_PAUSE_TIME # Pause for output to be processed
118
- test_message = @test_log_helper.last_log_message
119
- assert_equal(message, test_message)
120
- test_class = @test_log_helper.last_log_class
121
- assert_equal('message', test_class)
122
-
123
- # Test Empty String
130
+ # Test empty string is ignored
131
+ # Test blank space is ignored
132
+ # Note this uses the same `message` from the last test
124
133
  @logger.info('')
134
+ @logger.info(" \t")
125
135
  sleep Repla::Test::TEST_PAUSE_TIME # Pause for output to be processed
126
136
  test_message = @test_log_helper.last_log_message
127
137
  assert_equal(message, test_message)
@@ -154,12 +164,16 @@ Line 1
154
164
  Line 2
155
165
  Line 3
156
166
  '
167
+ lines = 3
157
168
  @logger.info(message)
158
- sleep Repla::Test::TEST_PAUSE_TIME * 2 # Pause for output to be processed
159
- result_count = @test_log_helper.number_of_log_messages
160
- assert_equal(result_count, 3, 'The number of log messages should match')
169
+ result_count = nil
170
+ Repla::Test.block_until do
171
+ result_count = @test_log_helper.number_of_log_messages
172
+ result_count == lines
173
+ end
174
+ assert_equal(result_count, lines)
161
175
 
162
- (1..3).each do |i|
176
+ (1..lines).each do |i|
163
177
  result = @test_log_helper.log_message_at_index(i - 1)
164
178
  test_result = "Line #{i}"
165
179
  assert_equal(result,
@@ -168,3 +182,45 @@ Line 3
168
182
  end
169
183
  end
170
184
  end
185
+
186
+ # Test logger threads
187
+ class TestLoggerThreads < Minitest::Test
188
+ def setup
189
+ @logger = Repla::Logger.new
190
+ @logger.show
191
+ end
192
+
193
+ def teardown
194
+ window = Repla::Window.new(@logger.window_id)
195
+ window.close
196
+ end
197
+
198
+ def test_multiple_threads
199
+ error_text = 'Error line'
200
+ message_text = 'Info line'
201
+ message_called = false
202
+ message_thread = Thread.new do
203
+ @logger.info(message_text)
204
+ message_called = true
205
+ end
206
+
207
+ error_called = false
208
+ error_thread = Thread.new do
209
+ @logger.error(error_text)
210
+ error_called = true
211
+ end
212
+
213
+ message_thread.join
214
+ error_thread.join
215
+
216
+ assert(error_called)
217
+ assert(message_called)
218
+ @test_log_helper = Repla::Test::LogHelper.new(@logger.window_id,
219
+ @logger.view_id)
220
+ Repla::Test.block_until { @test_log_helper.number_of_log_messages >= 2 }
221
+ result = @test_log_helper.last_log_message
222
+ result_two = @test_log_helper.log_message_at_index(0)
223
+ assert(result == message_text || result_two == message_text)
224
+ assert(result == error_text || result_two == error_text)
225
+ end
226
+ end
data/lib/repla/logger.rb CHANGED
@@ -7,6 +7,9 @@ module Repla
7
7
  ERROR_PREFIX = 'ERROR '.freeze
8
8
  LOG_PLUGIN_NAME = 'Log'.freeze
9
9
 
10
+ def initialize
11
+ @mutex = Mutex.new
12
+ end
10
13
  # Toggle
11
14
 
12
15
  SHOW_LOG_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, 'show_log.scpt')
@@ -48,12 +51,16 @@ module Repla
48
51
  end
49
52
 
50
53
  def view_id
51
- @view_id ||= Repla.split_id_in_window(window_id, LOG_PLUGIN_NAME)
52
- return @view_id unless @view_id.nil?
54
+ view_id = nil
55
+ @mutex.synchronize do
56
+ @view_id ||= Repla.split_id_in_window(window_id, LOG_PLUGIN_NAME)
57
+ return @view_id unless @view_id.nil?
53
58
 
54
- @view_id = Repla.split_id_in_window_last(window_id)
55
- Repla.run_plugin_in_split(LOG_PLUGIN_NAME, window_id, @view_id)
56
- @view_id
59
+ @view_id = Repla.split_id_in_window_last(window_id)
60
+ Repla.run_plugin_in_split(LOG_PLUGIN_NAME, window_id, @view_id)
61
+ view_id = @view_id
62
+ end
63
+ view_id
57
64
  end
58
65
 
59
66
  private
@@ -1,3 +1,3 @@
1
- #!/bin/sh
1
+ #!/bin/bash
2
2
 
3
- cat
3
+ cat
@@ -1,3 +1,3 @@
1
- #!/bin/sh
1
+ #!/bin/bash
2
2
 
3
- cat
3
+ cat
@@ -1,3 +1,3 @@
1
- #!/bin/sh
1
+ #!/bin/bash
2
2
 
3
- cat
3
+ cat
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env bash
1
+ #!/bin/bash
2
2
 
3
3
  set -e
4
4
 
data/lib/repla/test.rb CHANGED
@@ -3,6 +3,8 @@ module Repla
3
3
  module Test
4
4
  # General
5
5
  TEST_PAUSE_TIME = 2.00
6
+ TEST_TIMEOUT_TIME = 4.00
7
+ POLLING_INTERVAL = 0.5
6
8
 
7
9
  # Ruby
8
10
  REPLA_FILE = File.join(File.dirname(__FILE__), '../repla')
@@ -22,6 +24,19 @@ module Repla
22
24
  'http://127.0.0.1:5000/' + filename
23
25
  end
24
26
 
27
+ def self.block_until_with_timeout(timeout)
28
+ cycles = [timeout / POLLING_INTERVAL, 1].max
29
+ count = 0
30
+ until yield || count >= cycles
31
+ sleep(POLLING_INTERVAL)
32
+ count += 1
33
+ end
34
+ end
35
+
36
+ def self.block_until(&block)
37
+ block_until_with_timeout(TEST_TIMEOUT_TIME, &block)
38
+ end
39
+
25
40
  # HTML
26
41
  TEST_HTML_DIRECTORY = File.join(TEST_DIRECTORY, 'html')
27
42
  INDEX_HTML_FILENAME = 'index.html'.freeze
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: repla
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roben Kleene