diff --git a/test/plugin/test_base.rb b/test/plugin/test_base.rb
index ab2274f679..7816f1a664 100644
--- a/test/plugin/test_base.rb
+++ b/test/plugin/test_base.rb
@@ -154,6 +154,25 @@ 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 when_supervisor_mode_is_true(data)
+ stub(Fluent::Engine).supervisor_mode { true }
+ stub(Fluent::Engine).worker_id { -1 }
+ assert_system_config_workers_value(data)
+ end
+
+ def when_supervisor_mode_is_false(data)
+ stub(Fluent::Engine).supervisor_mode { false }
+ stub(Fluent::Engine).worker_id { 0 }
+ assert_system_config_workers_value(data)
+ end
+
sub_test_case 'with workers 3 ' do
setup do
system_config = Fluent::SystemConfig.new
@@ -161,118 +180,58 @@ 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
- 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
+ data(
+ 'without directive',
+ {
+ target_worker_ids: [],
+ expected: 3
+ }
+ )
+ data(
+ 'with ',
+ {
+ target_worker_ids: [0],
+ expected: 1
+ }
+ )
+ data(
+ 'with ',
+ {
+ target_worker_ids: [0, 1],
+ expected: 2
+ }
+ )
+ data(
+ 'with ',
+ {
+ target_worker_ids: [0, 1, 2],
+ expected: 3
+ }
+ )
+ test 'system_config.workers value after configure' do
+ when_supervisor_mode_is_true(data)
+ when_supervisor_mode_is_false(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
- 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
+ data(
+ 'without directive',
+ {
+ target_worker_ids: [],
+ expected: 1
+ }
+ )
+ data(
+ 'with ',
+ {
+ target_worker_ids: [0],
+ expected: 1
+ }
+ )
+ test 'system_config.workers value after configure' do
+ when_supervisor_mode_is_true(data)
+ when_supervisor_mode_is_false(data)
end
end
end