Shopify / statsd-instrument

A StatsD client for Ruby apps. Provides metaprogramming methods to inject StatsD instrumentation into your code.
http://shopify.github.io/statsd-instrument
MIT License
574 stars 97 forks source link

Clean up some test noise #362

Closed catlee closed 8 months ago

catlee commented 8 months ago

I was having problems with sporadic output from the tests, e.g.

rake TESTOPTS="--seed=46384" test                                                       
Run options: --seed=46384                                                                                                                                      

# Running:                                                                                                                                                     

............................................/opt/rubies/ruby-3.1.4-pshopify1/lib/ruby/3.1.0/psych/nodes/scalar.rb:65: warning: Exception in finalizer #<Proc:0x
00007f76b40897d8 /home/spin/src/github.com/Shopify/statsd-instrument/lib/statsd/instrument/udp_sink.rb:17 (lambda)>                                            
/home/spin/src/github.com/Shopify/statsd-instrument/lib/statsd/instrument/udp_sink.rb:20:in `block (2 levels) in <class:UDPSink>': #<Mock:socket> was instantia
ted in one test but it is receiving invocations within another test. This can lead to unintended interactions between tests and hence unexpected test failures.
 Ensure that every test correctly cleans up any state that it introduces. (Mocha::StubbingError)                                                               
        from /home/spin/src/github.com/Shopify/statsd-instrument/lib/statsd/instrument/udp_sink.rb:18:in `each'                                                
        from /home/spin/src/github.com/Shopify/statsd-instrument/lib/statsd/instrument/udp_sink.rb:18:in `block in <class:UDPSink>'                            
        from /opt/rubies/ruby-3.1.4-pshopify1/lib/ruby/3.1.0/psych/nodes/scalar.rb:65:in `initialize'                                                          
        from /opt/rubies/ruby-3.1.4-pshopify1/lib/ruby/3.1.0/psych/tree_builder.rb:97:in `new'                                                                 
        from /opt/rubies/ruby-3.1.4-pshopify1/lib/ruby/3.1.0/psych/tree_builder.rb:97:in `scalar'                              
...

I think this could be because the mock socket doesn't necessarily get cleaned up right away after the UDP sink tests execute.

I also added an expectation for the environment test mainly to avoid that warning from spamming the console every time tests are run.