fluentd 1.16.5-x86-mingw32 → 1.17.1-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (268) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +88 -0
  3. data/README.md +2 -1
  4. data/Rakefile +1 -1
  5. data/SECURITY.md +2 -2
  6. data/fluent.conf +14 -14
  7. data/lib/fluent/command/binlog_reader.rb +1 -1
  8. data/lib/fluent/command/cap_ctl.rb +4 -4
  9. data/lib/fluent/compat/call_super_mixin.rb +3 -3
  10. data/lib/fluent/compat/propagate_default.rb +4 -4
  11. data/lib/fluent/config/configure_proxy.rb +2 -2
  12. data/lib/fluent/config/types.rb +1 -1
  13. data/lib/fluent/config/yaml_parser/parser.rb +4 -0
  14. data/lib/fluent/configurable.rb +2 -2
  15. data/lib/fluent/counter/mutex_hash.rb +1 -1
  16. data/lib/fluent/fluent_log_event_router.rb +0 -2
  17. data/lib/fluent/log/console_adapter.rb +4 -2
  18. data/lib/fluent/plugin/buf_file.rb +1 -1
  19. data/lib/fluent/plugin/buffer/file_chunk.rb +1 -1
  20. data/lib/fluent/plugin/buffer/file_single_chunk.rb +2 -3
  21. data/lib/fluent/plugin/filter_parser.rb +26 -8
  22. data/lib/fluent/plugin/in_exec.rb +14 -2
  23. data/lib/fluent/plugin/in_http.rb +19 -54
  24. data/lib/fluent/plugin/in_sample.rb +13 -7
  25. data/lib/fluent/plugin/in_tail.rb +99 -25
  26. data/lib/fluent/plugin/out_copy.rb +1 -1
  27. data/lib/fluent/plugin/out_file.rb +8 -0
  28. data/lib/fluent/plugin/out_http.rb +137 -13
  29. data/lib/fluent/plugin/owned_by_mixin.rb +0 -1
  30. data/lib/fluent/plugin/parser_json.rb +26 -17
  31. data/lib/fluent/plugin/parser_msgpack.rb +24 -3
  32. data/lib/fluent/plugin_helper/http_server/server.rb +1 -1
  33. data/lib/fluent/plugin_helper/metrics.rb +2 -2
  34. data/lib/fluent/registry.rb +6 -6
  35. data/lib/fluent/test/output_test.rb +1 -1
  36. data/lib/fluent/unique_id.rb +1 -1
  37. data/lib/fluent/version.rb +1 -1
  38. data/templates/new_gem/fluent-plugin.gemspec.erb +6 -5
  39. metadata +109 -459
  40. data/.github/ISSUE_TEMPLATE/bug_report.yml +0 -71
  41. data/.github/ISSUE_TEMPLATE/config.yml +0 -5
  42. data/.github/ISSUE_TEMPLATE/feature_request.yml +0 -39
  43. data/.github/ISSUE_TEMPLATE.md +0 -17
  44. data/.github/PULL_REQUEST_TEMPLATE.md +0 -14
  45. data/.github/workflows/stale-actions.yml +0 -24
  46. data/.github/workflows/test.yml +0 -32
  47. data/.gitignore +0 -30
  48. data/Gemfile +0 -9
  49. data/fluentd.gemspec +0 -54
  50. data/test/command/test_binlog_reader.rb +0 -362
  51. data/test/command/test_ca_generate.rb +0 -70
  52. data/test/command/test_cap_ctl.rb +0 -100
  53. data/test/command/test_cat.rb +0 -128
  54. data/test/command/test_ctl.rb +0 -56
  55. data/test/command/test_fluentd.rb +0 -1291
  56. data/test/command/test_plugin_config_formatter.rb +0 -397
  57. data/test/command/test_plugin_generator.rb +0 -109
  58. data/test/compat/test_calls_super.rb +0 -166
  59. data/test/compat/test_parser.rb +0 -92
  60. data/test/config/assertions.rb +0 -42
  61. data/test/config/test_config_parser.rb +0 -551
  62. data/test/config/test_configurable.rb +0 -1784
  63. data/test/config/test_configure_proxy.rb +0 -604
  64. data/test/config/test_dsl.rb +0 -415
  65. data/test/config/test_element.rb +0 -518
  66. data/test/config/test_literal_parser.rb +0 -309
  67. data/test/config/test_plugin_configuration.rb +0 -56
  68. data/test/config/test_section.rb +0 -191
  69. data/test/config/test_system_config.rb +0 -195
  70. data/test/config/test_types.rb +0 -408
  71. data/test/counter/test_client.rb +0 -563
  72. data/test/counter/test_error.rb +0 -44
  73. data/test/counter/test_mutex_hash.rb +0 -179
  74. data/test/counter/test_server.rb +0 -589
  75. data/test/counter/test_store.rb +0 -258
  76. data/test/counter/test_validator.rb +0 -137
  77. data/test/helper.rb +0 -155
  78. data/test/helpers/fuzzy_assert.rb +0 -89
  79. data/test/helpers/process_extenstion.rb +0 -33
  80. data/test/log/test_console_adapter.rb +0 -110
  81. data/test/plugin/data/2010/01/20100102-030405.log +0 -0
  82. data/test/plugin/data/2010/01/20100102-030406.log +0 -0
  83. data/test/plugin/data/2010/01/20100102.log +0 -0
  84. data/test/plugin/data/log/bar +0 -0
  85. data/test/plugin/data/log/foo/bar.log +0 -0
  86. data/test/plugin/data/log/foo/bar2 +0 -0
  87. data/test/plugin/data/log/test.log +0 -0
  88. data/test/plugin/data/sd_file/config +0 -11
  89. data/test/plugin/data/sd_file/config.json +0 -17
  90. data/test/plugin/data/sd_file/config.yaml +0 -11
  91. data/test/plugin/data/sd_file/config.yml +0 -11
  92. data/test/plugin/data/sd_file/invalid_config.yml +0 -7
  93. data/test/plugin/in_tail/test_fifo.rb +0 -121
  94. data/test/plugin/in_tail/test_io_handler.rb +0 -150
  95. data/test/plugin/in_tail/test_position_file.rb +0 -346
  96. data/test/plugin/out_forward/test_ack_handler.rb +0 -140
  97. data/test/plugin/out_forward/test_connection_manager.rb +0 -145
  98. data/test/plugin/out_forward/test_handshake_protocol.rb +0 -112
  99. data/test/plugin/out_forward/test_load_balancer.rb +0 -106
  100. data/test/plugin/out_forward/test_socket_cache.rb +0 -174
  101. data/test/plugin/test_bare_output.rb +0 -131
  102. data/test/plugin/test_base.rb +0 -247
  103. data/test/plugin/test_buf_file.rb +0 -1314
  104. data/test/plugin/test_buf_file_single.rb +0 -898
  105. data/test/plugin/test_buf_memory.rb +0 -42
  106. data/test/plugin/test_buffer.rb +0 -1493
  107. data/test/plugin/test_buffer_chunk.rb +0 -209
  108. data/test/plugin/test_buffer_file_chunk.rb +0 -871
  109. data/test/plugin/test_buffer_file_single_chunk.rb +0 -611
  110. data/test/plugin/test_buffer_memory_chunk.rb +0 -339
  111. data/test/plugin/test_compressable.rb +0 -87
  112. data/test/plugin/test_file_util.rb +0 -96
  113. data/test/plugin/test_filter.rb +0 -368
  114. data/test/plugin/test_filter_grep.rb +0 -697
  115. data/test/plugin/test_filter_parser.rb +0 -731
  116. data/test/plugin/test_filter_record_transformer.rb +0 -577
  117. data/test/plugin/test_filter_stdout.rb +0 -207
  118. data/test/plugin/test_formatter_csv.rb +0 -136
  119. data/test/plugin/test_formatter_hash.rb +0 -38
  120. data/test/plugin/test_formatter_json.rb +0 -61
  121. data/test/plugin/test_formatter_ltsv.rb +0 -70
  122. data/test/plugin/test_formatter_msgpack.rb +0 -28
  123. data/test/plugin/test_formatter_out_file.rb +0 -116
  124. data/test/plugin/test_formatter_single_value.rb +0 -44
  125. data/test/plugin/test_formatter_tsv.rb +0 -76
  126. data/test/plugin/test_in_debug_agent.rb +0 -49
  127. data/test/plugin/test_in_exec.rb +0 -261
  128. data/test/plugin/test_in_forward.rb +0 -1178
  129. data/test/plugin/test_in_gc_stat.rb +0 -62
  130. data/test/plugin/test_in_http.rb +0 -1102
  131. data/test/plugin/test_in_monitor_agent.rb +0 -922
  132. data/test/plugin/test_in_object_space.rb +0 -66
  133. data/test/plugin/test_in_sample.rb +0 -190
  134. data/test/plugin/test_in_syslog.rb +0 -505
  135. data/test/plugin/test_in_tail.rb +0 -3288
  136. data/test/plugin/test_in_tcp.rb +0 -328
  137. data/test/plugin/test_in_udp.rb +0 -296
  138. data/test/plugin/test_in_unix.rb +0 -181
  139. data/test/plugin/test_input.rb +0 -137
  140. data/test/plugin/test_metadata.rb +0 -89
  141. data/test/plugin/test_metrics.rb +0 -294
  142. data/test/plugin/test_metrics_local.rb +0 -96
  143. data/test/plugin/test_multi_output.rb +0 -204
  144. data/test/plugin/test_out_copy.rb +0 -308
  145. data/test/plugin/test_out_exec.rb +0 -312
  146. data/test/plugin/test_out_exec_filter.rb +0 -606
  147. data/test/plugin/test_out_file.rb +0 -1038
  148. data/test/plugin/test_out_forward.rb +0 -1349
  149. data/test/plugin/test_out_http.rb +0 -429
  150. data/test/plugin/test_out_null.rb +0 -105
  151. data/test/plugin/test_out_relabel.rb +0 -28
  152. data/test/plugin/test_out_roundrobin.rb +0 -146
  153. data/test/plugin/test_out_secondary_file.rb +0 -458
  154. data/test/plugin/test_out_stdout.rb +0 -205
  155. data/test/plugin/test_out_stream.rb +0 -103
  156. data/test/plugin/test_output.rb +0 -1334
  157. data/test/plugin/test_output_as_buffered.rb +0 -2024
  158. data/test/plugin/test_output_as_buffered_backup.rb +0 -363
  159. data/test/plugin/test_output_as_buffered_compress.rb +0 -179
  160. data/test/plugin/test_output_as_buffered_overflow.rb +0 -250
  161. data/test/plugin/test_output_as_buffered_retries.rb +0 -966
  162. data/test/plugin/test_output_as_buffered_secondary.rb +0 -882
  163. data/test/plugin/test_output_as_standard.rb +0 -374
  164. data/test/plugin/test_owned_by.rb +0 -35
  165. data/test/plugin/test_parser.rb +0 -399
  166. data/test/plugin/test_parser_apache.rb +0 -42
  167. data/test/plugin/test_parser_apache2.rb +0 -47
  168. data/test/plugin/test_parser_apache_error.rb +0 -45
  169. data/test/plugin/test_parser_csv.rb +0 -200
  170. data/test/plugin/test_parser_json.rb +0 -138
  171. data/test/plugin/test_parser_labeled_tsv.rb +0 -160
  172. data/test/plugin/test_parser_multiline.rb +0 -111
  173. data/test/plugin/test_parser_nginx.rb +0 -88
  174. data/test/plugin/test_parser_none.rb +0 -52
  175. data/test/plugin/test_parser_regexp.rb +0 -284
  176. data/test/plugin/test_parser_syslog.rb +0 -650
  177. data/test/plugin/test_parser_tsv.rb +0 -122
  178. data/test/plugin/test_sd_file.rb +0 -228
  179. data/test/plugin/test_sd_srv.rb +0 -230
  180. data/test/plugin/test_storage.rb +0 -167
  181. data/test/plugin/test_storage_local.rb +0 -335
  182. data/test/plugin/test_string_util.rb +0 -26
  183. data/test/plugin_helper/data/cert/cert-key.pem +0 -27
  184. data/test/plugin_helper/data/cert/cert-with-CRLF.pem +0 -19
  185. data/test/plugin_helper/data/cert/cert-with-no-newline.pem +0 -19
  186. data/test/plugin_helper/data/cert/cert.pem +0 -19
  187. data/test/plugin_helper/data/cert/cert_chains/ca-cert-key.pem +0 -27
  188. data/test/plugin_helper/data/cert/cert_chains/ca-cert.pem +0 -20
  189. data/test/plugin_helper/data/cert/cert_chains/cert-key.pem +0 -27
  190. data/test/plugin_helper/data/cert/cert_chains/cert.pem +0 -40
  191. data/test/plugin_helper/data/cert/empty.pem +0 -0
  192. data/test/plugin_helper/data/cert/generate_cert.rb +0 -125
  193. data/test/plugin_helper/data/cert/with_ca/ca-cert-key-pass.pem +0 -30
  194. data/test/plugin_helper/data/cert/with_ca/ca-cert-key.pem +0 -27
  195. data/test/plugin_helper/data/cert/with_ca/ca-cert-pass.pem +0 -20
  196. data/test/plugin_helper/data/cert/with_ca/ca-cert.pem +0 -20
  197. data/test/plugin_helper/data/cert/with_ca/cert-key-pass.pem +0 -30
  198. data/test/plugin_helper/data/cert/with_ca/cert-key.pem +0 -27
  199. data/test/plugin_helper/data/cert/with_ca/cert-pass.pem +0 -21
  200. data/test/plugin_helper/data/cert/with_ca/cert.pem +0 -21
  201. data/test/plugin_helper/data/cert/without_ca/cert-key-pass.pem +0 -30
  202. data/test/plugin_helper/data/cert/without_ca/cert-key.pem +0 -27
  203. data/test/plugin_helper/data/cert/without_ca/cert-pass.pem +0 -20
  204. data/test/plugin_helper/data/cert/without_ca/cert.pem +0 -20
  205. data/test/plugin_helper/http_server/test_app.rb +0 -65
  206. data/test/plugin_helper/http_server/test_route.rb +0 -32
  207. data/test/plugin_helper/service_discovery/test_manager.rb +0 -93
  208. data/test/plugin_helper/service_discovery/test_round_robin_balancer.rb +0 -21
  209. data/test/plugin_helper/test_cert_option.rb +0 -25
  210. data/test/plugin_helper/test_child_process.rb +0 -862
  211. data/test/plugin_helper/test_compat_parameters.rb +0 -358
  212. data/test/plugin_helper/test_event_emitter.rb +0 -80
  213. data/test/plugin_helper/test_event_loop.rb +0 -52
  214. data/test/plugin_helper/test_extract.rb +0 -194
  215. data/test/plugin_helper/test_formatter.rb +0 -255
  216. data/test/plugin_helper/test_http_server_helper.rb +0 -372
  217. data/test/plugin_helper/test_inject.rb +0 -561
  218. data/test/plugin_helper/test_metrics.rb +0 -137
  219. data/test/plugin_helper/test_parser.rb +0 -264
  220. data/test/plugin_helper/test_record_accessor.rb +0 -238
  221. data/test/plugin_helper/test_retry_state.rb +0 -1006
  222. data/test/plugin_helper/test_server.rb +0 -1895
  223. data/test/plugin_helper/test_service_discovery.rb +0 -165
  224. data/test/plugin_helper/test_socket.rb +0 -146
  225. data/test/plugin_helper/test_storage.rb +0 -542
  226. data/test/plugin_helper/test_thread.rb +0 -164
  227. data/test/plugin_helper/test_timer.rb +0 -130
  228. data/test/scripts/exec_script.rb +0 -32
  229. data/test/scripts/fluent/plugin/formatter1/formatter_test1.rb +0 -7
  230. data/test/scripts/fluent/plugin/formatter2/formatter_test2.rb +0 -7
  231. data/test/scripts/fluent/plugin/formatter_known.rb +0 -8
  232. data/test/scripts/fluent/plugin/out_test.rb +0 -81
  233. data/test/scripts/fluent/plugin/out_test2.rb +0 -80
  234. data/test/scripts/fluent/plugin/parser_known.rb +0 -4
  235. data/test/test_capability.rb +0 -74
  236. data/test/test_clock.rb +0 -164
  237. data/test/test_config.rb +0 -369
  238. data/test/test_configdsl.rb +0 -148
  239. data/test/test_daemonizer.rb +0 -91
  240. data/test/test_engine.rb +0 -203
  241. data/test/test_event.rb +0 -531
  242. data/test/test_event_router.rb +0 -348
  243. data/test/test_event_time.rb +0 -199
  244. data/test/test_file_wrapper.rb +0 -53
  245. data/test/test_filter.rb +0 -121
  246. data/test/test_fluent_log_event_router.rb +0 -99
  247. data/test/test_formatter.rb +0 -369
  248. data/test/test_input.rb +0 -31
  249. data/test/test_log.rb +0 -1076
  250. data/test/test_match.rb +0 -148
  251. data/test/test_mixin.rb +0 -351
  252. data/test/test_msgpack_factory.rb +0 -50
  253. data/test/test_oj_options.rb +0 -55
  254. data/test/test_output.rb +0 -278
  255. data/test/test_plugin.rb +0 -251
  256. data/test/test_plugin_classes.rb +0 -370
  257. data/test/test_plugin_helper.rb +0 -81
  258. data/test/test_plugin_id.rb +0 -119
  259. data/test/test_process.rb +0 -14
  260. data/test/test_root_agent.rb +0 -951
  261. data/test/test_static_config_analysis.rb +0 -177
  262. data/test/test_supervisor.rb +0 -821
  263. data/test/test_test_drivers.rb +0 -136
  264. data/test/test_time_formatter.rb +0 -301
  265. data/test/test_time_parser.rb +0 -362
  266. data/test/test_tls.rb +0 -65
  267. data/test/test_unique_id.rb +0 -47
  268. data/test/test_variable_store.rb +0 -65
@@ -1,1006 +0,0 @@
1
- require_relative '../helper'
2
- require 'fluent/plugin_helper/retry_state'
3
- require 'fluent/plugin/base'
4
-
5
- require 'time'
6
-
7
- class RetryStateHelperTest < Test::Unit::TestCase
8
- def override_current_time(state, time)
9
- mojule = Module.new do
10
- define_method(:current_time){ time }
11
- end
12
- state.singleton_class.module_eval do
13
- prepend mojule
14
- end
15
- end
16
-
17
- class Dummy < Fluent::Plugin::TestBase
18
- helpers :retry_state
19
- end
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
-
36
- setup do
37
- @d = Dummy.new
38
- end
39
-
40
- test 'randomize can generate value within specified +/- range' do
41
- s = @d.retry_state_create(:t1, :exponential_backoff, 0.1, 30) # default enabled w/ 0.125
42
- 500.times do
43
- r = s.randomize(1000)
44
- assert{ r >= 875 && r < 1125 }
45
- end
46
-
47
- s = @d.retry_state_create(:t1, :exponential_backoff, 0.1, 30, randomize_width: 0.25)
48
- 500.times do
49
- r = s.randomize(1000)
50
- assert{ r >= 750 && r < 1250 }
51
- end
52
- end
53
-
54
- test 'plugin can create retry_state machine' do
55
- s = @d.retry_state_create(:t1, :exponential_backoff, 0.1, 30)
56
- # attr_reader :title, :start, :steps, :next_time, :timeout_at, :current, :secondary_transition_at, :secondary_transition_times
57
-
58
- assert_equal :t1, s.title
59
- start_time = s.start
60
-
61
- assert_equal 0, s.steps
62
- assert_equal (start_time + 0.1).to_i, s.next_time.to_i
63
- assert_equal (start_time + 0.1).nsec, s.next_time.nsec
64
- assert_equal (start_time + 30), s.timeout_at
65
-
66
- assert_equal :primary, s.current
67
- assert{ s.is_a? Fluent::PluginHelper::RetryState::ExponentialBackOffRetry }
68
- end
69
-
70
- test 'periodic retries' do
71
- s = @d.retry_state_create(:t2, :periodic, 3, 29, randomize: false)
72
- dummy_current_time = s.start
73
- override_current_time(s, dummy_current_time)
74
-
75
- assert_equal dummy_current_time, s.current_time
76
- assert_equal (dummy_current_time + 29), s.timeout_at
77
- assert_equal (dummy_current_time + 3), s.next_time
78
-
79
- i = 1
80
- while i < 9
81
- override_current_time(s, s.next_time)
82
- s.step
83
- assert_equal i, s.steps
84
- assert_equal (s.current_time + 3), s.next_time
85
- assert !s.limit?
86
- i += 1
87
- end
88
-
89
- assert_equal 9, i
90
- override_current_time(s, s.next_time)
91
- s.step
92
- assert_equal s.timeout_at, s.next_time
93
- s.step
94
- assert s.limit?
95
- end
96
-
97
- test 'periodic retries with max_steps' do
98
- s = @d.retry_state_create(:t2, :periodic, 3, 29, randomize: false, max_steps: 5)
99
- dummy_current_time = s.start
100
- override_current_time(s, dummy_current_time)
101
-
102
- assert_equal dummy_current_time, s.current_time
103
- assert_equal (dummy_current_time + 29), s.timeout_at
104
- assert_equal (dummy_current_time + 3), s.next_time
105
-
106
- i = 1
107
- while i < 5
108
- override_current_time(s, s.next_time)
109
- s.step
110
- assert_equal i, s.steps
111
- assert_equal (s.current_time + 3), s.next_time
112
- assert !s.limit?
113
- i += 1
114
- end
115
-
116
- assert_equal 5, i
117
- override_current_time(s, s.next_time)
118
- s.step
119
- assert s.limit?
120
- end
121
-
122
- test 'periodic retries with secondary' do
123
- s = @d.retry_state_create(:t3, :periodic, 3, 100, randomize: false, secondary: true) # threshold 0.8
124
- dummy_current_time = s.start
125
- override_current_time(s, dummy_current_time)
126
-
127
- assert_equal dummy_current_time, s.current_time
128
- assert_equal (dummy_current_time + 100), s.timeout_at
129
- assert_equal (dummy_current_time + 100 * 0.8), s.secondary_transition_at
130
-
131
- assert_equal (dummy_current_time + 3), s.next_time
132
- assert !s.secondary?
133
-
134
- i = 1
135
- while i < 26
136
- override_current_time(s, s.next_time)
137
- assert !s.secondary?
138
-
139
- s.step
140
- assert_equal i, s.steps
141
- assert_equal (s.current_time + 3), s.next_time
142
- assert !s.limit?
143
- i += 1
144
- end
145
-
146
- assert_equal 26, i
147
- override_current_time(s, s.next_time) # 78
148
- assert !s.secondary?
149
-
150
- s.step
151
- assert_equal 26, s.steps
152
- assert_equal s.secondary_transition_at, s.next_time
153
- assert !s.limit?
154
-
155
- i += 1
156
- assert_equal 27, i
157
- override_current_time(s, s.next_time) # 80
158
- assert s.secondary?
159
-
160
- s.step
161
- assert_equal (s.current_time + 3), s.next_time
162
- assert_equal s.steps, s.secondary_transition_steps
163
- assert !s.limit?
164
-
165
- i += 1
166
-
167
- while i < 33
168
- override_current_time(s, s.next_time)
169
- assert s.secondary?
170
-
171
- s.step
172
- assert_equal (s.current_time + 3), s.next_time
173
- assert !s.limit?
174
- i += 1
175
- end
176
-
177
- assert_equal 33, i
178
- override_current_time(s, s.next_time) # 98
179
- assert s.secondary?
180
-
181
- s.step
182
- assert_equal s.timeout_at, s.next_time # 100
183
-
184
- s.step
185
- assert s.limit?
186
- end
187
-
188
- test 'periodic retries with secondary and specified threshold' do
189
- s = @d.retry_state_create(:t3, :periodic, 3, 100, randomize: false, secondary: true, secondary_threshold: 0.75)
190
- dummy_current_time = s.start
191
- override_current_time(s, dummy_current_time)
192
-
193
- assert_equal dummy_current_time, s.current_time
194
- assert_equal (dummy_current_time + 100), s.timeout_at
195
- assert_equal (dummy_current_time + 100 * 0.75), s.secondary_transition_at
196
- end
197
-
198
- test 'periodic retries with secondary and max_steps' do
199
- s = @d.retry_state_create(:t3, :periodic, 3, 100, max_steps: 5, randomize: false, secondary: true)
200
- dummy_current_time = s.start
201
- override_current_time(s, dummy_current_time)
202
-
203
- assert_equal dummy_current_time, s.current_time
204
- assert_equal (dummy_current_time + 100), s.timeout_at
205
- assert_equal (dummy_current_time + 3 * 5 * 0.8), s.secondary_transition_at
206
- end
207
-
208
- test 'exponential backoff forever without randomization' do
209
- s = @d.retry_state_create(:t11, :exponential_backoff, 0.1, 300, randomize: false, forever: true, backoff_base: 2)
210
- dummy_current_time = s.start
211
- override_current_time(s, dummy_current_time)
212
-
213
- assert_equal dummy_current_time, s.current_time
214
-
215
- assert_equal 0, s.steps
216
- assert_equal (dummy_current_time + 0.1), s.next_time
217
-
218
- i = 1
219
- while i < 300
220
- s.step
221
- assert_equal i, s.steps
222
- assert_equal (dummy_current_time + 0.1 * (2 ** i)), s.next_time
223
- assert !s.limit?
224
- i += 1
225
- end
226
- end
227
-
228
- test 'exponential backoff with max_interval' do
229
- s = @d.retry_state_create(:t12, :exponential_backoff, 0.1, 300, randomize: false, forever: true, backoff_base: 2, max_interval: 100)
230
- dummy_current_time = s.start
231
- override_current_time(s, dummy_current_time)
232
-
233
- assert_equal dummy_current_time, s.current_time
234
-
235
- assert_equal 0, s.steps
236
- assert_equal (dummy_current_time + 0.1), s.next_time
237
-
238
- # 0.1 * 2 ** 9 == 51.2
239
- # 0.1 * 2 ** 10 == 102.4
240
- i = 1
241
- while i < 10
242
- s.step
243
- assert_equal i, s.steps
244
- assert_equal (dummy_current_time + 0.1 * (2 ** i)), s.next_time, "start:#{dummy_current_time}, i:#{i}"
245
- i += 1
246
- end
247
-
248
- s.step
249
- assert_equal 10, s.steps
250
- assert_equal (dummy_current_time + 100), s.next_time
251
-
252
- s.step
253
- assert_equal 11, s.steps
254
- assert_equal (dummy_current_time + 100), s.next_time
255
- end
256
-
257
- test 'exponential backoff with shorter timeout' do
258
- s = @d.retry_state_create(:t13, :exponential_backoff, 1, 12, randomize: false, backoff_base: 2, max_interval: 10)
259
- dummy_current_time = s.start
260
- override_current_time(s, dummy_current_time)
261
-
262
- assert_equal dummy_current_time, s.current_time
263
-
264
- assert_equal (dummy_current_time + 12), s.timeout_at
265
-
266
- assert_equal 0, s.steps
267
- assert_equal (dummy_current_time + 1), s.next_time
268
-
269
- # 1 + 2 + 4 (=7)
270
-
271
- override_current_time(s, s.next_time)
272
- s.step
273
- assert_equal 1, s.steps
274
- assert_equal (s.current_time + 2), s.next_time
275
-
276
- override_current_time(s, s.next_time)
277
- s.step
278
- assert_equal 2, s.steps
279
- assert_equal (s.current_time + 4), s.next_time
280
-
281
- assert !s.limit?
282
-
283
- # + 8 (=15) > 12
284
-
285
- override_current_time(s, s.next_time)
286
- s.step
287
- assert_equal 3, s.steps
288
- assert_equal s.timeout_at, s.next_time
289
-
290
- s.step
291
- assert s.limit?
292
- end
293
-
294
- test 'exponential backoff with max_steps' do
295
- s = @d.retry_state_create(:t14, :exponential_backoff, 1, 120, randomize: false, backoff_base: 2, max_interval: 10, max_steps: 6)
296
- dummy_current_time = s.start
297
- override_current_time(s, dummy_current_time)
298
-
299
- assert_equal dummy_current_time, s.current_time
300
-
301
- assert_equal (dummy_current_time + 120), s.timeout_at
302
-
303
- assert_equal 0, s.steps
304
- assert_equal (dummy_current_time + 1), s.next_time
305
-
306
- override_current_time(s, s.next_time)
307
- s.step
308
- assert_equal 1, s.steps
309
- assert_equal (s.current_time + 2), s.next_time
310
-
311
- override_current_time(s, s.next_time)
312
- s.step
313
- assert_equal 2, s.steps
314
- assert_equal (s.current_time + 4), s.next_time
315
-
316
- override_current_time(s, s.next_time)
317
- s.step
318
- assert_equal 3, s.steps
319
- assert_equal (s.current_time + 8), s.next_time
320
-
321
- assert !s.limit?
322
-
323
- override_current_time(s, s.next_time)
324
- s.step
325
- assert_equal 4, s.steps
326
- assert_equal (s.current_time + 10), s.next_time
327
-
328
- assert !s.limit?
329
-
330
- override_current_time(s, s.next_time)
331
- s.step
332
- assert_equal 5, s.steps
333
- assert_equal (s.current_time + 10), s.next_time
334
-
335
- assert !s.limit?
336
-
337
- override_current_time(s, s.next_time)
338
- s.step
339
- assert_equal 6, s.steps
340
- assert s.limit?
341
- end
342
-
343
- test 'exponential backoff retries with secondary' do
344
- s = @d.retry_state_create(:t15, :exponential_backoff, 1, 100, randomize: false, backoff_base: 2, secondary: true) # threshold 0.8
345
- dummy_current_time = s.start
346
- override_current_time(s, dummy_current_time)
347
-
348
- assert_equal dummy_current_time, s.current_time
349
- assert_equal (dummy_current_time + 100), s.timeout_at
350
- assert_equal (dummy_current_time + 100 * 0.8), s.secondary_transition_at
351
-
352
- assert_equal (dummy_current_time + 1), s.next_time
353
- assert !s.secondary?
354
-
355
- # primary: 3, 7, 15, 31, 63, 80 (timeout * threashold)
356
- # secondary: 81, 83, 87, 95, 100
357
- i = 1
358
- while i < 6
359
- override_current_time(s, s.next_time)
360
- assert !s.secondary?
361
-
362
- s.step
363
- assert_equal i, s.steps
364
- assert_equal (s.current_time + 1 * (2 ** i)), s.next_time
365
- assert !s.limit?
366
- i += 1
367
- end
368
-
369
- assert_equal 6, i
370
- override_current_time(s, s.next_time) # 63
371
- assert !s.secondary?
372
-
373
- s.step
374
- assert_equal 6, s.steps
375
- assert_equal s.secondary_transition_at, s.next_time
376
- assert !s.limit?
377
-
378
- i += 1
379
- assert_equal 7, i
380
- override_current_time(s, s.next_time) # 80
381
- assert s.secondary?
382
-
383
- s.step
384
- assert_equal 7, s.steps
385
- assert_equal s.steps, s.secondary_transition_steps
386
- assert_equal (s.secondary_transition_at + 1.0), s.next_time # 81
387
- assert !s.limit?
388
- assert_equal :secondary, s.current
389
-
390
- # 83, 87, 95, 100
391
- j = 1
392
- while j < 4
393
- override_current_time(s, s.next_time)
394
- assert s.secondary?
395
- assert_equal :secondary, s.current
396
-
397
- s.step
398
- assert_equal (7 + j), s.steps
399
- assert_equal (s.current_time + (1 * (2 ** j))), s.next_time
400
- assert !s.limit?, "j:#{j}"
401
- j += 1
402
- end
403
-
404
- assert_equal 4, j
405
- override_current_time(s, s.next_time) # 95
406
- assert s.secondary?
407
-
408
- s.step
409
- assert_equal s.timeout_at, s.next_time # 100
410
-
411
- s.step
412
- assert s.limit?
413
- end
414
-
415
- test 'exponential backoff retries with secondary and specified threshold' do
416
- s = @d.retry_state_create(:t16, :exponential_backoff, 1, 100, randomize: false, secondary: true, backoff_base: 2, secondary_threshold: 0.75)
417
- dummy_current_time = s.start
418
- override_current_time(s, dummy_current_time)
419
-
420
- assert_equal dummy_current_time, s.current_time
421
- assert_equal (dummy_current_time + 100), s.timeout_at
422
- assert_equal (dummy_current_time + 100 * 0.75), s.secondary_transition_at
423
- end
424
-
425
- test 'exponential backoff retries with secondary and max_steps' do
426
- s = @d.retry_state_create(:t15, :exponential_backoff, 1, 100, randomize: false, max_steps: 5, backoff_base: 2, secondary: true) # threshold 0.8
427
- dummy_current_time = s.start
428
- override_current_time(s, dummy_current_time)
429
-
430
- timeout = 0
431
- 5.times { |i| timeout += 1.0 * (2 ** i) }
432
-
433
- assert_equal dummy_current_time, s.current_time
434
- assert_equal (dummy_current_time + 100), s.timeout_at
435
- assert_equal (dummy_current_time + timeout * 0.8), s.secondary_transition_at
436
- end
437
-
438
- sub_test_case 'exponential backoff' do
439
- test 'too big steps(check inf handling)' do
440
- s = @d.retry_state_create(:t11, :exponential_backoff, 1, 300, randomize: false, forever: true, backoff_base: 2)
441
- dummy_current_time = s.start
442
- override_current_time(s, dummy_current_time)
443
-
444
- i = 1
445
- while i < 1027
446
- if i >= 1025
447
- # With this setting, 1025+ number causes inf in `calc_interval`, so 1024 value is used for next_time
448
- assert_nothing_raised(FloatDomainError) { s.step }
449
- assert_equal (dummy_current_time + (2 ** (1024 - 1))), s.next_time
450
- else
451
- s.step
452
- end
453
- i += 1
454
- end
455
- end
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
1006
- end