Skip to content

Commit

Permalink
Merge pull request #2494 from ganmacs/fix-vulnerable-test
Browse files Browse the repository at this point in the history
Fix vulnerable tests
  • Loading branch information
ganmacs authored Jul 17, 2019
2 parents 1d59e1a + 864e11b commit e5f9a01
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions test/plugin/test_output_as_buffered.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1079,40 +1079,42 @@ def waiting(seconds)
end

sub_test_case 'buffered output with large timekey and small timekey_wait' do
setup do
test 'writes event in proper interval' do
chunk_key = 'time'
hash = {
'timekey' => 86400, # per 1 day
'timekey_wait' => 10, # 10 seconds delay for flush
'flush_thread_count' => 1,
'flush_thread_burst_interval' => 0.01,
}
@i = create_output(:buffered)
@i.configure(config_element('ROOT','',{},[config_element('buffer',chunk_key,hash)]))
@i.start
@i.after_start
end

test '#configure raises config error if timekey is not specified' do
Timecop.freeze( Time.parse('2019-02-08 00:01:00 +0900') )
ary = []
@i.register(:write){|chunk| ary << chunk.read }
@i.thread_wait_until_start
events = [
[event_time('2019-02-08 00:02:00 +0900'), {"message" => "foobar"}]
]
@i.emit_events("test.tag", Fluent::ArrayEventStream.new(events))
@i.enqueue_thread_wait
assert{ @i.write_count == 0 }
with_timezone("UTC+09") do
Timecop.freeze(Time.parse('2019-02-08 00:01:00 +0900'))
@i = create_output(:buffered)
# timezone is set
@i.configure(config_element('ROOT', '', {}, [config_element('buffer',chunk_key,hash)]))
@i.start
@i.after_start
@i.thread_wait_until_start
assert_equal(0, @i.write_count)
@i.interrupt_flushes

Timecop.freeze( Time.parse('2019-02-09 00:00:08 +0900') )
@i.enqueue_thread_wait
assert{ @i.write_count == 0 }
events = [
[event_time('2019-02-08 00:02:00 +0900'), { "message" => "foobar" }]
]
@i.emit_events("test.tag", Fluent::ArrayEventStream.new(events))
@i.enqueue_thread_wait
assert_equal(0, @i.write_count)

Timecop.freeze( Time.parse('2019-02-09 00:00:12 +0900') )
# wirte should be called in few seconds since
# running interval of enque thread is timekey_wait / 11.0.
waiting(5){ sleep 0.1 until @i.write_count == 1 }
Timecop.freeze(Time.parse('2019-02-09 00:00:08 +0900'))
@i.enqueue_thread_wait
assert_equal(0, @i.write_count)

Timecop.freeze(Time.parse('2019-02-09 00:00:12 +0900'))
# wirte should be called in few seconds since
# running interval of enque thread is timekey_wait / 11.0.
waiting(5){ sleep 0.1 until @i.write_count == 1 }
end
end
end

Expand Down

0 comments on commit e5f9a01

Please sign in to comment.