test-loop 10.0.0 → 10.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/test/loop.rb +31 -17
  2. metadata +2 -2
data/lib/test/loop.rb CHANGED
@@ -54,20 +54,22 @@ module Test
54
54
  @lines_by_file = {} # path => readlines
55
55
  @last_ran_at = @started_at = Time.now
56
56
 
57
- catch self do
58
- register_signals
59
- load_user_config
60
- absorb_overhead
61
- run_test_loop
62
- end
57
+ register_signals
58
+ load_user_config
59
+ absorb_overhead
60
+ run_test_loop
63
61
 
64
- kill_workers
65
- notify 'Goodbye!'
62
+ rescue Interrupt
63
+ # allow user to break the loop by pressing Ctrl-C or sending SIGINT
66
64
 
67
65
  rescue Exception => error
68
66
  STDERR.puts error.inspect, error.backtrace
69
67
  pause_momentarily
70
68
  reload_master_process
69
+
70
+ ensure
71
+ kill_workers
72
+ notify 'Goodbye!'
71
73
  end
72
74
 
73
75
  private
@@ -80,8 +82,10 @@ module Test
80
82
  ANSI_RED = "\e[31m%s\e[0m".freeze
81
83
 
82
84
  def notify message
83
- # using print() because puts() is not an atomic operation
84
- print "test-loop: #{message}\n"
85
+ # using print() because puts() is not an atomic operation.
86
+ # also, clear the line before printing because some shells emit
87
+ # text when control-key combos are pressed (to trigger signals)
88
+ print "#{ANSI_CLEAR_LINE}test-loop: #{message}\n"
85
89
  end
86
90
 
87
91
  def register_signals
@@ -89,11 +93,20 @@ module Test
89
93
  # workers can be killed by sending it to the entire process group
90
94
  trap :TERM, :IGNORE
91
95
 
92
- # clear line to shield normal output from control-key interference:
93
- # some shells like BASH emit text when control-key combos are pressed
94
- trap(:INT) { print ANSI_CLEAR_LINE; throw self }
95
- trap(:QUIT) { print ANSI_CLEAR_LINE; reload_master_process }
96
- trap(:TSTP) { print ANSI_CLEAR_LINE; forcibly_run_all_tests }
96
+ master_pid = $$
97
+ master_trap = lambda do |signal, &handler|
98
+ trap signal do
99
+ if $$ == master_pid
100
+ handler.call
101
+ else
102
+ # ignore future ocurrences of this signal in worker processes
103
+ trap signal, :IGNORE
104
+ end
105
+ end
106
+ end
107
+
108
+ master_trap.call(:QUIT) { reload_master_process }
109
+ master_trap.call(:TSTP) { forcibly_run_all_tests }
97
110
  end
98
111
 
99
112
  def kill_workers
@@ -183,8 +196,9 @@ module Test
183
196
  @lines_by_file[test_file] = new_lines
184
197
 
185
198
  worker_pid = fork do
186
- # unregister custom signal handlers meant for master process
187
- [:TERM, :INT, :QUIT, :TSTP].each {|sig| trap sig, :DEFAULT }
199
+ # this signal is ignored in master and honored in workers, so all
200
+ # workers can be killed by sending it to the entire process group
201
+ trap :TERM, :DEFAULT
188
202
 
189
203
  # capture test output in log file because tests are run in parallel
190
204
  # which makes it difficult to understand interleaved output thereof
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: test-loop
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 10.0.0
5
+ version: 10.0.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Suraj N. Kurapati
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-04-06 00:00:00 -07:00
14
+ date: 2011-04-08 00:00:00 -07:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency