logstash-plugins / logstash-output-google_cloud_storage

Apache License 2.0
9 stars 26 forks source link

Test reliant on timing causing nondeterministic results #28

Closed josephlewis42 closed 6 years ago

josephlewis42 commented 6 years ago

It looks like there's a timing issue in this test even with nanoseconds being the timestamp. Maybe replace all instances of the %N with millis and nanos and add a sleep (or mock the calls to Time).

https://github.com/logstash-plugins/logstash-output-google_cloud_storage/blob/db32da1aea5e7980da1d3fb200a7f9530e6095f6/spec/outputs/gcs/path_factory_spec.rb#L117

It's causing this error to show up in CI:

https://travis-ci.org/logstash-plugins/logstash-output-google_cloud_storage/jobs/379924151

josephlewis42 commented 6 years ago

More info:

Failures:

  1) LogStash::Outputs::Gcs::SynchronizedLogFile behaves like a log file #time_since_sync returns a delta
     Got 1 failure and 1 other error:
     Shared Example Group: "a log file" called from ./spec/outputs/gcs/temp_log_file_spec.rb:118

     1.1) Failure/Error: expect(Time).to receive(:now).and_return(30, 40, 50)
          
            (Time (class)).now(*(any args))
                expected: 3 times with any arguments
                received: 4 times with any arguments
          # ./spec/outputs/gcs/temp_log_file_spec.rb:71:in `block in (root)'
          # /home/travis/.rvm/gems/jruby-9.1.13.0/gems/rspec-wait-0.0.9/lib/rspec/wait.rb:46:in `block in (root)'

     1.2) Failure/Error: date: Time.now.strftime(@date_pattern),
          
          NoMethodError:
            undefined method `strftime' for 50:Fixnum
          # ./lib/logstash/outputs/gcs/path_factory.rb:82:in `template_variables'
          # ./lib/logstash/outputs/gcs/path_factory.rb:89:in `next_base'
          # ./lib/logstash/outputs/gcs/path_factory.rb:48:in `block in should_rotate?'
          # ./lib/logstash/outputs/gcs/path_factory.rb:47:in `should_rotate?'
          # ./lib/logstash/outputs/gcs/log_rotate.rb:67:in `block in should_rotate?'
          # /home/travis/.rvm/gems/jruby-9.1.13.0/gems/concurrent-ruby-1.0.5-java/lib/concurrent/atomic/reentrant_read_write_lock.rb:126:in `with_read_lock'
          # ./lib/logstash/outputs/gcs/log_rotate.rb:66:in `should_rotate?'
          # ./lib/logstash/outputs/gcs/log_rotate.rb:28:in `block in writeln'
          # /home/travis/.rvm/gems/jruby-9.1.13.0/gems/concurrent-ruby-1.0.5-java/lib/concurrent/atomic/reentrant_read_write_lock.rb:145:in `with_write_lock'
          # ./lib/logstash/outputs/gcs/log_rotate.rb:27:in `writeln'
          # ./lib/logstash/outputs/google_cloud_storage.rb:229:in `block in start_uploader'
          # /home/travis/.rvm/gems/jruby-9.1.13.0/gems/stud-0.0.23/lib/stud/interval.rb:20:in `interval'
          # ./lib/logstash/outputs/google_cloud_storage.rb:228:in `block in start_uploader'

  2) LogStash::Outputs::Gcs::SynchronizedLogFile behaves like a log file #time_since_sync returns a delta
     Got 1 failure and 1 other error:
     Shared Example Group: "a log file" called from ./spec/outputs/gcs/temp_log_file_spec.rb:118

     2.1) Failure/Error: expect(Time).to receive(:now).and_return(30, 40, 50)
          
            (Time (class)).now(*(any args))
                expected: 3 times with any arguments
                received: 4 times with any arguments
          # ./spec/outputs/gcs/temp_log_file_spec.rb:71:in `block in (root)'
          # /home/travis/.rvm/gems/jruby-9.1.13.0/gems/rspec-wait-0.0.9/lib/rspec/wait.rb:46:in `block in (root)'

     2.2) Failure/Error: date: Time.now.strftime(@date_pattern),
          
          NoMethodError:
            undefined method `strftime' for 50:Fixnum
          # ./lib/logstash/outputs/gcs/path_factory.rb:82:in `template_variables'
          # ./lib/logstash/outputs/gcs/path_factory.rb:89:in `next_base'
          # ./lib/logstash/outputs/gcs/path_factory.rb:48:in `block in should_rotate?'
          # ./lib/logstash/outputs/gcs/path_factory.rb:47:in `should_rotate?'
          # ./lib/logstash/outputs/gcs/log_rotate.rb:67:in `block in should_rotate?'
          # /home/travis/.rvm/gems/jruby-9.1.13.0/gems/concurrent-ruby-1.0.5-java/lib/concurrent/atomic/reentrant_read_write_lock.rb:126:in `with_read_lock'
          # ./lib/logstash/outputs/gcs/log_rotate.rb:66:in `should_rotate?'
          # ./lib/logstash/outputs/gcs/log_rotate.rb:28:in `block in writeln'
          # /home/travis/.rvm/gems/jruby-9.1.13.0/gems/concurrent-ruby-1.0.5-java/lib/concurrent/atomic/reentrant_read_write_lock.rb:145:in `with_write_lock'
          # ./lib/logstash/outputs/gcs/log_rotate.rb:27:in `writeln'
          # ./lib/logstash/outputs/google_cloud_storage.rb:229:in `block in start_uploader'
          # /home/travis/.rvm/gems/jruby-9.1.13.0/gems/stud-0.0.23/lib/stud/interval.rb:20:in `interval'
          # ./lib/logstash/outputs/google_cloud_storage.rb:228:in `block in start_uploader'

Finished in 3.18 seconds (files took 3.56 seconds to load)
81 examples, 2 failures

Failed examples:

rspec ./spec/outputs/gcs/temp_log_file_spec.rb[3:1:6:1] # LogStash::Outputs::Gcs::SynchronizedLogFile behaves like a log file #time_since_sync returns a delta
rspec ./spec/outputs/gcs/temp_log_file_spec.rb[3:1:6:1] # LogStash::Outputs::Gcs::SynchronizedLogFile behaves like a log file #time_since_sync returns a delta

Randomized with seed 11809
josephlewis42 commented 6 years ago

Different distinct failure:


Randomized with seed 10964
...................F............................................................
Failures:
  1) LogStash::Outputs::Gcs::PathFactory rotate_path! resets the part number if the base has changed
     Failure/Error: expect(pf.current_path).to include('part000')
       expected "dir/pre_970000000.part001.log" to include "part000"
     # ./spec/outputs/gcs/path_factory_spec.rb:125:in `(root)'
     # /home/travis/.rvm/gems/jruby-1.7.27/gems/rspec-wait-0.0.9/lib/rspec/wait.rb:46:in `(root)'
Finished in 2.74 seconds (files took 6.81 seconds to load)
80 examples, 1 failure
Failed examples:
rspec ./spec/outputs/gcs/path_factory_spec.rb:112 # LogStash::Outputs::Gcs::PathFactory rotate_path! resets the part number if the base has changed
Randomized with seed 10964

These might be caused by a background thread waking up and rotating files; we need to make sure this (and concurrent execution) isn't happening.