macournoyer / thin

A very fast & simple Ruby web server
https://rubygems.org/gems/thin
2.27k stars 345 forks source link

Flaky specs #368

Closed ioquatix closed 4 years ago

ioquatix commented 4 years ago

I cannot get daemonization specs to pass.

I also observed the daemonization spec did not pass on the current latest master branch before rebasing. But after rebasing on feature/rspec3 on the master branch, the spec passed on my local.

Instead of that, I saw the following 2 Thin::Logging tracing routines (with NO custom logger) specs failed on Ruby 2.7.1, Fedora 32 on my local machine.

  1) Thin::Logging tracing routines (with NO custom logger) should emit trace messages if tracing is enabled-
     Failure/Error: out.include?("Hey").should be_truthy

       expected: truthy value
            got: false
     # ./spec/logging_spec.rb:158:in `block (3 levels) in <top (required)>'

  2) Thin::Logging tracing routines (with NO custom logger) should be usable (at the module level) for logging
     Failure/Error: out.include?("hey").should be_truthy

       expected: truthy value
            got: false
     # ./spec/logging_spec.rb:167:in `block (3 levels) in <top (required)>'

@object.trace and Logging.trace_msg are methods to output the message when Logging.trace? is true.

The 2 spec passed when it was executed as isolated test.

$ bundle exec rspec spec/logging_spec.rb:158

$ bundle exec rspec spec/logging_spec.rb:167

The 2 specs still failed when running like this.

$ bundle exec rspec spec/logging_spec.rb

But when adding the following code, as a sub consequence (?), the 2 spec passed on my local when running bundle exec rspec spec/logging_spec.rb. :-)

$ git diff
diff --git a/spec/logging_spec.rb b/spec/logging_spec.rb
index 9510c1f..d38f005 100644
--- a/spec/logging_spec.rb
+++ b/spec/logging_spec.rb
@@ -151,7 +151,9 @@ describe Logging do

     it "should emit trace messages if tracing is enabled " do
       Logging.trace = true
+      p "[DEBUG] Hey trace: #{Logging.trace?}"
       out = with_redirected_stdout do
+        p "[DEBUG] Hey trace: #{Logging.trace?}"
         @object.trace("Hey")
       end

@@ -160,7 +162,9 @@ describe Logging do

     it "should be usable (at the module level) for logging" do
       Logging.trace = true
+      p "[DEBUG] hey trace: #{Logging.trace?}"
       out = with_redirected_stdout do
+        p "[DEBUG] hey trace: #{Logging.trace?}"
         Logging.trace_msg("hey")
       end

It's great if you take a look at the code. Thanks.

Originally posted by @junaruga in https://github.com/macournoyer/thin/pull/334#issuecomment-668146586

ioquatix commented 4 years ago

@macournoyer & @junaruga I've reworked the specs and they are all passing now. I hope we didn't loose any important tests by my changes, but it looks good.