33module VCAP ::CloudController
44 module Jobs ::Runtime
55 RSpec . describe PruneCompletedBuilds , job_context : :worker do
6- let ( :max_retained_builds_per_app ) { 15 }
6+ let ( :max_retained_builds_per_app ) { 3 }
77
88 subject ( :job ) { PruneCompletedBuilds . new ( max_retained_builds_per_app ) }
99
@@ -19,67 +19,67 @@ module Jobs::Runtime
1919 it 'deletes all the staged builds over the limit' do
2020 expect ( BuildModel . count ) . to eq ( 0 )
2121
22- total = 50
23- ( 1 ..50 ) . each do |i |
22+ total = 8
23+ ( 1 ..total ) . each do |i |
2424 BuildModel . make ( id : i , state : BuildModel ::STAGED_STATE , app : app , created_at : Time . now - total + i )
2525 end
2626
2727 job . perform
2828
29- expect ( BuildModel . count ) . to eq ( 15 )
30- expect ( BuildModel . map ( &:id ) ) . to match_array ( ( 36 .. 50 ) . to_a )
29+ expect ( BuildModel . count ) . to eq ( 3 )
30+ expect ( BuildModel . map ( &:id ) ) . to match_array ( ( 6 .. 8 ) . to_a )
3131 end
3232
3333 it 'deletes all failed builds over the limit' do
3434 expect ( BuildModel . count ) . to eq ( 0 )
3535
36- total = 50
37- ( 1 ..50 ) . each do |i |
36+ total = 8
37+ ( 1 ..total ) . each do |i |
3838 BuildModel . make ( id : i , state : BuildModel ::FAILED_STATE , app : app , created_at : Time . now - total + i )
3939 end
4040
4141 job . perform
4242
43- expect ( BuildModel . count ) . to eq ( 15 )
44- expect ( BuildModel . map ( &:id ) ) . to match_array ( ( 36 .. 50 ) . to_a )
43+ expect ( BuildModel . count ) . to eq ( 3 )
44+ expect ( BuildModel . map ( &:id ) ) . to match_array ( ( 6 .. 8 ) . to_a )
4545 end
4646
4747 it 'does NOT delete any staging builds over the limit' do
4848 expect ( BuildModel . count ) . to eq ( 0 )
4949
50- total = 50
51- ( 1 ..50 ) . each do |i |
50+ total = 8
51+ ( 1 ..total ) . each do |i |
5252 BuildModel . make ( id : i , state : BuildModel ::STAGING_STATE , app : app , created_at : Time . now - total + i )
5353 end
5454
5555 job . perform
5656
57- expect ( BuildModel . count ) . to eq ( 50 )
58- expect ( BuildModel . map ( &:id ) ) . to match_array ( ( 1 ..50 ) . to_a )
57+ expect ( BuildModel . count ) . to eq ( 8 )
58+ expect ( BuildModel . map ( &:id ) ) . to match_array ( ( 1 ..8 ) . to_a )
5959 end
6060
6161 it 'does not delete in-flight builds over the limit' do
62- total = 60
63- ( 1 ..20 ) . each do |i |
62+ total = 12
63+ ( 1 ..4 ) . each do |i |
6464 BuildModel . make ( id : i , state : BuildModel ::STAGED_STATE , app : app , created_at : Time . now - total + i )
6565 end
66- ( 21 .. 40 ) . each do |i |
66+ ( 5 .. 8 ) . each do |i |
6767 BuildModel . make ( id : i , state : BuildModel ::STAGING_STATE , app : app , created_at : Time . now - total + i )
6868 end
69- ( 41 .. 60 ) . each do |i |
69+ ( 9 .. 12 ) . each do |i |
7070 BuildModel . make ( id : i , state : BuildModel ::STAGED_STATE , app : app , created_at : Time . now - total + i )
7171 end
7272
7373 job . perform
7474
75- expect ( BuildModel . count ) . to be ( 35 )
76- expect ( BuildModel . order ( Sequel . asc ( :created_at ) , Sequel . asc ( :id ) ) . map ( &:id ) ) . to eq ( ( 21 .. 40 ) . to_a + ( 46 .. 60 ) . to_a )
75+ expect ( BuildModel . count ) . to be ( 7 )
76+ expect ( BuildModel . order ( Sequel . asc ( :created_at ) , Sequel . asc ( :id ) ) . map ( &:id ) ) . to eq ( ( 5 .. 8 ) . to_a + ( 10 .. 12 ) . to_a )
7777 end
7878
7979 it 'calls destroy on the BuildModel so association dependencies are respected' do
8080 expect ( BuildModel . count ) . to eq ( 0 )
8181
82- 50 . times do
82+ 8 . times do
8383 b = BuildModel . make ( state : BuildModel ::STAGED_STATE , app : app )
8484 BuildpackLifecycleDataModel . make ( build : b )
8585 end
@@ -97,22 +97,22 @@ module Jobs::Runtime
9797 expect ( BuildModel . count ) . to eq ( 0 )
9898
9999 [ app , app_the_second , app_the_third ] . each_with_index do |current_app , app_index |
100- total = 50
100+ total = 8
101101 ( 1 ..total ) . each do |i |
102102 BuildModel . make ( id : i + ( 1000 * app_index ) , state : BuildModel ::STAGED_STATE , app : current_app , created_at : Time . now - total + i )
103103 end
104104 end
105105
106106 job . perform
107107
108- expect ( BuildModel . where ( app :) . count ) . to eq ( 15 )
109- expect ( BuildModel . where ( app :) . map ( &:id ) ) . to match_array ( ( 36 .. 50 ) . to_a )
108+ expect ( BuildModel . where ( app :) . count ) . to eq ( 3 )
109+ expect ( BuildModel . where ( app :) . map ( &:id ) ) . to match_array ( ( 6 .. 8 ) . to_a )
110110
111- expect ( BuildModel . where ( app : app_the_second ) . count ) . to eq ( 15 )
112- expect ( BuildModel . where ( app : app_the_second ) . map ( &:id ) ) . to match_array ( ( 1036 .. 1050 ) . to_a )
111+ expect ( BuildModel . where ( app : app_the_second ) . count ) . to eq ( 3 )
112+ expect ( BuildModel . where ( app : app_the_second ) . map ( &:id ) ) . to match_array ( ( 1006 .. 1008 ) . to_a )
113113
114- expect ( BuildModel . where ( app : app_the_third ) . count ) . to eq ( 15 )
115- expect ( BuildModel . where ( app : app_the_third ) . map ( &:id ) ) . to match_array ( ( 2036 .. 2050 ) . to_a )
114+ expect ( BuildModel . where ( app : app_the_third ) . count ) . to eq ( 3 )
115+ expect ( BuildModel . where ( app : app_the_third ) . map ( &:id ) ) . to match_array ( ( 2006 .. 2008 ) . to_a )
116116 end
117117 end
118118
0 commit comments