Skip to content

Commit 5935ca0

Browse files
committed
test: ensure removing old engine on setup (#5057)
**Which issue(s) this PR fixes**: Continued from * #5054 * #5055 (6cac9f0) **What this PR does / why we need it**: Each test should not consider the initialization of `Fluent::Engine`. It should be the responsibility of `Fluent::Test.setup`. Note: Set `nil` explicitly to ensure that GC can remove the objects, though it is very strange that some objects can still exist after `remove_const` and `GC.start`. **Docs Changes**: Not needed. **Release Note**: CI improvements. Signed-off-by: Daijiro Fukuda <[email protected]>
1 parent c301faa commit 5935ca0

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

lib/fluent/test.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ def self.setup
4040

4141
$log = dummy_logger
4242

43-
Fluent.__send__(:remove_const, :Engine)
44-
engine = Fluent.const_set(:Engine, EngineClass.new).init(SystemConfig.new)
43+
old_engine = Fluent.__send__(:remove_const, :Engine)
44+
# Ensure that GC can remove the objects of the old engine.
45+
# Some objects can still exist after `remove_const`. See https://github.com/fluent/fluentd/issues/5054.
46+
old_engine.instance_variable_set(:@root_agent, nil)
4547

48+
engine = Fluent.const_set(:Engine, EngineClass.new).init(SystemConfig.new)
4649
engine.define_singleton_method(:now=) {|n|
4750
@now = n
4851
}

test/plugin/test_input.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,5 @@ def emit(tag, es)
133133
assert{ @p.router.object_id != original_router.object_id }
134134

135135
@p.router.emit('mytag.testing', ['for mock'])
136-
ensure
137-
Fluent::Engine.root_agent.labels['@mytest'] = nil
138136
end
139137
end

test/plugin_helper/test_event_emitter.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ class Dummy < Fluent::Plugin::TestBase
7070
d.configure(config_element('ROOT', '', {'@label' => '@mytest'}))
7171
router = d.event_emitter_router("@mytest")
7272
assert_equal router_mock, router
73-
ensure
74-
Fluent::Engine.root_agent.labels['@mytest'] = nil
7573
end
7674

7775
test 'get root router' do

0 commit comments

Comments
 (0)