Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- test "don't do unnecessary work for no change" do
- # let's assume that there's an enqueue(evt) method which pulls an event into the
- # processing pipeline, and that the enqueue method in turn calls a process(evt) method
- # let's further assume that if an event has an attribute, once processed, we don't want
- # to process it again for the same attribute value. so evt(attr:5), evt(attr:5), evt(attr:6) would
- # generate two process() calls, not three.
- pipeline = Pipeline.new() # or whatever
- spy = mock_method(pipeline.process) # maybe this
- # enqueue our first event
- evt1 = Event.new(attr: 5)
- pipeline.enqueue(evt1)
- assert pipeline.queue.length == 1
- # or
- assert spy.times_called == 1
- # enqueue our second, duplicate event
- dupe_evt1 = Event.new(attr: 5)
- pipeline.enqueue(dup_evt1)
- assert pipeline.queue.length == 1 # dup is discarded
- # or
- assert spy.times_called == 1
- # enqueue our third, unique event
- evt2 = Event.new(attr: 6)
- pipeline.enqueue(evt2)
- assert pipeline.queue.length == 2 # new event is enqueued
- # or
- assert spy.times_called == 2
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement