Last active
March 20, 2019 19:19
-
-
Save bvandgrift/13d6f6a3ec0e2ac7f8e0170416a81909 to your computer and use it in GitHub Desktop.
throwaway sketch for a maybe test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment