Skip to content

CI: Use Driver::logs for asserting log messages #4136

Open
@daipom

Description

@daipom

Describe the bug

Some tests are asserting log messages as follows.
We should fix these tests.

  • Use shutdown: false and manually do d.instance_shutdown
  • Take logs from Driver::instance

d.run(shutdown: false, expect_records: 2, timeout: 10) do
entries = []
# These entries are skipped
entries << ['tag1', true, {'a' => 3}] << ['tag2', time, 'invalid record']
entries += records.map { |tag, _time, record| [tag, _time, record] }
entries.each {|tag, _time, record|
# Without ack, logs are sometimes not saved to logs during test.
send_data packer.write([tag, _time, record]).to_s #, try_to_receive_response: true
}
end
logs = d.instance.log.logs
assert_equal 2, logs.count { |line| line =~ /got invalid event and drop it/ }
assert_equal records[0], d.events[0]
assert_equal records[1], d.events[1]
d.instance_shutdown

We should not use this approach.

The log messages of the instance will be cleared after the shutdown, but we can still take log messages from Driver::logs.
So we should use Driver::logs and should not use shutdown: false for this purpose.

Note: Driver::logs is the same instance as instance.log.out.logs (= instance.log.logs), but reset will not clear it, just re-assign the new list to DummyLogDevice. So we can use Driver::logs after the shutdown.

To Reproduce

None.

Expected behavior

None.

Your Environment

Not related.

Your Configuration

Not related.

Your Error Log

Not related.

Additional context

The document also says we should use Driver::logs.

https://docs.fluentd.org/plugin-development/plugin-test-code#tests-for-logs

Metadata

Metadata

Assignees

Labels

enhancementFeature request or improve operations

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions