Skip to content

Commit ada90e0

Browse files
committed
test: ensure removing old engine on setup (fluent#5057)
**Which issue(s) this PR fixes**: Continued from * fluent#5054 * fluent#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 <fukuda@clear-code.com>
1 parent daccbc6 commit ada90e0

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
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
}

0 commit comments

Comments
 (0)