fluentd 1.8.1-x64-mingw32 → 1.9.0-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of fluentd might be problematic. Click here for more details.

Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.gitlab-ci.yml +14 -58
  3. data/.travis.yml +2 -17
  4. data/CHANGELOG.md +39 -0
  5. data/Gemfile +1 -4
  6. data/README.md +2 -6
  7. data/fluentd.gemspec +6 -6
  8. data/lib/fluent/command/cat.rb +1 -3
  9. data/lib/fluent/command/plugin_generator.rb +2 -1
  10. data/lib/fluent/config.rb +19 -0
  11. data/lib/fluent/config/literal_parser.rb +13 -8
  12. data/lib/fluent/config/v1_parser.rb +5 -3
  13. data/lib/fluent/engine.rb +60 -9
  14. data/lib/fluent/ext_monitor_require.rb +28 -0
  15. data/lib/fluent/load.rb +1 -1
  16. data/lib/fluent/msgpack_factory.rb +16 -4
  17. data/lib/fluent/plugin/base.rb +5 -0
  18. data/lib/fluent/plugin/buf_file.rb +10 -6
  19. data/lib/fluent/plugin/buf_file_single.rb +10 -6
  20. data/lib/fluent/plugin/buffer.rb +40 -22
  21. data/lib/fluent/plugin/buffer/chunk.rb +1 -1
  22. data/lib/fluent/plugin/in_http.rb +9 -9
  23. data/lib/fluent/plugin/in_tail.rb +8 -6
  24. data/lib/fluent/plugin/out_http.rb +2 -2
  25. data/lib/fluent/plugin/output.rb +2 -2
  26. data/lib/fluent/plugin/parser.rb +6 -0
  27. data/lib/fluent/plugin_helper/http_server.rb +0 -1
  28. data/lib/fluent/plugin_helper/record_accessor.rb +0 -8
  29. data/lib/fluent/plugin_helper/server.rb +6 -21
  30. data/lib/fluent/plugin_id.rb +9 -4
  31. data/lib/fluent/static_config_analysis.rb +194 -0
  32. data/lib/fluent/supervisor.rb +103 -28
  33. data/lib/fluent/system_config.rb +2 -1
  34. data/lib/fluent/test/driver/base.rb +4 -3
  35. data/lib/fluent/variable_store.rb +40 -0
  36. data/lib/fluent/version.rb +1 -1
  37. data/test/config/test_config_parser.rb +19 -16
  38. data/test/config/test_system_config.rb +6 -4
  39. data/test/plugin/test_in_exec.rb +9 -9
  40. data/test/plugin/test_in_forward.rb +10 -11
  41. data/test/plugin/test_in_http.rb +35 -3
  42. data/test/plugin/test_in_object_space.rb +3 -7
  43. data/test/plugin/test_out_exec_filter.rb +28 -45
  44. data/test/plugin/test_out_forward.rb +2 -2
  45. data/test/plugin/test_out_http.rb +8 -2
  46. data/test/plugin/test_output.rb +3 -3
  47. data/test/plugin/test_output_as_buffered.rb +1 -1
  48. data/test/plugin/test_output_as_buffered_overflow.rb +1 -1
  49. data/test/plugin/test_output_as_buffered_secondary.rb +2 -2
  50. data/test/plugin_helper/test_child_process.rb +45 -56
  51. data/test/plugin_helper/test_server.rb +13 -0
  52. data/test/plugin_helper/test_timer.rb +11 -13
  53. data/test/test_config.rb +27 -5
  54. data/test/test_engine.rb +203 -0
  55. data/test/test_output.rb +2 -2
  56. data/test/test_static_config_analysis.rb +177 -0
  57. data/test/test_supervisor.rb +18 -80
  58. data/test/test_test_drivers.rb +4 -3
  59. data/test/test_variable_store.rb +65 -0
  60. metadata +40 -27
  61. data/.gitlab/cicd-template.yaml +0 -10
  62. data/Vagrantfile +0 -17
@@ -27,7 +27,7 @@ class ObjectSpaceInputTest < Test::Unit::TestCase
27
27
  end
28
28
 
29
29
  TESTCONFIG = %[
30
- emit_interval 1
30
+ emit_interval 0.2
31
31
  tag t1
32
32
  top 2
33
33
  ]
@@ -38,7 +38,7 @@ class ObjectSpaceInputTest < Test::Unit::TestCase
38
38
 
39
39
  def test_configure
40
40
  d = create_driver
41
- assert_equal 1, d.instance.emit_interval
41
+ assert_equal 0.2, d.instance.emit_interval
42
42
  assert_equal "t1", d.instance.tag
43
43
  assert_equal 2, d.instance.top
44
44
  end
@@ -46,11 +46,7 @@ class ObjectSpaceInputTest < Test::Unit::TestCase
46
46
  def test_emit
47
47
  d = create_driver
48
48
 
49
- d.run do
50
- waiting(10, d.instance) do
51
- sleep 0.5 until d.events.size > 3
52
- end
53
- end
49
+ d.run(expect_emits: 3)
54
50
 
55
51
  emits = d.events
56
52
  assert{ emits.length > 0 }
@@ -460,7 +460,7 @@ class ExecFilterOutputTest < Test::Unit::TestCase
460
460
 
461
461
  CONFIG_ROUND_ROBIN = %[
462
462
  command ruby -e 'STDOUT.sync = true; STDIN.each_line{|line| puts line.chomp + "\t" + Process.pid.to_s }'
463
- num_children 3
463
+ num_children 2
464
464
  <inject>
465
465
  tag_key tag
466
466
  time_key time_in
@@ -489,7 +489,7 @@ class ExecFilterOutputTest < Test::Unit::TestCase
489
489
  out_time_key time_out
490
490
  time_format %Y-%m-%d %H:%M:%S
491
491
  localtime
492
- num_children 3
492
+ num_children 2
493
493
  ]
494
494
 
495
495
  data(
@@ -498,53 +498,38 @@ class ExecFilterOutputTest < Test::Unit::TestCase
498
498
  )
499
499
  test 'using child processes by round robin' do |conf|
500
500
  d = create_driver(conf)
501
- time = event_time("2011-01-02 13:14:15")
501
+ time = event_time('2011-01-02 13:14:15')
502
502
 
503
- d.run(default_tag: 'test', expect_emits: 1, timeout: 10, start: true, shutdown: false){ d.feed(time, {"k1"=>1}) }
504
- d.run(default_tag: 'test', expect_emits: 1, timeout: 10, start: false, shutdown: false){ d.feed(time, {"k1"=>2}) }
505
- d.run(default_tag: 'test', expect_emits: 1, timeout: 10, start: false, shutdown: false){ d.feed(time, {"k1"=>3}) }
506
- d.run(default_tag: 'test', expect_emits: 1, timeout: 10, start: false, shutdown: false){ d.feed(time, {"k1"=>4}) }
507
- d.run(default_tag: 'test', expect_emits: 1, timeout: 10, start: false, shutdown: false){ d.feed(time, {"k1"=>5}) }
508
- d.run(default_tag: 'test', expect_emits: 1, timeout: 10, start: false, shutdown: false){ d.feed(time, {"k1"=>6}) }
509
- d.run(default_tag: 'test', expect_emits: 1, timeout: 10, start: false, shutdown: false){ d.feed(time, {"k1"=>7}) }
510
- d.run(default_tag: 'test', expect_emits: 1, timeout: 10, start: false, shutdown: false){ d.feed(time, {"k1"=>8}) }
511
- d.run(default_tag: 'test', expect_emits: 1, timeout: 10, start: false, shutdown: true ){ d.feed(time, {"k1"=>9}) }
503
+ d.run(default_tag: 'test', expect_emits: 1, timeout: 10, start: true, shutdown: false){ d.feed(time, {"k1" => 0}) }
504
+ d.run(default_tag: 'test', expect_emits: 1, timeout: 10, start: false, shutdown: false){ d.feed(time, {"k1" => 1}) }
505
+ d.run(default_tag: 'test', expect_emits: 1, timeout: 10, start: false, shutdown: false){ d.feed(time, {"k1" => 2}) }
506
+ d.run(default_tag: 'test', expect_emits: 1, timeout: 10, start: false, shutdown: false){ d.feed(time, {"k1" => 3}) }
512
507
 
513
- assert_equal "2011-01-02 13:14:15\ttest\t1\n", d.formatted[0]
514
- assert_equal "2011-01-02 13:14:15\ttest\t2\n", d.formatted[1]
515
- assert_equal "2011-01-02 13:14:15\ttest\t3\n", d.formatted[2]
516
- assert_equal "2011-01-02 13:14:15\ttest\t4\n", d.formatted[3]
517
- assert_equal "2011-01-02 13:14:15\ttest\t5\n", d.formatted[4]
518
- assert_equal "2011-01-02 13:14:15\ttest\t6\n", d.formatted[5]
519
- assert_equal "2011-01-02 13:14:15\ttest\t7\n", d.formatted[6]
520
- assert_equal "2011-01-02 13:14:15\ttest\t8\n", d.formatted[7]
521
- assert_equal "2011-01-02 13:14:15\ttest\t9\n", d.formatted[8]
508
+ assert_equal "2011-01-02 13:14:15\ttest\t0\n", d.formatted[0]
509
+ assert_equal "2011-01-02 13:14:15\ttest\t1\n", d.formatted[1]
510
+ assert_equal "2011-01-02 13:14:15\ttest\t2\n", d.formatted[2]
511
+ assert_equal "2011-01-02 13:14:15\ttest\t3\n", d.formatted[3]
522
512
 
523
513
  events = d.events
524
- assert_equal 9, events.length
514
+ assert_equal 4, events.length
525
515
 
526
516
  pid_list = []
527
517
  events.each do |event|
528
518
  pid = event[2]['child_pid']
529
519
  pid_list << pid unless pid_list.include?(pid)
530
520
  end
531
- assert_equal 3, pid_list.size, "the number of pids should be same with number of child processes: #{pid_list.inspect}"
521
+ assert_equal 2, pid_list.size, "the number of pids should be same with number of child processes: #{pid_list.inspect}"
532
522
 
533
523
  assert_equal pid_list[0], events[0][2]['child_pid']
534
524
  assert_equal pid_list[1], events[1][2]['child_pid']
535
- assert_equal pid_list[2], events[2][2]['child_pid']
536
- assert_equal pid_list[0], events[3][2]['child_pid']
537
- assert_equal pid_list[1], events[4][2]['child_pid']
538
- assert_equal pid_list[2], events[5][2]['child_pid']
539
- assert_equal pid_list[0], events[6][2]['child_pid']
540
- assert_equal pid_list[1], events[7][2]['child_pid']
541
- assert_equal pid_list[2], events[8][2]['child_pid']
525
+ assert_equal pid_list[0], events[2][2]['child_pid']
526
+ assert_equal pid_list[1], events[3][2]['child_pid']
542
527
  end
543
528
 
544
529
  # child process exits per 3 lines
545
530
  CONFIG_RESPAWN = %[
546
531
  command ruby -e 'STDOUT.sync = true; proc = ->(){line = STDIN.readline.chomp; puts line + "\t" + Process.pid.to_s}; proc.call; proc.call; proc.call'
547
- num_children 4
532
+ num_children 2
548
533
  child_respawn -1
549
534
  <inject>
550
535
  tag_key tag
@@ -566,7 +551,7 @@ class ExecFilterOutputTest < Test::Unit::TestCase
566
551
 
567
552
  CONFIG_RESPAWN_COMPAT = %[
568
553
  command ruby -e 'STDOUT.sync = true; proc = ->(){line = STDIN.readline.chomp; puts line + "\t" + Process.pid.to_s}; proc.call; proc.call; proc.call'
569
- num_children 4
554
+ num_children 2
570
555
  child_respawn -1
571
556
  in_keys time_in,tag,k1
572
557
  out_keys time_out,tag,k2,child_pid
@@ -584,35 +569,33 @@ class ExecFilterOutputTest < Test::Unit::TestCase
584
569
  test 'emit events via child processes which exits sometimes' do |conf|
585
570
  d = create_driver(conf)
586
571
  time = event_time("2011-01-02 13:14:15")
587
-
588
572
  countup = 0
589
573
 
590
574
  d.run(start: true, shutdown: false)
575
+ assert_equal 2, d.instance.instance_eval{ @_child_process_processes.size }
591
576
 
592
- assert_equal 4, d.instance.instance_eval{ @_child_process_processes.size }
593
-
594
- 20.times do
595
- d.run(default_tag: 'test', expect_emits: 1, timeout: 10, force_flush_retry: true, start: false, shutdown: false) do
596
- d.feed(time, {"k1"=>countup}); countup += 1
597
- d.feed(time, {"k1"=>countup}); countup += 1
598
- d.feed(time, {"k1"=>countup}); countup += 1
577
+ 2.times do
578
+ d.run(default_tag: 'test', expect_emits: 3, timeout: 3, force_flush_retry: true, start: false, shutdown: false) do
579
+ d.feed(time, { "k1" => countup }); countup += 1
580
+ d.feed(time, { "k1" => countup }); countup += 1
581
+ d.feed(time, { "k1" => countup }); countup += 1
599
582
  end
600
583
  end
601
584
 
602
585
  events = d.events
603
- assert_equal 60, events.length
586
+ assert_equal 6, events.length
604
587
 
605
588
  pid_list = []
606
589
  events.each do |event|
607
590
  pid = event[2]['child_pid']
608
591
  pid_list << pid unless pid_list.include?(pid)
609
592
  end
610
- # the number of pids should be same with number of child processes
611
- assert{ pid_list.size >= 18 }
612
593
 
594
+ # the number of pids should be same with number of child processes
595
+ assert_equal 2, pid_list.size
613
596
  logs = d.instance.log.out.logs
614
- assert{ logs.select{|l| l.include?("child process exits with error code") }.size >= 18 } # 20
615
- assert{ logs.select{|l| l.include?("respawning child process") }.size >= 18 } # 20
597
+ assert_equal 2, logs.select { |l| l.include?('child process exits with error code') }.size
598
+ assert_equal 2, logs.select { |l| l.include?('respawning child process') }.size
616
599
 
617
600
  d.run(start: false, shutdown: true)
618
601
  end
@@ -671,7 +671,7 @@ EOL
671
671
 
672
672
  @d = d = create_driver(CONFIG + %[
673
673
  require_ack_response true
674
- ack_response_timeout 5s
674
+ ack_response_timeout 1s
675
675
  <buffer tag>
676
676
  flush_mode immediate
677
677
  retry_type periodic
@@ -699,7 +699,7 @@ EOL
699
699
  end
700
700
  end
701
701
 
702
- assert_equal (5 + 2), delayed_commit_timeout_value
702
+ assert_equal (1 + 2), delayed_commit_timeout_value
703
703
 
704
704
  events = target_input_driver.events
705
705
  assert_equal ['test', time, records[0]], events[0]
@@ -117,7 +117,7 @@ class HTTPOutputTest < Test::Unit::TestCase
117
117
  Fluent::Test.setup
118
118
  FileUtils.rm_rf(TMP_DIR)
119
119
 
120
- @@result = Result.new(nil, nil, {}, nil)
120
+ @@result = Result.new(nil, nil, {}, nil)
121
121
  @@http_server_thread ||= Thread.new do
122
122
  run_http_server
123
123
  end
@@ -230,6 +230,9 @@ class HTTPOutputTest < Test::Unit::TestCase
230
230
  end
231
231
 
232
232
  def test_write_with_retryable_response
233
+ old_report_on_exception = Thread.report_on_exception
234
+ Thread.report_on_exception = false # thread finished as invalid state since RetryableResponse raises.
235
+
233
236
  d = create_driver("endpoint #{base_endpoint}/503")
234
237
  assert_raise(Fluent::Plugin::HTTPOutput::RetryableResponse) do
235
238
  d.run(default_tag: 'test.http', shutdown: false) do
@@ -238,7 +241,10 @@ class HTTPOutputTest < Test::Unit::TestCase
238
241
  }
239
242
  end
240
243
  end
241
- d.instance_shutdown
244
+
245
+ d.instance_shutdown(log: $log)
246
+ ensure
247
+ Thread.report_on_exception = old_report_on_exception
242
248
  end
243
249
 
244
250
  def test_write_with_disabled_unrecoverable
@@ -855,7 +855,7 @@ class OutputTest < Test::Unit::TestCase
855
855
  sub_test_case 'configure secondary' do
856
856
  test "Warn if primary type is different from secondary type and either primary or secondary has custom_format" do
857
857
  o = create_output(:buffered)
858
- mock(o.log).warn("secondary type should be same with primary one",
858
+ mock(o.log).warn("Use different plugin for secondary. Check the plugin works with primary like secondary_file",
859
859
  { primary: o.class.to_s, secondary: "Fluent::Plugin::TestOutput" })
860
860
 
861
861
  o.configure(config_element('ROOT','',{},[config_element('secondary','',{'@type'=>'test', 'name' => "cool"})]))
@@ -864,7 +864,7 @@ class OutputTest < Test::Unit::TestCase
864
864
 
865
865
  test "don't warn if primary type is the same as secondary type" do
866
866
  o = Fluent::Plugin::TestOutput.new
867
- mock(o.log).warn("secondary type should be same with primary one",
867
+ mock(o.log).warn("Use different plugin for secondary. Check the plugin works with primary like secondary_file",
868
868
  { primary: o.class.to_s, secondary: "Fluent::Plugin::TestOutput" }).never
869
869
 
870
870
  o.configure(config_element('ROOT','',{'name' => "cool2"},
@@ -876,7 +876,7 @@ class OutputTest < Test::Unit::TestCase
876
876
 
877
877
  test "don't warn if primary type is different from secondary type and both don't have custom_format" do
878
878
  o = create_output(:standard)
879
- mock(o.log).warn("secondary type should be same with primary one",
879
+ mock(o.log).warn("Use different plugin for secondary. Check the plugin works with primary like secondary_file",
880
880
  { primary: o.class.to_s, secondary: "Fluent::Plugin::TestOutput" }).never
881
881
 
882
882
  o.configure(config_element('ROOT','',{},[config_element('secondary','',{'@type'=>'test', 'name' => "cool"})]))
@@ -699,7 +699,7 @@ class BufferedOutputTest < Test::Unit::TestCase
699
699
  r["key#{i}"] = "value #{i}"
700
700
  end
701
701
 
702
- 3.times do |i|
702
+ 2.times do |i|
703
703
  rand_records = rand(1..4)
704
704
  es = Fluent::ArrayEventStream.new([ [t, r] ] * rand_records)
705
705
  assert_equal rand_records, es.size
@@ -141,7 +141,7 @@ class BufferedOutputOverflowTest < Test::Unit::TestCase
141
141
  assert !@i.buffer.storable?
142
142
 
143
143
  Thread.new do
144
- sleep 3
144
+ sleep 1
145
145
  failing = false
146
146
  end
147
147
 
@@ -153,7 +153,7 @@ class BufferedOutputSecondaryTest < Test::Unit::TestCase
153
153
  i = create_output()
154
154
  i.configure(config_element('ROOT','',{},[priconf,secconf]))
155
155
  logs = i.log.out.logs
156
- assert{ logs.any?{|l| l.include?("secondary type should be same with primary one") } }
156
+ assert{ logs.any?{|l| l.include?("Use different plugin for secondary. Check the plugin works with primary like secondary_file") } }
157
157
  end
158
158
 
159
159
  test 'secondary plugin lifecycle is kicked by primary' do
@@ -162,7 +162,7 @@ class BufferedOutputSecondaryTest < Test::Unit::TestCase
162
162
  i = create_output()
163
163
  i.configure(config_element('ROOT','',{},[priconf,secconf]))
164
164
  logs = i.log.out.logs
165
- assert{ logs.any?{|l| l.include?("secondary type should be same with primary one") } }
165
+ assert{ logs.any?{|l| l.include?("Use different plugin for secondary. Check the plugin works with primary like secondary_file") } }
166
166
 
167
167
  assert i.secondary.configured?
168
168
 
@@ -232,30 +232,26 @@ class ChildProcessTest < Test::Unit::TestCase
232
232
  end
233
233
 
234
234
  test 'can execute external command at just once, which runs forever' do
235
- m = Mutex.new
236
235
  ary = []
237
236
  Timeout.timeout(TEST_DEADLOCK_TIMEOUT) do
238
237
  ran = false
239
- args = ["-e", "while sleep #{TEST_WAIT_INTERVAL_FOR_LOOP}; puts 1; STDOUT.flush; end"]
238
+ args = ["-e", "while sleep 0.1; puts 1; STDOUT.flush; end"]
240
239
  @d.child_process_execute(:t3, "ruby", arguments: args, mode: [:read]) do |io|
241
- m.lock
242
- ran = true
243
240
  begin
244
241
  while @d.child_process_running? && line = io.readline
242
+ ran ||= true
245
243
  ary << line
246
244
  end
247
245
  rescue
248
246
  # ignore
249
- ensure
250
- m.unlock
251
247
  end
252
248
  end
253
- sleep TEST_WAIT_INTERVAL_FOR_BLOCK_RUNNING until m.locked? || ran
254
- sleep TEST_WAIT_INTERVAL_FOR_LOOP * 10
249
+ sleep TEST_WAIT_INTERVAL_FOR_BLOCK_RUNNING until ran
250
+ sleep 1
251
+
255
252
  @d.stop # nothing occurs
256
253
  @d.shutdown
257
-
258
- assert{ ary.size > 5 }
254
+ assert { ary.size >= 4 }
259
255
 
260
256
  @d.close
261
257
 
@@ -272,7 +268,7 @@ class ChildProcessTest < Test::Unit::TestCase
272
268
  ary = []
273
269
  Timeout.timeout(TEST_DEADLOCK_TIMEOUT) do
274
270
  ran = false
275
- @d.child_process_execute(:t4, "ruby -e 'Signal.trap(:TERM, nil); while sleep #{TEST_WAIT_INTERVAL_FOR_LOOP}; puts 1; STDOUT.flush rescue nil; end'", mode: [:read]) do |io|
271
+ @d.child_process_execute(:t4, "ruby -e 'Signal.trap(:TERM, nil); while sleep 0.1; puts 1; STDOUT.flush rescue nil; end'", mode: [:read]) do |io|
276
272
  m.lock
277
273
  ran = true
278
274
  begin
@@ -290,17 +286,17 @@ class ChildProcessTest < Test::Unit::TestCase
290
286
  assert_equal [], @d.log.out.logs
291
287
 
292
288
  @d.stop # nothing occurs
293
- sleep TEST_WAIT_INTERVAL_FOR_LOOP * 5
289
+ sleep TEST_WAIT_INTERVAL_FOR_LOOP
294
290
  lines1 = ary.size
295
291
  assert{ lines1 > 1 }
296
292
 
297
293
  pid = @d._child_process_processes.keys.first
298
-
294
+ # default value 10 is too long for test
295
+ @d.instance_eval { @_child_process_exit_timeout = 1 }
299
296
  @d.shutdown
300
- sleep TEST_WAIT_INTERVAL_FOR_LOOP * 5
297
+ sleep TEST_WAIT_INTERVAL_FOR_LOOP
301
298
  lines2 = ary.size
302
- assert{ lines2 > lines1 }
303
-
299
+ assert { lines2 > lines1 }
304
300
  @d.close
305
301
 
306
302
  assert_nil((Process.waitpid(pid, Process::WNOHANG) rescue nil))
@@ -318,12 +314,12 @@ class ChildProcessTest < Test::Unit::TestCase
318
314
 
319
315
  test 'can execute external command many times, which finishes immediately' do
320
316
  ary = []
321
- arguments = ["-e", "3.times{ puts 'okay'; STDOUT.flush rescue nil; sleep #{TEST_WAIT_INTERVAL_FOR_LOOP} }"] # 0.5 * 3
317
+ arguments = ["-e", "puts 'okay'; STDOUT.flush rescue nil"]
322
318
  Timeout.timeout(TEST_DEADLOCK_TIMEOUT) do
323
- @d.child_process_execute(:t5, "ruby", arguments: arguments, interval: 5, mode: [:read]) do |io|
319
+ @d.child_process_execute(:t5, "ruby", arguments: arguments, interval: 1, mode: [:read]) do |io|
324
320
  ary << io.read.split("\n").map(&:chomp).join
325
321
  end
326
- sleep 13 # 5sec * 2 + 3sec
322
+ sleep 2.5 # 2sec(second invocation) + 0.5sec
327
323
  assert_equal [], @d.log.out.logs
328
324
  @d.stop
329
325
  assert_equal [], @d.log.out.logs
@@ -334,13 +330,12 @@ class ChildProcessTest < Test::Unit::TestCase
334
330
 
335
331
  test 'can execute external command many times, with leading once executed immediately' do
336
332
  ary = []
337
- arguments = ["-e", "3.times{ puts 'okay'; STDOUT.flush rescue nil; sleep #{TEST_WAIT_INTERVAL_FOR_LOOP} }"]
333
+ arguments = ["-e", "puts 'okay'; STDOUT.flush rescue nil"]
338
334
  Timeout.timeout(TEST_DEADLOCK_TIMEOUT) do
339
- @d.child_process_execute(:t6, "ruby", arguments: arguments, interval: 5, immediate: true, mode: [:read]) do |io|
335
+ @d.child_process_execute(:t6, "ruby", arguments: arguments, interval: 1, immediate: true, mode: [:read]) do |io|
340
336
  ary << io.read.split("\n").map(&:chomp).join
341
337
  end
342
- sleep 8 # 5sec * 1 + 3sec
343
- # but expected lines are same with test above
338
+ sleep 1.5 # 2sec(second invocation) + 0.5sec
344
339
  @d.stop; @d.shutdown; @d.close; @d.terminate
345
340
  assert_equal 2, ary.size
346
341
  assert_equal [], @d.log.out.logs
@@ -349,7 +344,7 @@ class ChildProcessTest < Test::Unit::TestCase
349
344
 
350
345
  test 'does not execute long running external command in parallel in default' do
351
346
  ary = []
352
- arguments = ["-e", "10.times{ puts 'okay'; STDOUT.flush rescue nil; sleep #{TEST_WAIT_INTERVAL_FOR_LOOP} }"] # 0.5 * 10
347
+ arguments = ["-e", "10.times{ sleep #{TEST_WAIT_INTERVAL_FOR_LOOP} }"] # 5 sec
353
348
  Timeout.timeout(TEST_DEADLOCK_TIMEOUT) do
354
349
  assert_equal [], @d.log.out.logs
355
350
  @d.log.out.singleton_class.module_eval do
@@ -359,13 +354,13 @@ class ChildProcessTest < Test::Unit::TestCase
359
354
  }
360
355
  end
361
356
 
362
- @d.child_process_execute(:t7, "ruby", arguments: arguments, interval: 2, immediate: true, mode: [:read]) do |io|
357
+ @d.child_process_execute(:t7, "ruby", arguments: arguments, interval: 1, immediate: true, mode: [:read]) do |io|
363
358
  ary << io.read.split("\n").map(&:chomp).join
364
359
  end
365
- sleep 4
360
+ sleep 2
366
361
  assert_equal 1, @d._child_process_processes.size
367
362
  @d.stop
368
- warn_msg = '[warn]: previous child process is still running. skipped. title=:t7 command="ruby" arguments=["-e", "10.times{ puts \'okay\'; STDOUT.flush rescue nil; sleep 0.5 }"] interval=2 parallel=false' + "\n"
363
+ warn_msg = '[warn]: previous child process is still running. skipped. title=:t7 command="ruby" arguments=["-e", "10.times{ sleep 0.5 }"] interval=1 parallel=false' + "\n"
369
364
  logs = @d.log.out.logs
370
365
  assert{ logs.first.end_with?(warn_msg) }
371
366
  assert{ logs.all?{|line| line.end_with?(warn_msg) } }
@@ -376,14 +371,14 @@ class ChildProcessTest < Test::Unit::TestCase
376
371
 
377
372
  test 'can execute long running external command in parallel if specified' do
378
373
  ary = []
379
- arguments = ["-e", "10.times{ puts 'okay'; STDOUT.flush rescue nil; sleep #{TEST_WAIT_INTERVAL_FOR_LOOP} }"] # 0.5 * 10 sec
374
+ arguments = ["-e", "10.times{ puts 'okay'; STDOUT.flush rescue nil; sleep #{TEST_WAIT_INTERVAL_FOR_LOOP} }"] # 5 sec
380
375
  Timeout.timeout(TEST_DEADLOCK_TIMEOUT) do
381
376
  @d.child_process_execute(:t8, "ruby", arguments: arguments, interval: 1, immediate: true, parallel: true, mode: [:read]) do |io|
382
377
  ary << io.read.split("\n").map(&:chomp).join
383
378
  end
384
- sleep 4
379
+ sleep 2
385
380
  processes = @d._child_process_processes.size
386
- assert{ processes >= 3 && processes <= 5 }
381
+ assert { processes >= 2 && processes <= 4 }
387
382
  @d.stop; @d.shutdown; @d.close; @d.terminate
388
383
  assert_equal [], @d.log.out.logs
389
384
  end
@@ -662,14 +657,14 @@ class ChildProcessTest < Test::Unit::TestCase
662
657
  block_exits = false
663
658
  callback_called = false
664
659
  exit_status = nil
665
- args = ['-e', 'sleep ARGV[0].to_i; puts "yay"; File.unlink ARGV[1]', '1', @temp_path]
660
+ args = ['-e', 'puts "yay"; File.unlink ARGV[0]', @temp_path]
666
661
  cb = ->(status){ exit_status = status; callback_called = true }
667
662
 
668
663
  str = nil
669
-
670
664
  pid = nil
671
665
  @d.child_process_execute(:st1, "ruby", arguments: args, mode: [:read], on_exit_callback: cb) do |readio|
672
- pid = @d.instance_eval{ child_process_id }
666
+ assert !callback_called # ensure yet to be called
667
+ pid = @d.instance_eval { child_process_id }
673
668
  str = readio.read.chomp
674
669
  block_exits = true
675
670
  end
@@ -697,16 +692,11 @@ class ChildProcessTest < Test::Unit::TestCase
697
692
  cb = ->(status){ exit_status = status; callback_called = true }
698
693
 
699
694
  str = nil
700
-
701
695
  pid = nil
702
696
  @d.child_process_execute(:st1, "ruby", arguments: args, mode: [:read], on_exit_callback: cb) do |readio|
703
- pid = @d.instance_eval{ child_process_id }
704
- sleep 10 # to run child process correctly
705
- Process.kill(:QUIT, pid)
697
+ pid = @d.instance_eval { child_process_id }
706
698
  sleep 1
707
- Process.kill(:QUIT, pid) rescue nil # once more to send kill
708
- sleep 1
709
- Process.kill(:QUIT, pid) rescue nil # just like sync
699
+ Process.kill(:QUIT, pid)
710
700
  str = readio.read.chomp rescue nil # empty string before EOF
711
701
  block_exits = true
712
702
  end
@@ -717,29 +707,28 @@ class ChildProcessTest < Test::Unit::TestCase
717
707
  assert callback_called
718
708
  assert exit_status
719
709
 
720
- # This test sometimes fails on TravisCI
721
- # with [nil, 11] # SIGSEGV
722
- # or with [1, nil] # ???
723
- assert_equal [nil, 3, true, ""], [exit_status.exitstatus, exit_status.termsig, File.exist?(@temp_path), str] # SIGQUIT
724
- # SIGSEGV looks a kind of BUG of ruby...
710
+ assert_equal nil, exit_status.exitstatus
711
+ assert_equal 3, exit_status.termsig
712
+ assert File.exist?(@temp_path)
713
+ assert_equal '', str
725
714
  end
726
715
 
727
716
  test 'calls on_exit_callback for each process exits for interval call using on_exit_callback' do
728
717
  read_data_list = []
729
718
  exit_status_list = []
730
719
 
731
- args = ['-e', 'puts "yay"', '1']
720
+ args = ['-e', 'puts "yay"']
732
721
  cb = ->(status){ exit_status_list << status }
733
722
 
734
723
  Timeout.timeout(TEST_DEADLOCK_TIMEOUT) do
735
- @d.child_process_execute(:st1, "ruby", arguments: args, immediate: true, interval: 2, mode: [:read], on_exit_callback: cb) do |readio|
724
+ @d.child_process_execute(:st1, "ruby", arguments: args, immediate: true, interval: 1, mode: [:read], on_exit_callback: cb) do |readio|
736
725
  read_data_list << readio.read.chomp
737
726
  end
738
- sleep 10
727
+ sleep 2
739
728
  end
740
729
 
741
- assert{ read_data_list.size >= 3 }
742
- assert{ exit_status_list.size >= 3 }
730
+ assert { read_data_list.size >= 2 }
731
+ assert { exit_status_list.size >= 2 }
743
732
  end
744
733
 
745
734
  test 'waits lasting child process until wait_timeout if block is not specified' do
@@ -747,11 +736,11 @@ class ChildProcessTest < Test::Unit::TestCase
747
736
 
748
737
  callback_called = false
749
738
  exit_status = nil
750
- args = ['-e', 'sleep ARGV[0].to_i; File.unlink ARGV[1]', '1', @temp_path]
739
+ args = ['-e', 'File.unlink ARGV[0]', @temp_path]
751
740
  cb = ->(status){ exit_status = status; callback_called = true }
752
741
 
753
742
  Timeout.timeout(TEST_DEADLOCK_TIMEOUT) do
754
- @d.child_process_execute(:t17, "ruby", arguments: args, on_exit_callback: cb, wait_timeout: 5)
743
+ @d.child_process_execute(:t17, "ruby", arguments: args, on_exit_callback: cb, wait_timeout: 2)
755
744
  sleep TEST_WAIT_INTERVAL_FOR_BLOCK_RUNNING until callback_called
756
745
  end
757
746
 
@@ -766,7 +755,7 @@ class ChildProcessTest < Test::Unit::TestCase
766
755
 
767
756
  callback_called = false
768
757
  exit_status = nil
769
- args = ['-e', 'sleep ARGV[0].to_i; File.unlink ARGV[1]', '3', @temp_path]
758
+ args = ['-e', 'File.unlink ARGV[0]', @temp_path]
770
759
  cb = ->(status){ exit_status = status; callback_called = true }
771
760
 
772
761
  Timeout.timeout(TEST_DEADLOCK_TIMEOUT) do
@@ -791,7 +780,7 @@ class ChildProcessTest < Test::Unit::TestCase
791
780
  cb = ->(status){ exit_status = status; callback_called = true }
792
781
 
793
782
  Timeout.timeout(TEST_DEADLOCK_TIMEOUT) do
794
- @d.child_process_execute(:t17, "ruby", arguments: args, on_exit_callback: cb, wait_timeout: 3)
783
+ @d.child_process_execute(:t17, "ruby", arguments: args, on_exit_callback: cb, wait_timeout: 1)
795
784
  sleep TEST_WAIT_INTERVAL_FOR_BLOCK_RUNNING until callback_called
796
785
  end
797
786
 
@@ -813,8 +802,8 @@ class ChildProcessTest < Test::Unit::TestCase
813
802
  cb = ->(status){ exit_status = status; callback_called = true }
814
803
 
815
804
  Timeout.timeout(TEST_DEADLOCK_TIMEOUT) do
816
- @d.child_process_execute(:t17, "ruby", arguments: args, mode: nil, on_exit_callback: cb, wait_timeout: 3) do
817
- sleep 3
805
+ @d.child_process_execute(:t17, "ruby", arguments: args, mode: nil, on_exit_callback: cb, wait_timeout: 1) do
806
+ sleep 1
818
807
  end
819
808
  sleep TEST_WAIT_INTERVAL_FOR_BLOCK_RUNNING until callback_called
820
809
  end