daily pastebin goal
0%
SHARE
TWEET

Untitled

a guest Mar 26th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. test "don't do unnecessary work for no change" do
  2.  
  3.   # let's assume that there's an enqueue(evt) method which pulls an event into the
  4.   # processing pipeline, and that the enqueue method in turn calls a process(evt) method
  5.  
  6.   # let's further assume that if an event has an attribute, once processed, we don't want
  7.   # to process it again for the same attribute value. so evt(attr:5), evt(attr:5), evt(attr:6) would
  8.   # generate two process() calls, not three.
  9.  
  10.   pipeline = Pipeline.new() # or whatever
  11.   spy = mock_method(pipeline.process) # maybe this
  12.  
  13.   # enqueue our first event
  14.   evt1 = Event.new(attr: 5)
  15.   pipeline.enqueue(evt1)
  16.   assert pipeline.queue.length == 1
  17.   # or
  18.   assert spy.times_called == 1
  19.  
  20.   # enqueue our second, duplicate event
  21.   dupe_evt1 = Event.new(attr: 5)
  22.   pipeline.enqueue(dup_evt1)
  23.   assert pipeline.queue.length == 1 # dup is discarded
  24.   # or
  25.   assert spy.times_called == 1
  26.  
  27.   # enqueue our third, unique event
  28.   evt2 = Event.new(attr: 6)
  29.   pipeline.enqueue(evt2)
  30.   assert pipeline.queue.length == 2 # new event is enqueued
  31.   # or
  32.   assert spy.times_called == 2
  33. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top