diff --git a/test/plugin/test_base.rb b/test/plugin/test_base.rb
index ab2274f679..479ecc49f6 100644
--- a/test/plugin/test_base.rb
+++ b/test/plugin/test_base.rb
@@ -154,6 +154,18 @@ class FluentPluginBaseTest::DummyPlugin2 < Fluent::Plugin::TestBase
end
sub_test_case 'system_config.workers value after configure' do
+ def assert_system_config_workers_value(data)
+ conf = config_element()
+ conf.set_target_worker_ids(data[:target_worker_ids])
+ @p.configure(conf)
+ assert{ @p.system_config.workers == data[:expected] }
+ end
+
+ def stub_supervisor_mode
+ stub(Fluent::Engine).supervisor_mode { true }
+ stub(Fluent::Engine).worker_id { -1 }
+ end
+
sub_test_case 'with workers 3 ' do
setup do
system_config = Fluent::SystemConfig.new
@@ -161,118 +173,74 @@ class FluentPluginBaseTest::DummyPlugin2 < Fluent::Plugin::TestBase
stub(Fluent::Engine).system_config { system_config }
end
- sub_test_case 'supervisor_mode is true' do
- setup do
- stub(Fluent::Engine).supervisor_mode { true }
- stub(Fluent::Engine).worker_id { -1 }
- end
-
- test 'without directive' do
- conf = config_element()
- conf.set_target_worker_ids([])
- @p.configure(conf)
- assert{ @p.system_config.workers == 3 }
- end
-
- test 'with ' do
- conf = config_element()
- conf.set_target_worker_ids([0])
- @p.configure(conf)
- assert{ @p.system_config.workers == 1 }
- end
-
- test 'with ' do
- conf = config_element()
- conf.set_target_worker_ids([0, 1])
- @p.configure(conf)
- assert{ @p.system_config.workers == 2 }
- end
-
- test 'with ' do
- conf = config_element()
- conf.set_target_worker_ids([0, 1, 2])
- @p.configure(conf)
- assert{ @p.system_config.workers == 3 }
- end
+ data(
+ 'without directive',
+ {
+ target_worker_ids: [],
+ expected: 3
+ },
+ keep: true
+ )
+ data(
+ 'with ',
+ {
+ target_worker_ids: [0],
+ expected: 1
+ },
+ keep: true
+ )
+ data(
+ 'with ',
+ {
+ target_worker_ids: [0, 1],
+ expected: 2
+ },
+ keep: true
+ )
+ data(
+ 'with ',
+ {
+ target_worker_ids: [0, 1, 2],
+ expected: 3
+ },
+ keep: true
+ )
+
+ test 'system_config.workers value after configure' do
+ assert_system_config_workers_value(data)
end
- sub_test_case 'supervisor_mode is false' do
- setup do
- stub(Fluent::Engine).supervisor_mode { false }
- stub(Fluent::Engine).worker_id { 0 }
- end
-
- test 'without directive' do
- conf = config_element()
- conf.set_target_worker_ids([])
- @p.configure(conf)
- assert{ @p.system_config.workers == 3 }
- end
-
- test 'with ' do
- conf = config_element()
- conf.set_target_worker_ids([0])
- @p.configure(conf)
- assert{ @p.system_config.workers == 1 }
- end
-
- test 'with ' do
- conf = config_element()
- conf.set_target_worker_ids([0, 1])
- @p.configure(conf)
- assert{ @p.system_config.workers == 2 }
- end
-
- test 'with ' do
- conf = config_element()
- conf.set_target_worker_ids([0, 1, 2])
- @p.configure(conf)
- assert{ @p.system_config.workers == 3 }
- end
+ test 'system_config.workers value after configure with supervisor_mode' do
+ stub_supervisor_mode
+ assert_system_config_workers_value(data)
end
end
sub_test_case 'without directive' do
- sub_test_case 'supervisor_mode is true' do
- setup do
- stub(Fluent::Engine).supervisor_mode { true }
- stub(Fluent::Engine).worker_id { -1 }
- end
-
- test 'without directive' do
- conf = config_element()
- conf.set_target_worker_ids([])
- @p.configure(conf)
- assert{ @p.system_config.workers == 1 }
- end
-
- test 'with ' do
- conf = config_element()
- conf.set_target_worker_ids([0])
- @p.configure(conf)
- assert{ @p.system_config.workers == 1 }
- end
+ data(
+ 'without directive',
+ {
+ target_worker_ids: [],
+ expected: 1
+ },
+ keep: true
+ )
+ data(
+ 'with ',
+ {
+ target_worker_ids: [0],
+ expected: 1
+ },
+ keep: true
+ )
+
+ test 'system_config.workers value after configure' do
+ assert_system_config_workers_value(data)
end
- sub_test_case 'supervisor_mode is false' do
- setup do
- stub(Fluent::Engine).supervisor_mode { false }
- stub(Fluent::Engine).worker_id { 0 }
- end
-
- test 'without directive' do
- conf = config_element()
- conf.set_target_worker_ids([])
- @p.configure(conf)
- assert{ @p.system_config.workers == 1 }
- end
-
- test 'with ' do
- conf = config_element()
- conf.set_target_worker_ids([0])
- @p.configure(conf)
- assert{ @p.system_config.workers == 1 }
- end
+ test 'system_config.workers value after configure with supervisor_mode' do
+ stub_supervisor_mode
+ assert_system_config_workers_value(data)
end
end
end