From 8a498391ca8528598f94af34c300e694d1fd18c9 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 15 Nov 2017 12:44:10 +1100 Subject: [PATCH] Add performance spec for removal of proxy orders --- spec/performance/proxy_order_syncer_spec.rb | 25 ++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/spec/performance/proxy_order_syncer_spec.rb b/spec/performance/proxy_order_syncer_spec.rb index 8956b1cc66..f07cc6f57b 100644 --- a/spec/performance/proxy_order_syncer_spec.rb +++ b/spec/performance/proxy_order_syncer_spec.rb @@ -19,7 +19,7 @@ module OpenFoodNetwork end context "measuring performance for initialisation" do - it "reports the average run time for 150 x 10 OCs" do + it "reports the average run time for adding 10 OCs to 150 standing orders" do expect(ProxyOrder.count).to be 0 times = [] 10.times do @@ -37,5 +37,28 @@ module OpenFoodNetwork puts "AVG: #{(times.sum/times.count).round(2)}" end end + + context "measuring performance for removal" do + it "reports the average run time for removing 8 OCs from 150 standing orders" do + times = [] + 10.times do + syncer = ProxyOrderSyncer.new(standing_orders.reload) + syncer.sync! + expect(ProxyOrder.count).to be 1500 + standing_orders.update_all(begins_at: start + 8.days + 1.minute) + syncer = ProxyOrderSyncer.new(standing_orders.reload) + sleep 1 + t1 = Time.now + syncer.sync! + t2 = Time.now + times << t2-t1 + puts (t2-t1).round(2) + expect(ProxyOrder.count).to be 300 + standing_orders.update_all(begins_at: start) + sleep 1 + end + puts "AVG: #{(times.sum/times.count).round(2)}" + end + end end end