fluentd 1.14.5-x64-mingw32 → 1.15.1-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 (66) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/config.yml +2 -2
  3. data/.github/workflows/linux-test.yaml +1 -1
  4. data/.github/workflows/macos-test.yaml +5 -1
  5. data/.github/workflows/windows-test.yaml +9 -6
  6. data/CHANGELOG.md +105 -21
  7. data/CONTRIBUTING.md +1 -1
  8. data/MAINTAINERS.md +2 -2
  9. data/README.md +1 -1
  10. data/fluentd.gemspec +2 -1
  11. data/lib/fluent/command/ctl.rb +4 -1
  12. data/lib/fluent/command/fluentd.rb +14 -0
  13. data/lib/fluent/config/literal_parser.rb +2 -2
  14. data/lib/fluent/config/yaml_parser/fluent_value.rb +47 -0
  15. data/lib/fluent/config/yaml_parser/loader.rb +91 -0
  16. data/lib/fluent/config/yaml_parser/parser.rb +166 -0
  17. data/lib/fluent/config/yaml_parser/section_builder.rb +107 -0
  18. data/lib/fluent/config/yaml_parser.rb +56 -0
  19. data/lib/fluent/config.rb +14 -1
  20. data/lib/fluent/error.rb +3 -0
  21. data/lib/fluent/event_router.rb +19 -1
  22. data/lib/fluent/plugin/bare_output.rb +1 -1
  23. data/lib/fluent/plugin/base.rb +19 -0
  24. data/lib/fluent/plugin/file_wrapper.rb +52 -107
  25. data/lib/fluent/plugin/in_forward.rb +1 -1
  26. data/lib/fluent/plugin/in_tail/group_watch.rb +204 -0
  27. data/lib/fluent/plugin/in_tail/position_file.rb +1 -15
  28. data/lib/fluent/plugin/in_tail.rb +68 -48
  29. data/lib/fluent/plugin/out_file.rb +11 -1
  30. data/lib/fluent/plugin/out_forward/socket_cache.rb +2 -0
  31. data/lib/fluent/plugin/output.rb +43 -37
  32. data/lib/fluent/plugin/parser.rb +3 -4
  33. data/lib/fluent/plugin/parser_syslog.rb +1 -1
  34. data/lib/fluent/plugin_helper/retry_state.rb +14 -4
  35. data/lib/fluent/plugin_helper/server.rb +23 -4
  36. data/lib/fluent/plugin_helper/service_discovery.rb +2 -2
  37. data/lib/fluent/rpc.rb +4 -3
  38. data/lib/fluent/supervisor.rb +119 -28
  39. data/lib/fluent/system_config.rb +2 -1
  40. data/lib/fluent/version.rb +1 -1
  41. data/lib/fluent/winsvc.rb +2 -0
  42. data/test/command/test_ctl.rb +0 -1
  43. data/test/command/test_fluentd.rb +33 -0
  44. data/test/config/test_system_config.rb +3 -1
  45. data/test/config/test_types.rb +1 -1
  46. data/test/plugin/in_tail/test_io_handler.rb +14 -4
  47. data/test/plugin/in_tail/test_position_file.rb +0 -63
  48. data/test/plugin/out_forward/test_socket_cache.rb +26 -1
  49. data/test/plugin/test_base.rb +34 -0
  50. data/test/plugin/test_file_wrapper.rb +0 -68
  51. data/test/plugin/test_in_forward.rb +0 -2
  52. data/test/plugin/test_in_object_space.rb +9 -3
  53. data/test/plugin/test_in_syslog.rb +1 -1
  54. data/test/plugin/test_in_tail.rb +629 -353
  55. data/test/plugin/test_out_forward.rb +30 -20
  56. data/test/plugin/test_output_as_buffered_retries.rb +7 -7
  57. data/test/plugin/test_output_as_buffered_secondary.rb +1 -1
  58. data/test/plugin/test_parser_syslog.rb +1 -1
  59. data/test/plugin_helper/test_cert_option.rb +1 -1
  60. data/test/plugin_helper/test_child_process.rb +16 -4
  61. data/test/plugin_helper/test_retry_state.rb +602 -38
  62. data/test/plugin_helper/test_server.rb +18 -0
  63. data/test/test_config.rb +135 -4
  64. data/test/test_event_router.rb +17 -0
  65. data/test/test_supervisor.rb +196 -6
  66. metadata +25 -5
@@ -18,6 +18,21 @@ class RetryStateHelperTest < Test::Unit::TestCase
18
18
  helpers :retry_state
19
19
  end
20
20
 
21
+ class RetryRecord
22
+ attr_reader :retry_count, :elapsed_sec, :is_secondary
23
+ def initialize(retry_count, elapsed_sec, is_secondary)
24
+ @retry_count = retry_count # This is Nth retryment
25
+ @elapsed_sec = elapsed_sec
26
+ @is_secondary = is_secondary
27
+ end
28
+
29
+ def ==(obj)
30
+ @retry_count == obj.retry_count &&
31
+ @elapsed_sec == obj.elapsed_sec &&
32
+ @is_secondary == obj.is_secondary
33
+ end
34
+ end
35
+
21
36
  setup do
22
37
  @d = Dummy.new
23
38
  end
@@ -75,6 +90,7 @@ class RetryStateHelperTest < Test::Unit::TestCase
75
90
  override_current_time(s, s.next_time)
76
91
  s.step
77
92
  assert_equal s.timeout_at, s.next_time
93
+ s.step
78
94
  assert s.limit?
79
95
  end
80
96
 
@@ -100,7 +116,6 @@ class RetryStateHelperTest < Test::Unit::TestCase
100
116
  assert_equal 5, i
101
117
  override_current_time(s, s.next_time)
102
118
  s.step
103
- assert_equal (s.current_time + 3), s.next_time
104
119
  assert s.limit?
105
120
  end
106
121
 
@@ -164,7 +179,9 @@ class RetryStateHelperTest < Test::Unit::TestCase
164
179
  assert s.secondary?
165
180
 
166
181
  s.step
167
- assert_equal s.timeout_at, s.next_time
182
+ assert_equal s.timeout_at, s.next_time # 100
183
+
184
+ s.step
168
185
  assert s.limit?
169
186
  end
170
187
 
@@ -202,7 +219,7 @@ class RetryStateHelperTest < Test::Unit::TestCase
202
219
  while i < 300
203
220
  s.step
204
221
  assert_equal i, s.steps
205
- assert_equal (dummy_current_time + 0.1 * (2 ** (i - 1))), s.next_time
222
+ assert_equal (dummy_current_time + 0.1 * (2 ** i)), s.next_time
206
223
  assert !s.limit?
207
224
  i += 1
208
225
  end
@@ -218,22 +235,22 @@ class RetryStateHelperTest < Test::Unit::TestCase
218
235
  assert_equal 0, s.steps
219
236
  assert_equal (dummy_current_time + 0.1), s.next_time
220
237
 
221
- # 0.1 * (2 ** (10 - 1)) == 0.1 * 2 ** 9 == 51.2
222
- # 0.1 * (2 ** (11 - 1)) == 0.1 * 2 ** 10 == 102.4
238
+ # 0.1 * 2 ** 9 == 51.2
239
+ # 0.1 * 2 ** 10 == 102.4
223
240
  i = 1
224
- while i < 11
241
+ while i < 10
225
242
  s.step
226
243
  assert_equal i, s.steps
227
- assert_equal (dummy_current_time + 0.1 * (2 ** (i - 1))), s.next_time, "start:#{dummy_current_time}, i:#{i}"
244
+ assert_equal (dummy_current_time + 0.1 * (2 ** i)), s.next_time, "start:#{dummy_current_time}, i:#{i}"
228
245
  i += 1
229
246
  end
230
247
 
231
248
  s.step
232
- assert_equal 11, s.steps
249
+ assert_equal 10, s.steps
233
250
  assert_equal (dummy_current_time + 100), s.next_time
234
251
 
235
252
  s.step
236
- assert_equal 12, s.steps
253
+ assert_equal 11, s.steps
237
254
  assert_equal (dummy_current_time + 100), s.next_time
238
255
  end
239
256
 
@@ -249,32 +266,28 @@ class RetryStateHelperTest < Test::Unit::TestCase
249
266
  assert_equal 0, s.steps
250
267
  assert_equal (dummy_current_time + 1), s.next_time
251
268
 
252
- # 1 + 1 + 2 + 4 (=8)
269
+ # 1 + 2 + 4 (=7)
253
270
 
254
271
  override_current_time(s, s.next_time)
255
272
  s.step
256
273
  assert_equal 1, s.steps
257
- assert_equal (s.current_time + 1), s.next_time
258
-
259
- override_current_time(s, s.next_time)
260
- s.step
261
- assert_equal 2, s.steps
262
274
  assert_equal (s.current_time + 2), s.next_time
263
275
 
264
276
  override_current_time(s, s.next_time)
265
277
  s.step
266
- assert_equal 3, s.steps
278
+ assert_equal 2, s.steps
267
279
  assert_equal (s.current_time + 4), s.next_time
268
280
 
269
281
  assert !s.limit?
270
282
 
271
- # + 8 (=16) > 12
283
+ # + 8 (=15) > 12
272
284
 
273
285
  override_current_time(s, s.next_time)
274
286
  s.step
275
- assert_equal 4, s.steps
287
+ assert_equal 3, s.steps
276
288
  assert_equal s.timeout_at, s.next_time
277
289
 
290
+ s.step
278
291
  assert s.limit?
279
292
  end
280
293
 
@@ -293,24 +306,24 @@ class RetryStateHelperTest < Test::Unit::TestCase
293
306
  override_current_time(s, s.next_time)
294
307
  s.step
295
308
  assert_equal 1, s.steps
296
- assert_equal (s.current_time + 1), s.next_time
309
+ assert_equal (s.current_time + 2), s.next_time
297
310
 
298
311
  override_current_time(s, s.next_time)
299
312
  s.step
300
313
  assert_equal 2, s.steps
301
- assert_equal (s.current_time + 2), s.next_time
314
+ assert_equal (s.current_time + 4), s.next_time
302
315
 
303
316
  override_current_time(s, s.next_time)
304
317
  s.step
305
318
  assert_equal 3, s.steps
306
- assert_equal (s.current_time + 4), s.next_time
319
+ assert_equal (s.current_time + 8), s.next_time
307
320
 
308
321
  assert !s.limit?
309
322
 
310
323
  override_current_time(s, s.next_time)
311
324
  s.step
312
325
  assert_equal 4, s.steps
313
- assert_equal (s.current_time + 8), s.next_time
326
+ assert_equal (s.current_time + 10), s.next_time
314
327
 
315
328
  assert !s.limit?
316
329
 
@@ -324,8 +337,6 @@ class RetryStateHelperTest < Test::Unit::TestCase
324
337
  override_current_time(s, s.next_time)
325
338
  s.step
326
339
  assert_equal 6, s.steps
327
- assert_equal (s.current_time + 10), s.next_time
328
-
329
340
  assert s.limit?
330
341
  end
331
342
 
@@ -341,40 +352,42 @@ class RetryStateHelperTest < Test::Unit::TestCase
341
352
  assert_equal (dummy_current_time + 1), s.next_time
342
353
  assert !s.secondary?
343
354
 
344
- # 1, 1(2), 2(4), 4(8), 8(16), 16(32), 32(64), (80), (81), (83), (87), (95), (100)
355
+ # primary: 3, 7, 15, 31, 63, 80 (timeout * threashold)
356
+ # secondary: 81, 83, 87, 95, 100
345
357
  i = 1
346
- while i < 7
358
+ while i < 6
347
359
  override_current_time(s, s.next_time)
348
360
  assert !s.secondary?
349
361
 
350
362
  s.step
351
363
  assert_equal i, s.steps
352
- assert_equal (s.current_time + 1 * (2 ** (i - 1))), s.next_time
364
+ assert_equal (s.current_time + 1 * (2 ** i)), s.next_time
353
365
  assert !s.limit?
354
366
  i += 1
355
367
  end
356
368
 
357
- assert_equal 7, i
358
- override_current_time(s, s.next_time) # 64
369
+ assert_equal 6, i
370
+ override_current_time(s, s.next_time) # 63
359
371
  assert !s.secondary?
360
372
 
361
373
  s.step
362
- assert_equal 7, s.steps
374
+ assert_equal 6, s.steps
363
375
  assert_equal s.secondary_transition_at, s.next_time
364
376
  assert !s.limit?
365
377
 
366
378
  i += 1
367
- assert_equal 8, i
379
+ assert_equal 7, i
368
380
  override_current_time(s, s.next_time) # 80
369
381
  assert s.secondary?
370
382
 
371
383
  s.step
372
- assert_equal 8, s.steps
384
+ assert_equal 7, s.steps
373
385
  assert_equal s.steps, s.secondary_transition_steps
374
- assert_equal (s.secondary_transition_at + 1.0), s.next_time
386
+ assert_equal (s.secondary_transition_at + 1.0), s.next_time # 81
375
387
  assert !s.limit?
388
+ assert_equal :secondary, s.current
376
389
 
377
- # 81, 82, 84, 88, 96, 100
390
+ # 83, 87, 95, 100
378
391
  j = 1
379
392
  while j < 4
380
393
  override_current_time(s, s.next_time)
@@ -382,18 +395,20 @@ class RetryStateHelperTest < Test::Unit::TestCase
382
395
  assert_equal :secondary, s.current
383
396
 
384
397
  s.step
385
- assert_equal (8 + j), s.steps
398
+ assert_equal (7 + j), s.steps
386
399
  assert_equal (s.current_time + (1 * (2 ** j))), s.next_time
387
400
  assert !s.limit?, "j:#{j}"
388
401
  j += 1
389
402
  end
390
403
 
391
404
  assert_equal 4, j
392
- override_current_time(s, s.next_time) # 96
405
+ override_current_time(s, s.next_time) # 95
393
406
  assert s.secondary?
394
407
 
395
408
  s.step
396
- assert_equal s.timeout_at, s.next_time
409
+ assert_equal s.timeout_at, s.next_time # 100
410
+
411
+ s.step
397
412
  assert s.limit?
398
413
  end
399
414
 
@@ -413,7 +428,7 @@ class RetryStateHelperTest < Test::Unit::TestCase
413
428
  override_current_time(s, dummy_current_time)
414
429
 
415
430
  timeout = 0
416
- 5.times { |i| timeout += 1.0 * (2 ** (i - 1)) }
431
+ 5.times { |i| timeout += 1.0 * (2 ** i) }
417
432
 
418
433
  assert_equal dummy_current_time, s.current_time
419
434
  assert_equal (dummy_current_time + 100), s.timeout_at
@@ -439,4 +454,553 @@ class RetryStateHelperTest < Test::Unit::TestCase
439
454
  end
440
455
  end
441
456
  end
457
+
458
+ sub_test_case "ExponentialBackOff_ScenarioTests" do
459
+ data("Simple timeout", {
460
+ timeout: 100, max_steps: nil, max_interval: nil, use_sec: false, sec_thres: 0.8, wait: 1, backoff_base: 2,
461
+ expected: [
462
+ RetryRecord.new(1, 1, false),
463
+ RetryRecord.new(2, 3, false),
464
+ RetryRecord.new(3, 7, false),
465
+ RetryRecord.new(4, 15, false),
466
+ RetryRecord.new(5, 31, false),
467
+ RetryRecord.new(6, 63, false),
468
+ RetryRecord.new(7, 100, false),
469
+ ],
470
+ })
471
+ data("Simple timeout with secondary", {
472
+ timeout: 100, max_steps: nil, max_interval: nil, use_sec: true, sec_thres: 0.8, wait: 1, backoff_base: 2,
473
+ expected: [
474
+ RetryRecord.new(1, 1, false),
475
+ RetryRecord.new(2, 3, false),
476
+ RetryRecord.new(3, 7, false),
477
+ RetryRecord.new(4, 15, false),
478
+ RetryRecord.new(5, 31, false),
479
+ RetryRecord.new(6, 63, false),
480
+ RetryRecord.new(7, 80, true),
481
+ RetryRecord.new(8, 81, true),
482
+ RetryRecord.new(9, 83, true),
483
+ RetryRecord.new(10, 87, true),
484
+ RetryRecord.new(11, 95, true),
485
+ RetryRecord.new(12, 100, true),
486
+ ],
487
+ })
488
+ data("Simple timeout with custom wait and backoff_base", {
489
+ timeout: 1000, max_steps: nil, max_interval: nil, use_sec: false, sec_thres: 0.8, wait: 2, backoff_base: 3,
490
+ expected: [
491
+ RetryRecord.new(1, 2, false),
492
+ RetryRecord.new(2, 8, false),
493
+ RetryRecord.new(3, 26, false),
494
+ RetryRecord.new(4, 80, false),
495
+ RetryRecord.new(5, 242, false),
496
+ RetryRecord.new(6, 728, false),
497
+ RetryRecord.new(7, 1000, false),
498
+ ],
499
+ })
500
+ data("Simple timeout with custom wait and backoff_base and secondary", {
501
+ timeout: 1000, max_steps: nil, max_interval: nil, use_sec: true, sec_thres: 0.8, wait: 2, backoff_base: 3,
502
+ expected: [
503
+ RetryRecord.new(1, 2, false),
504
+ RetryRecord.new(2, 8, false),
505
+ RetryRecord.new(3, 26, false),
506
+ RetryRecord.new(4, 80, false),
507
+ RetryRecord.new(5, 242, false),
508
+ RetryRecord.new(6, 728, false),
509
+ RetryRecord.new(7, 800, true),
510
+ RetryRecord.new(8, 802, true),
511
+ RetryRecord.new(9, 808, true),
512
+ RetryRecord.new(10, 826, true),
513
+ RetryRecord.new(11, 880, true),
514
+ RetryRecord.new(12, 1000, true),
515
+ ],
516
+ })
517
+ data("Default timeout", {
518
+ timeout: 72*3600, max_steps: nil, max_interval: nil, use_sec: false, sec_thres: 0.8, wait: 1, backoff_base: 2,
519
+ expected: [
520
+ RetryRecord.new(1, 1, false),
521
+ RetryRecord.new(2, 3, false),
522
+ RetryRecord.new(3, 7, false),
523
+ RetryRecord.new(4, 15, false),
524
+ RetryRecord.new(5, 31, false),
525
+ RetryRecord.new(6, 63, false),
526
+ RetryRecord.new(7, 127, false),
527
+ RetryRecord.new(8, 255, false),
528
+ RetryRecord.new(9, 511, false),
529
+ RetryRecord.new(10, 1023, false),
530
+ RetryRecord.new(11, 2047, false),
531
+ RetryRecord.new(12, 4095, false),
532
+ RetryRecord.new(13, 8191, false),
533
+ RetryRecord.new(14, 16383, false),
534
+ RetryRecord.new(15, 32767, false),
535
+ RetryRecord.new(16, 65535, false),
536
+ RetryRecord.new(17, 131071, false),
537
+ RetryRecord.new(18, 259200, false),
538
+ ],
539
+ })
540
+ data("Default timeout with secondary", {
541
+ timeout: 72*3600, max_steps: nil, max_interval: nil, use_sec: true, sec_thres: 0.8, wait: 1, backoff_base: 2,
542
+ expected: [
543
+ RetryRecord.new(1, 1, false),
544
+ RetryRecord.new(2, 3, false),
545
+ RetryRecord.new(3, 7, false),
546
+ RetryRecord.new(4, 15, false),
547
+ RetryRecord.new(5, 31, false),
548
+ RetryRecord.new(6, 63, false),
549
+ RetryRecord.new(7, 127, false),
550
+ RetryRecord.new(8, 255, false),
551
+ RetryRecord.new(9, 511, false),
552
+ RetryRecord.new(10, 1023, false),
553
+ RetryRecord.new(11, 2047, false),
554
+ RetryRecord.new(12, 4095, false),
555
+ RetryRecord.new(13, 8191, false),
556
+ RetryRecord.new(14, 16383, false),
557
+ RetryRecord.new(15, 32767, false),
558
+ RetryRecord.new(16, 65535, false),
559
+ RetryRecord.new(17, 131071, false),
560
+ RetryRecord.new(18, 207360, true),
561
+ RetryRecord.new(19, 207361, true),
562
+ RetryRecord.new(20, 207363, true),
563
+ RetryRecord.new(21, 207367, true),
564
+ RetryRecord.new(22, 207375, true),
565
+ RetryRecord.new(23, 207391, true),
566
+ RetryRecord.new(24, 207423, true),
567
+ RetryRecord.new(25, 207487, true),
568
+ RetryRecord.new(26, 207615, true),
569
+ RetryRecord.new(27, 207871, true),
570
+ RetryRecord.new(28, 208383, true),
571
+ RetryRecord.new(29, 209407, true),
572
+ RetryRecord.new(30, 211455, true),
573
+ RetryRecord.new(31, 215551, true),
574
+ RetryRecord.new(32, 223743, true),
575
+ RetryRecord.new(33, 240127, true),
576
+ RetryRecord.new(34, 259200, true),
577
+ ],
578
+ })
579
+ data("Default timeout with secondary and custom threshold", {
580
+ timeout: 72*3600, max_steps: nil, max_interval: nil, use_sec: true, sec_thres: 0.5, wait: 1, backoff_base: 2,
581
+ expected: [
582
+ RetryRecord.new(1, 1, false),
583
+ RetryRecord.new(2, 3, false),
584
+ RetryRecord.new(3, 7, false),
585
+ RetryRecord.new(4, 15, false),
586
+ RetryRecord.new(5, 31, false),
587
+ RetryRecord.new(6, 63, false),
588
+ RetryRecord.new(7, 127, false),
589
+ RetryRecord.new(8, 255, false),
590
+ RetryRecord.new(9, 511, false),
591
+ RetryRecord.new(10, 1023, false),
592
+ RetryRecord.new(11, 2047, false),
593
+ RetryRecord.new(12, 4095, false),
594
+ RetryRecord.new(13, 8191, false),
595
+ RetryRecord.new(14, 16383, false),
596
+ RetryRecord.new(15, 32767, false),
597
+ RetryRecord.new(16, 65535, false),
598
+ RetryRecord.new(17, 129600, true),
599
+ RetryRecord.new(18, 129601, true),
600
+ RetryRecord.new(19, 129603, true),
601
+ RetryRecord.new(20, 129607, true),
602
+ RetryRecord.new(21, 129615, true),
603
+ RetryRecord.new(22, 129631, true),
604
+ RetryRecord.new(23, 129663, true),
605
+ RetryRecord.new(24, 129727, true),
606
+ RetryRecord.new(25, 129855, true),
607
+ RetryRecord.new(26, 130111, true),
608
+ RetryRecord.new(27, 130623, true),
609
+ RetryRecord.new(28, 131647, true),
610
+ RetryRecord.new(29, 133695, true),
611
+ RetryRecord.new(30, 137791, true),
612
+ RetryRecord.new(31, 145983, true),
613
+ RetryRecord.new(32, 162367, true),
614
+ RetryRecord.new(33, 195135, true),
615
+ RetryRecord.new(34, 259200, true),
616
+ ],
617
+ })
618
+ data("Simple max_steps", {
619
+ timeout: 72*3600, max_steps: 10, max_interval: nil, use_sec: false, sec_thres: 0.8, wait: 1, backoff_base: 2,
620
+ expected: [
621
+ RetryRecord.new(1, 1, false),
622
+ RetryRecord.new(2, 3, false),
623
+ RetryRecord.new(3, 7, false),
624
+ RetryRecord.new(4, 15, false),
625
+ RetryRecord.new(5, 31, false),
626
+ RetryRecord.new(6, 63, false),
627
+ RetryRecord.new(7, 127, false),
628
+ RetryRecord.new(8, 255, false),
629
+ RetryRecord.new(9, 511, false),
630
+ RetryRecord.new(10, 1023, false),
631
+ ],
632
+ })
633
+ data("Simple max_steps with secondary", {
634
+ timeout: 72*3600, max_steps: 10, max_interval: nil, use_sec: true, sec_thres: 0.8, wait: 1, backoff_base: 2,
635
+ expected: [
636
+ RetryRecord.new(1, 1, false),
637
+ RetryRecord.new(2, 3, false),
638
+ RetryRecord.new(3, 7, false),
639
+ RetryRecord.new(4, 15, false),
640
+ RetryRecord.new(5, 31, false),
641
+ RetryRecord.new(6, 63, false),
642
+ RetryRecord.new(7, 127, false),
643
+ RetryRecord.new(8, 255, false),
644
+ RetryRecord.new(9, 511, false),
645
+ RetryRecord.new(10, 818, true),
646
+ ],
647
+ })
648
+ data("Simple interval", {
649
+ timeout: 72*3600, max_steps: nil, max_interval: 3600, use_sec: false, sec_thres: 0.8, wait: 1, backoff_base: 2,
650
+ expected: [
651
+ RetryRecord.new(1, 1, false),
652
+ RetryRecord.new(2, 3, false),
653
+ RetryRecord.new(3, 7, false),
654
+ RetryRecord.new(4, 15, false),
655
+ RetryRecord.new(5, 31, false),
656
+ RetryRecord.new(6, 63, false),
657
+ RetryRecord.new(7, 127, false),
658
+ RetryRecord.new(8, 255, false),
659
+ RetryRecord.new(9, 511, false),
660
+ RetryRecord.new(10, 1023, false),
661
+ RetryRecord.new(11, 2047, false),
662
+ RetryRecord.new(12, 4095, false),
663
+ RetryRecord.new(13, 7695, false),
664
+ RetryRecord.new(14, 11295, false),
665
+ RetryRecord.new(15, 14895, false),
666
+ RetryRecord.new(16, 18495, false),
667
+ RetryRecord.new(17, 22095, false),
668
+ RetryRecord.new(18, 25695, false),
669
+ RetryRecord.new(19, 29295, false),
670
+ RetryRecord.new(20, 32895, false),
671
+ RetryRecord.new(21, 36495, false),
672
+ RetryRecord.new(22, 40095, false),
673
+ RetryRecord.new(23, 43695, false),
674
+ RetryRecord.new(24, 47295, false),
675
+ RetryRecord.new(25, 50895, false),
676
+ RetryRecord.new(26, 54495, false),
677
+ RetryRecord.new(27, 58095, false),
678
+ RetryRecord.new(28, 61695, false),
679
+ RetryRecord.new(29, 65295, false),
680
+ RetryRecord.new(30, 68895, false),
681
+ RetryRecord.new(31, 72495, false),
682
+ RetryRecord.new(32, 76095, false),
683
+ RetryRecord.new(33, 79695, false),
684
+ RetryRecord.new(34, 83295, false),
685
+ RetryRecord.new(35, 86895, false),
686
+ RetryRecord.new(36, 90495, false),
687
+ RetryRecord.new(37, 94095, false),
688
+ RetryRecord.new(38, 97695, false),
689
+ RetryRecord.new(39, 101295, false),
690
+ RetryRecord.new(40, 104895, false),
691
+ RetryRecord.new(41, 108495, false),
692
+ RetryRecord.new(42, 112095, false),
693
+ RetryRecord.new(43, 115695, false),
694
+ RetryRecord.new(44, 119295, false),
695
+ RetryRecord.new(45, 122895, false),
696
+ RetryRecord.new(46, 126495, false),
697
+ RetryRecord.new(47, 130095, false),
698
+ RetryRecord.new(48, 133695, false),
699
+ RetryRecord.new(49, 137295, false),
700
+ RetryRecord.new(50, 140895, false),
701
+ RetryRecord.new(51, 144495, false),
702
+ RetryRecord.new(52, 148095, false),
703
+ RetryRecord.new(53, 151695, false),
704
+ RetryRecord.new(54, 155295, false),
705
+ RetryRecord.new(55, 158895, false),
706
+ RetryRecord.new(56, 162495, false),
707
+ RetryRecord.new(57, 166095, false),
708
+ RetryRecord.new(58, 169695, false),
709
+ RetryRecord.new(59, 173295, false),
710
+ RetryRecord.new(60, 176895, false),
711
+ RetryRecord.new(61, 180495, false),
712
+ RetryRecord.new(62, 184095, false),
713
+ RetryRecord.new(63, 187695, false),
714
+ RetryRecord.new(64, 191295, false),
715
+ RetryRecord.new(65, 194895, false),
716
+ RetryRecord.new(66, 198495, false),
717
+ RetryRecord.new(67, 202095, false),
718
+ RetryRecord.new(68, 205695, false),
719
+ RetryRecord.new(69, 209295, false),
720
+ RetryRecord.new(70, 212895, false),
721
+ RetryRecord.new(71, 216495, false),
722
+ RetryRecord.new(72, 220095, false),
723
+ RetryRecord.new(73, 223695, false),
724
+ RetryRecord.new(74, 227295, false),
725
+ RetryRecord.new(75, 230895, false),
726
+ RetryRecord.new(76, 234495, false),
727
+ RetryRecord.new(77, 238095, false),
728
+ RetryRecord.new(78, 241695, false),
729
+ RetryRecord.new(79, 245295, false),
730
+ RetryRecord.new(80, 248895, false),
731
+ RetryRecord.new(81, 252495, false),
732
+ RetryRecord.new(82, 256095, false),
733
+ RetryRecord.new(83, 259200, false),
734
+ ],
735
+ })
736
+ data("Simple interval with secondary", {
737
+ timeout: 72*3600, max_steps: nil, max_interval: 3600, use_sec: true, sec_thres: 0.8, wait: 1, backoff_base: 2,
738
+ expected: [
739
+ RetryRecord.new(1, 1, false),
740
+ RetryRecord.new(2, 3, false),
741
+ RetryRecord.new(3, 7, false),
742
+ RetryRecord.new(4, 15, false),
743
+ RetryRecord.new(5, 31, false),
744
+ RetryRecord.new(6, 63, false),
745
+ RetryRecord.new(7, 127, false),
746
+ RetryRecord.new(8, 255, false),
747
+ RetryRecord.new(9, 511, false),
748
+ RetryRecord.new(10, 1023, false),
749
+ RetryRecord.new(11, 2047, false),
750
+ RetryRecord.new(12, 4095, false),
751
+ RetryRecord.new(13, 7695, false),
752
+ RetryRecord.new(14, 11295, false),
753
+ RetryRecord.new(15, 14895, false),
754
+ RetryRecord.new(16, 18495, false),
755
+ RetryRecord.new(17, 22095, false),
756
+ RetryRecord.new(18, 25695, false),
757
+ RetryRecord.new(19, 29295, false),
758
+ RetryRecord.new(20, 32895, false),
759
+ RetryRecord.new(21, 36495, false),
760
+ RetryRecord.new(22, 40095, false),
761
+ RetryRecord.new(23, 43695, false),
762
+ RetryRecord.new(24, 47295, false),
763
+ RetryRecord.new(25, 50895, false),
764
+ RetryRecord.new(26, 54495, false),
765
+ RetryRecord.new(27, 58095, false),
766
+ RetryRecord.new(28, 61695, false),
767
+ RetryRecord.new(29, 65295, false),
768
+ RetryRecord.new(30, 68895, false),
769
+ RetryRecord.new(31, 72495, false),
770
+ RetryRecord.new(32, 76095, false),
771
+ RetryRecord.new(33, 79695, false),
772
+ RetryRecord.new(34, 83295, false),
773
+ RetryRecord.new(35, 86895, false),
774
+ RetryRecord.new(36, 90495, false),
775
+ RetryRecord.new(37, 94095, false),
776
+ RetryRecord.new(38, 97695, false),
777
+ RetryRecord.new(39, 101295, false),
778
+ RetryRecord.new(40, 104895, false),
779
+ RetryRecord.new(41, 108495, false),
780
+ RetryRecord.new(42, 112095, false),
781
+ RetryRecord.new(43, 115695, false),
782
+ RetryRecord.new(44, 119295, false),
783
+ RetryRecord.new(45, 122895, false),
784
+ RetryRecord.new(46, 126495, false),
785
+ RetryRecord.new(47, 130095, false),
786
+ RetryRecord.new(48, 133695, false),
787
+ RetryRecord.new(49, 137295, false),
788
+ RetryRecord.new(50, 140895, false),
789
+ RetryRecord.new(51, 144495, false),
790
+ RetryRecord.new(52, 148095, false),
791
+ RetryRecord.new(53, 151695, false),
792
+ RetryRecord.new(54, 155295, false),
793
+ RetryRecord.new(55, 158895, false),
794
+ RetryRecord.new(56, 162495, false),
795
+ RetryRecord.new(57, 166095, false),
796
+ RetryRecord.new(58, 169695, false),
797
+ RetryRecord.new(59, 173295, false),
798
+ RetryRecord.new(60, 176895, false),
799
+ RetryRecord.new(61, 180495, false),
800
+ RetryRecord.new(62, 184095, false),
801
+ RetryRecord.new(63, 187695, false),
802
+ RetryRecord.new(64, 191295, false),
803
+ RetryRecord.new(65, 194895, false),
804
+ RetryRecord.new(66, 198495, false),
805
+ RetryRecord.new(67, 202095, false),
806
+ RetryRecord.new(68, 205695, false),
807
+ RetryRecord.new(69, 207360, true),
808
+ RetryRecord.new(70, 207361, true),
809
+ RetryRecord.new(71, 207363, true),
810
+ RetryRecord.new(72, 207367, true),
811
+ RetryRecord.new(73, 207375, true),
812
+ RetryRecord.new(74, 207391, true),
813
+ RetryRecord.new(75, 207423, true),
814
+ RetryRecord.new(76, 207487, true),
815
+ RetryRecord.new(77, 207615, true),
816
+ RetryRecord.new(78, 207871, true),
817
+ RetryRecord.new(79, 208383, true),
818
+ RetryRecord.new(80, 209407, true),
819
+ RetryRecord.new(81, 211455, true),
820
+ RetryRecord.new(82, 215055, true),
821
+ RetryRecord.new(83, 218655, true),
822
+ RetryRecord.new(84, 222255, true),
823
+ RetryRecord.new(85, 225855, true),
824
+ RetryRecord.new(86, 229455, true),
825
+ RetryRecord.new(87, 233055, true),
826
+ RetryRecord.new(88, 236655, true),
827
+ RetryRecord.new(89, 240255, true),
828
+ RetryRecord.new(90, 243855, true),
829
+ RetryRecord.new(91, 247455, true),
830
+ RetryRecord.new(92, 251055, true),
831
+ RetryRecord.new(93, 254655, true),
832
+ RetryRecord.new(94, 258255, true),
833
+ RetryRecord.new(95, 259200, true),
834
+ ],
835
+ })
836
+ data("Max_steps and max_interval", {
837
+ timeout: 72*3600, max_steps: 30, max_interval: 3600, use_sec: false, sec_thres: 0.8, wait: 1, backoff_base: 2,
838
+ expected: [
839
+ RetryRecord.new(1, 1, false),
840
+ RetryRecord.new(2, 3, false),
841
+ RetryRecord.new(3, 7, false),
842
+ RetryRecord.new(4, 15, false),
843
+ RetryRecord.new(5, 31, false),
844
+ RetryRecord.new(6, 63, false),
845
+ RetryRecord.new(7, 127, false),
846
+ RetryRecord.new(8, 255, false),
847
+ RetryRecord.new(9, 511, false),
848
+ RetryRecord.new(10, 1023, false),
849
+ RetryRecord.new(11, 2047, false),
850
+ RetryRecord.new(12, 4095, false),
851
+ RetryRecord.new(13, 7695, false),
852
+ RetryRecord.new(14, 11295, false),
853
+ RetryRecord.new(15, 14895, false),
854
+ RetryRecord.new(16, 18495, false),
855
+ RetryRecord.new(17, 22095, false),
856
+ RetryRecord.new(18, 25695, false),
857
+ RetryRecord.new(19, 29295, false),
858
+ RetryRecord.new(20, 32895, false),
859
+ RetryRecord.new(21, 36495, false),
860
+ RetryRecord.new(22, 40095, false),
861
+ RetryRecord.new(23, 43695, false),
862
+ RetryRecord.new(24, 47295, false),
863
+ RetryRecord.new(25, 50895, false),
864
+ RetryRecord.new(26, 54495, false),
865
+ RetryRecord.new(27, 58095, false),
866
+ RetryRecord.new(28, 61695, false),
867
+ RetryRecord.new(29, 65295, false),
868
+ RetryRecord.new(30, 68895, false),
869
+ ],
870
+ })
871
+ data("Max_steps and max_interval with secondary", {
872
+ timeout: 72*3600, max_steps: 30, max_interval: 3600, use_sec: true, sec_thres: 0.8, wait: 1, backoff_base: 2,
873
+ expected: [
874
+ RetryRecord.new(1, 1, false),
875
+ RetryRecord.new(2, 3, false),
876
+ RetryRecord.new(3, 7, false),
877
+ RetryRecord.new(4, 15, false),
878
+ RetryRecord.new(5, 31, false),
879
+ RetryRecord.new(6, 63, false),
880
+ RetryRecord.new(7, 127, false),
881
+ RetryRecord.new(8, 255, false),
882
+ RetryRecord.new(9, 511, false),
883
+ RetryRecord.new(10, 1023, false),
884
+ RetryRecord.new(11, 2047, false),
885
+ RetryRecord.new(12, 4095, false),
886
+ RetryRecord.new(13, 7695, false),
887
+ RetryRecord.new(14, 11295, false),
888
+ RetryRecord.new(15, 14895, false),
889
+ RetryRecord.new(16, 18495, false),
890
+ RetryRecord.new(17, 22095, false),
891
+ RetryRecord.new(18, 25695, false),
892
+ RetryRecord.new(19, 29295, false),
893
+ RetryRecord.new(20, 32895, false),
894
+ RetryRecord.new(21, 36495, false),
895
+ RetryRecord.new(22, 40095, false),
896
+ RetryRecord.new(23, 43695, false),
897
+ RetryRecord.new(24, 47295, false),
898
+ RetryRecord.new(25, 50895, false),
899
+ RetryRecord.new(26, 54495, false),
900
+ RetryRecord.new(27, 55116, true),
901
+ RetryRecord.new(28, 55117, true),
902
+ RetryRecord.new(29, 55119, true),
903
+ RetryRecord.new(30, 55123, true),
904
+ ],
905
+ })
906
+ data("Max_steps and max_interval with timeout", {
907
+ timeout: 10000, max_steps: 30, max_interval: 1000, use_sec: false, sec_thres: 0.8, wait: 1, backoff_base: 2,
908
+ expected: [
909
+ RetryRecord.new(1, 1, false),
910
+ RetryRecord.new(2, 3, false),
911
+ RetryRecord.new(3, 7, false),
912
+ RetryRecord.new(4, 15, false),
913
+ RetryRecord.new(5, 31, false),
914
+ RetryRecord.new(6, 63, false),
915
+ RetryRecord.new(7, 127, false),
916
+ RetryRecord.new(8, 255, false),
917
+ RetryRecord.new(9, 511, false),
918
+ RetryRecord.new(10, 1023, false),
919
+ RetryRecord.new(11, 2023, false),
920
+ RetryRecord.new(12, 3023, false),
921
+ RetryRecord.new(13, 4023, false),
922
+ RetryRecord.new(14, 5023, false),
923
+ RetryRecord.new(15, 6023, false),
924
+ RetryRecord.new(16, 7023, false),
925
+ RetryRecord.new(17, 8023, false),
926
+ RetryRecord.new(18, 9023, false),
927
+ RetryRecord.new(19, 10000, false),
928
+ ],
929
+ })
930
+ data("Max_steps and max_interval with timeout and secondary", {
931
+ timeout: 10000, max_steps: 30, max_interval: 1000, use_sec: true, sec_thres: 0.8, wait: 1, backoff_base: 2,
932
+ expected: [
933
+ RetryRecord.new(1, 1, false),
934
+ RetryRecord.new(2, 3, false),
935
+ RetryRecord.new(3, 7, false),
936
+ RetryRecord.new(4, 15, false),
937
+ RetryRecord.new(5, 31, false),
938
+ RetryRecord.new(6, 63, false),
939
+ RetryRecord.new(7, 127, false),
940
+ RetryRecord.new(8, 255, false),
941
+ RetryRecord.new(9, 511, false),
942
+ RetryRecord.new(10, 1023, false),
943
+ RetryRecord.new(11, 2023, false),
944
+ RetryRecord.new(12, 3023, false),
945
+ RetryRecord.new(13, 4023, false),
946
+ RetryRecord.new(14, 5023, false),
947
+ RetryRecord.new(15, 6023, false),
948
+ RetryRecord.new(16, 7023, false),
949
+ RetryRecord.new(17, 8000, true),
950
+ RetryRecord.new(18, 8001, true),
951
+ RetryRecord.new(19, 8003, true),
952
+ RetryRecord.new(20, 8007, true),
953
+ RetryRecord.new(21, 8015, true),
954
+ RetryRecord.new(22, 8031, true),
955
+ RetryRecord.new(23, 8063, true),
956
+ RetryRecord.new(24, 8127, true),
957
+ RetryRecord.new(25, 8255, true),
958
+ RetryRecord.new(26, 8511, true),
959
+ RetryRecord.new(27, 9023, true),
960
+ RetryRecord.new(28, 10000, true),
961
+ ],
962
+ })
963
+ test "exponential backoff with senario" do |data|
964
+ print_for_debug = false # change this value true if need to see msg always.
965
+ trying_count = 1000 # just for avoiding infinite loop
966
+
967
+ retry_records = []
968
+ msg = ""
969
+
970
+ s = @d.retry_state_create(
971
+ :t15, :exponential_backoff, data[:wait], data[:timeout],
972
+ max_steps: data[:max_steps], max_interval: data[:max_interval],
973
+ secondary: data[:use_sec], secondary_threshold: data[:sec_thres],
974
+ backoff_base: data[:backoff_base], randomize: false
975
+ )
976
+ override_current_time(s, s.start)
977
+
978
+ retry_count = 0
979
+ trying_count.times do
980
+ next_elapsed = (s.next_time - s.start).to_i
981
+
982
+ msg << "step: #{s.steps}, next: #{next_elapsed}s (#{next_elapsed / 3600}h)\n"
983
+
984
+ # Wait until next time to trigger the next retry
985
+ override_current_time(s, s.next_time)
986
+
987
+ # Retry will be triggered at this point.
988
+ retry_count += 1
989
+ rec = RetryRecord.new(retry_count, next_elapsed, s.secondary?)
990
+ retry_records.append(rec)
991
+ msg << "[#{next_elapsed}s elapsed point] #{retry_count}th-Retry(#{s.secondary? ? "SEC" : "PRI"}) is triggered.\n"
992
+
993
+ # Update retry statement
994
+ s.step
995
+ if s.limit?
996
+ msg << "--- Reach limit. ---\n"
997
+ break
998
+ end
999
+ end
1000
+
1001
+ assert_equal(data[:expected], retry_records, msg)
1002
+
1003
+ print(msg) if print_for_debug
1004
+ end
1005
+ end
442
1006
  end