From cca00408e2d797a79b09531d313378aca5b76e57 Mon Sep 17 00:00:00 2001 From: Holger Just Date: Wed, 16 Aug 2017 20:54:55 +0200 Subject: [PATCH] With allow_silent, also check the presence of an explicit timestamp for Buffer#pending? --- lib/rackstash/buffer.rb | 6 ++++-- spec/rackstash/buffer_spec.rb | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/rackstash/buffer.rb b/lib/rackstash/buffer.rb index f983639..96d7eb9 100644 --- a/lib/rackstash/buffer.rb +++ b/lib/rackstash/buffer.rb @@ -206,14 +206,16 @@ module Rackstash # This flag denotes whether the current buffer holds flushable data. By # default, a new buffer is not pending and will not be flushed to the sink. # Each time there is a new message logged, this is set to `true` for the - # buffer. For changes of tags or fields, the `pending?` flag is only - # flipped to `true` if {#allow_silent?} is set to `true`. + # buffer. For changes of tags or fields or when setting the {#timestamp}, + # the `pending?` flag is only flipped to `true` if {#allow_silent?} is set + # to `true`. # # @return [Boolean] `true` if the buffer has stored data which should be # flushed. def pending? return true if @messages.any? if allow_silent? + return true unless @timestamp.nil? return true unless @fields.nil? || @fields.empty? return true unless @tags.nil? || @tags.empty? end diff --git a/spec/rackstash/buffer_spec.rb b/spec/rackstash/buffer_spec.rb index 5f10d43..893dc2b 100644 --- a/spec/rackstash/buffer_spec.rb +++ b/spec/rackstash/buffer_spec.rb @@ -283,6 +283,11 @@ describe Rackstash::Buffer do buffer.tags << 'alice' expect(buffer.pending?).to be true end + + it 'is true if the timestamp was set' do + buffer.timestamp + expect(buffer.pending?).to be true + end end context 'with allow_silent: false' do @@ -304,6 +309,11 @@ describe Rackstash::Buffer do buffer.tags << 'alice' expect(buffer.pending?).to be false end + + it 'ignores the timestamp' do + buffer.timestamp + expect(buffer.pending?).to be false + end end end