Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test driver: Return the return value of yield #1282

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/fluent/test/driver/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def run_actual(timeout: nil, &block)
end

proc = if block_given?
->(){ block.call; sleep(0.1) until stop? }
->(){ value = block.call; sleep(0.1) until stop?; value }
else
->(){ sleep(0.1) until stop? }
end
Expand Down
3 changes: 2 additions & 1 deletion lib/fluent/test/driver/output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ def run(flush: true, **kwargs, &block)
end

def run_actual(**kwargs, &block)
super(**kwargs, &block)
value = super(**kwargs, &block)
if @flush_buffer_at_cleanup
@instance.force_flush
Timeout.timeout(10){ sleep 0.1 until [email protected] || @instance.buffer.queue.size == 0 }
end
value
end

def formatted
Expand Down
30 changes: 30 additions & 0 deletions test/driver/test_filter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require_relative '../helper'
require 'fluent/test/driver/filter'

class NullFilter < Fluent::Plugin::Filter
def filter(tag, time, record)
end
end

class TestDriverFilterTest < Test::Unit::TestCase
def setup
Fluent::Test.setup
end

def create_driver(conf = "")
Fluent::Test::Driver::Filter.new(NullFilter).configure(conf)
end

test 'run w/ block returns last evaluated value in block' do
d = create_driver
value = d.run do
:value
end
assert_equal(value, :value)
end

test 'run w/o block returns nil' do
d = create_driver
assert_nil(d.run(timeout: 0.01))
end
end
30 changes: 30 additions & 0 deletions test/driver/test_formatter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require_relative '../helper'
require 'fluent/test/driver/formatter'

class NullFormatter < Fluent::Plugin::Formatter
def format(tag, time, record)
end
end

class TestDriverFormatterTest < Test::Unit::TestCase
def setup
Fluent::Test.setup
end

def create_driver(conf = "")
Fluent::Test::Driver::Formatter.new(NullFormatter).configure(conf)
end

test 'run w/ block returns last evaluated value in block' do
d = create_driver
value = d.run do
:value
end
assert_equal(value, :value)
end

test 'run w/o block returns nil' do
d = create_driver
assert_nil(d.run(timeout: 0.01))
end
end
28 changes: 28 additions & 0 deletions test/driver/test_input.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require_relative '../helper'
require 'fluent/test/driver/input'

class NullInput < Fluent::Plugin::Input
end

class TestDriverInputTest < Test::Unit::TestCase
def setup
Fluent::Test.setup
end

def create_driver(conf = "")
Fluent::Test::Driver::Input.new(NullInput).configure(conf)
end

test 'run w/ block returns last evaluated value in block' do
d = create_driver
value = d.run do
:value
end
assert_equal(value, :value)
end

test 'run w/o block returns nil' do
d = create_driver
assert_nil(d.run(timeout: 0.01))
end
end
26 changes: 26 additions & 0 deletions test/driver/test_output.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require_relative '../helper'
require 'fluent/test/driver/output'
require 'fluent/plugin/out_null'

class TestDriverOutputTest < Test::Unit::TestCase
def setup
Fluent::Test.setup
end

def create_driver(conf = "")
Fluent::Test::Driver::Output.new(Fluent::Plugin::NullOutput).configure(conf)
end

test 'run w/ block returns last evaluated value in block' do
d = create_driver
value = d.run do
:value
end
assert_equal(value, :value)
end

test 'run w/o block returns nil' do
d = create_driver
assert_nil(d.run(timeout: 0.01))
end
end
31 changes: 31 additions & 0 deletions test/driver/test_parser.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require_relative '../helper'
require 'fluent/test/driver/parser'

class NullParser < Fluent::Plugin::Parser
def parse(text)
yield nil, nil
end
end

class TestDriverParserTest < Test::Unit::TestCase
def setup
Fluent::Test.setup
end

def create_driver(conf = "")
Fluent::Test::Driver::Parser.new(NullParser).configure(conf)
end

test 'run w/ block returns last evaluated value in block' do
d = create_driver
value = d.run do
:value
end
assert_equal(value, :value)
end

test 'run w/o block returns nil' do
d = create_driver
assert_nil(d.run(timeout: 0.01))
end
end