@@ -43,12 +43,26 @@ suite(testing.suiteName(), function() {
43434444 wp . email_on_error || false ,
4545 ] ;
46- const with_cap = await db . fns . update_worker_pool_with_capacity ( ...input ) ;
46+ const with_cap = await db . fns . update_worker_pool_with_capacity_and_counts_by_state ( ...input ) ;
4747 for ( const wp of with_cap ) {
48- assert ( wp . current_capacity !== undefined ) ;
49- delete wp . current_capacity ;
48+ assert ( wp . requested_count !== undefined ) ;
49+ assert ( wp . running_count !== undefined ) ;
50+ assert ( wp . stopping_count !== undefined ) ;
51+ assert ( wp . stopped_count !== undefined ) ;
52+ assert ( wp . requested_capacity !== undefined ) ;
53+ assert ( wp . running_capacity !== undefined ) ;
54+ assert ( wp . stopping_capacity !== undefined ) ;
55+ assert ( wp . stopped_capacity !== undefined ) ;
56+ delete wp . requested_count ;
57+ delete wp . running_count ;
58+ delete wp . stopping_count ;
59+ delete wp . stopped_count ;
60+ delete wp . requested_capacity ;
61+ delete wp . running_capacity ;
62+ delete wp . stopping_capacity ;
63+ delete wp . stopped_capacity ;
5064 }
51- const old = await db . deprecatedFns . update_worker_pool ( ...input ) ;
65+ const old = await db . deprecatedFns . update_worker_pool_with_capacity ( ...input ) ;
5266 // We override previous_provider_id in this comparison because a side-effect
5367 // of calling this function is updating that value so we can't compare here
5468 assert . deepEqual ( { ...with_cap [ 0 ] , previous_provider_id : '' } , { ...old [ 0 ] , previous_provider_id : '' } ) ;
@@ -115,23 +129,51 @@ suite(testing.suiteName(), function() {
115129 } ;
116130
117131 const get_worker_pool = async ( db , worker_pool_id ) => {
118- const with_cap = await db . fns . get_worker_pool_with_capacity ( worker_pool_id ) ;
132+ const with_cap = await db . fns . get_worker_pool_with_capacity_and_counts_by_state ( worker_pool_id ) ;
119133 for ( const wp of with_cap ) {
120- assert ( wp . current_capacity !== undefined ) ;
121- delete wp . current_capacity ;
134+ assert ( wp . requested_count !== undefined ) ;
135+ assert ( wp . running_count !== undefined ) ;
136+ assert ( wp . stopping_count !== undefined ) ;
137+ assert ( wp . stopped_count !== undefined ) ;
138+ assert ( wp . requested_capacity !== undefined ) ;
139+ assert ( wp . running_capacity !== undefined ) ;
140+ assert ( wp . stopping_capacity !== undefined ) ;
141+ assert ( wp . stopped_capacity !== undefined ) ;
142+ delete wp . requested_count ;
143+ delete wp . running_count ;
144+ delete wp . stopping_count ;
145+ delete wp . stopped_count ;
146+ delete wp . requested_capacity ;
147+ delete wp . running_capacity ;
148+ delete wp . stopping_capacity ;
149+ delete wp . stopped_capacity ;
122150 }
123- const old = await db . deprecatedFns . get_worker_pool ( worker_pool_id ) ;
151+ const old = await db . deprecatedFns . get_worker_pool_with_capacity ( worker_pool_id ) ;
124152 assert . deepEqual ( with_cap , old ) ;
125153 return with_cap ;
126154 } ;
127155
128156 const get_worker_pools = async ( db , page_size , page_offset ) => {
129- const with_cap = await db . fns . get_worker_pools_with_capacity ( page_size , page_offset ) ;
157+ const with_cap = await db . fns . get_worker_pools_with_capacity_and_counts_by_state ( page_size , page_offset ) ;
130158 for ( const wp of with_cap ) {
131- assert ( wp . current_capacity !== undefined ) ;
132- delete wp . current_capacity ;
159+ assert ( wp . requested_count !== undefined ) ;
160+ assert ( wp . running_count !== undefined ) ;
161+ assert ( wp . stopping_count !== undefined ) ;
162+ assert ( wp . stopped_count !== undefined ) ;
163+ assert ( wp . requested_capacity !== undefined ) ;
164+ assert ( wp . running_capacity !== undefined ) ;
165+ assert ( wp . stopping_capacity !== undefined ) ;
166+ assert ( wp . stopped_capacity !== undefined ) ;
167+ delete wp . requested_count ;
168+ delete wp . running_count ;
169+ delete wp . stopping_count ;
170+ delete wp . stopped_count ;
171+ delete wp . requested_capacity ;
172+ delete wp . running_capacity ;
173+ delete wp . stopping_capacity ;
174+ delete wp . stopped_capacity ;
133175 }
134- const old = await db . deprecatedFns . get_worker_pools ( page_size , page_offset ) ;
176+ const old = await db . deprecatedFns . get_worker_pools_with_capacity ( page_size , page_offset ) ;
135177 assert . deepEqual ( with_cap , old ) ;
136178 return with_cap ;
137179 } ;
@@ -901,54 +943,108 @@ suite(testing.suiteName(), function() {
901943 suite ( 'existing capacity' , function ( ) {
902944 helper . dbTest ( 'no workers' , async function ( db ) {
903945 await create_worker_pool ( db ) ;
904- assert . equal ( ( await db . fns . get_worker_pool_with_capacity ( 'wp/id' ) ) [ 0 ] . current_capacity , 0 ) ;
946+ const row = ( await db . fns . get_worker_pool_with_capacity_and_counts_by_state ( 'wp/id' ) ) [ 0 ] ;
947+ assert . equal ( row . current_capacity , 0 ) ;
948+ assert . equal ( row . requested_count , 0 ) ;
949+ assert . equal ( row . running_count , 0 ) ;
950+ assert . equal ( row . stopping_count , 0 ) ;
951+ assert . equal ( row . stopped_count , 0 ) ;
952+ assert . equal ( row . requested_capacity , 0 ) ;
953+ assert . equal ( row . running_capacity , 0 ) ;
954+ assert . equal ( row . stopping_capacity , 0 ) ;
955+ assert . equal ( row . stopped_capacity , 0 ) ;
905956 } ) ;
906957 helper . dbTest ( 'single worker, capacity 1' , async function ( db ) {
907958 await create_worker_pool ( db ) ;
908959 await create_worker ( db , { capacity : 1 , state : 'running' } ) ;
909- assert . equal ( ( await db . fns . get_worker_pool_with_capacity ( 'wp/id' ) ) [ 0 ] . current_capacity , 1 ) ;
960+ const row = ( await db . fns . get_worker_pool_with_capacity_and_counts_by_state ( 'wp/id' ) ) [ 0 ] ;
961+ assert . equal ( row . current_capacity , 1 ) ;
962+ assert . equal ( row . requested_count , 0 ) ;
963+ assert . equal ( row . running_count , 1 ) ;
964+ assert . equal ( row . stopping_count , 0 ) ;
965+ assert . equal ( row . stopped_count , 0 ) ;
966+ assert . equal ( row . requested_capacity , 0 ) ;
967+ assert . equal ( row . running_capacity , 1 ) ;
968+ assert . equal ( row . stopping_capacity , 0 ) ;
969+ assert . equal ( row . stopped_capacity , 0 ) ;
910970 } ) ;
911971 helper . dbTest ( 'single worker, capacity > 1' , async function ( db ) {
912972 await create_worker_pool ( db ) ;
913973 await create_worker ( db , { capacity : 64 , state : 'running' } ) ;
914- assert . equal ( ( await db . fns . get_worker_pool_with_capacity ( 'wp/id' ) ) [ 0 ] . current_capacity , 64 ) ;
974+ const row = ( await db . fns . get_worker_pool_with_capacity_and_counts_by_state ( 'wp/id' ) ) [ 0 ] ;
975+ assert . equal ( row . current_capacity , 64 ) ;
976+ assert . equal ( row . requested_count , 0 ) ;
977+ assert . equal ( row . running_count , 1 ) ;
978+ assert . equal ( row . stopping_count , 0 ) ;
979+ assert . equal ( row . stopped_count , 0 ) ;
980+ assert . equal ( row . requested_capacity , 0 ) ;
981+ assert . equal ( row . running_capacity , 64 ) ;
982+ assert . equal ( row . stopping_capacity , 0 ) ;
983+ assert . equal ( row . stopped_capacity , 0 ) ;
915984 } ) ;
916985 helper . dbTest ( 'multiple workers, capacity 1' , async function ( db ) {
917986 await create_worker_pool ( db ) ;
918987 await create_worker ( db , { worker_id : 'foo1' , capacity : 1 , state : 'running' } ) ;
919988 await create_worker ( db , { worker_id : 'foo2' , capacity : 1 , state : 'running' } ) ;
920989 await create_worker ( db , { worker_id : 'foo3' , capacity : 1 , state : 'running' } ) ;
921990 await create_worker ( db , { worker_id : 'foo4' , capacity : 1 , state : 'running' } ) ;
922- assert . equal ( ( await db . fns . get_worker_pool_with_capacity ( 'wp/id' ) ) [ 0 ] . current_capacity , 4 ) ;
991+ const row = ( await db . fns . get_worker_pool_with_capacity_and_counts_by_state ( 'wp/id' ) ) [ 0 ] ;
992+ assert . equal ( row . current_capacity , 4 ) ;
993+ assert . equal ( row . requested_count , 0 ) ;
994+ assert . equal ( row . running_count , 4 ) ;
995+ assert . equal ( row . stopping_count , 0 ) ;
996+ assert . equal ( row . stopped_count , 0 ) ;
997+ assert . equal ( row . requested_capacity , 0 ) ;
998+ assert . equal ( row . running_capacity , 4 ) ;
999+ assert . equal ( row . stopping_capacity , 0 ) ;
1000+ assert . equal ( row . stopped_capacity , 0 ) ;
9231001 } ) ;
9241002 helper . dbTest ( 'multiple workers, capacity > 1' , async function ( db ) {
9251003 await create_worker_pool ( db ) ;
9261004 await create_worker ( db , { worker_id : 'foo1' , capacity : 32 , state : 'running' } ) ;
9271005 await create_worker ( db , { worker_id : 'foo2' , capacity : 64 , state : 'running' } ) ;
9281006 await create_worker ( db , { worker_id : 'foo3' , capacity : 64 , state : 'running' } ) ;
9291007 await create_worker ( db , { worker_id : 'foo4' , capacity : 1 , state : 'running' } ) ;
930- assert . equal ( ( await db . fns . get_worker_pool_with_capacity ( 'wp/id' ) ) [ 0 ] . current_capacity , 161 ) ;
1008+ const row = ( await db . fns . get_worker_pool_with_capacity_and_counts_by_state ( 'wp/id' ) ) [ 0 ] ;
1009+ assert . equal ( row . current_capacity , 161 ) ;
1010+ assert . equal ( row . requested_count , 0 ) ;
1011+ assert . equal ( row . running_count , 4 ) ;
1012+ assert . equal ( row . stopping_count , 0 ) ;
1013+ assert . equal ( row . stopped_count , 0 ) ;
1014+ assert . equal ( row . requested_capacity , 0 ) ;
1015+ assert . equal ( row . running_capacity , 161 ) ;
1016+ assert . equal ( row . stopping_capacity , 0 ) ;
1017+ assert . equal ( row . stopped_capacity , 0 ) ;
9311018 } ) ;
9321019 helper . dbTest ( 'multiple workers, multiple states' , async function ( db ) {
9331020 await create_worker_pool ( db ) ;
9341021 await create_worker ( db , { worker_id : 'foo1' , capacity : 32 , state : 'running' } ) ;
9351022 await create_worker ( db , { worker_id : 'foo2' , capacity : 64 , state : 'stopped' } ) ;
9361023 await create_worker ( db , { worker_id : 'foo3' , capacity : 64 , state : 'running' } ) ;
9371024 await create_worker ( db , { worker_id : 'foo4' , capacity : 1 , state : 'requested' } ) ;
938- assert . equal ( ( await db . fns . get_worker_pool_with_capacity ( 'wp/id' ) ) [ 0 ] . current_capacity , 97 ) ;
1025+ const row = ( await db . fns . get_worker_pool_with_capacity_and_counts_by_state ( 'wp/id' ) ) [ 0 ] ;
1026+ assert . equal ( row . current_capacity , 97 ) ;
1027+ assert . equal ( row . requested_count , 1 ) ;
1028+ assert . equal ( row . running_count , 2 ) ;
1029+ assert . equal ( row . stopping_count , 0 ) ;
1030+ assert . equal ( row . stopped_count , 1 ) ;
1031+ assert . equal ( row . requested_capacity , 1 ) ;
1032+ assert . equal ( row . running_capacity , 96 ) ;
1033+ assert . equal ( row . stopping_capacity , 0 ) ;
1034+ assert . equal ( row . stopped_capacity , 64 ) ;
9391035 } ) ;
9401036 helper . dbTest ( 'no workers (multiple pools)' , async function ( db ) {
9411037 await create_worker_pool ( db ) ;
9421038 await create_worker_pool ( db , { worker_pool_id : 'ff/tt' } ) ;
943- const pools = ( await db . fns . get_worker_pools_with_capacity ( null , null ) ) . sort ( ) ;
1039+ const pools = ( await db . fns . get_worker_pools_with_capacity_and_counts_by_state ( null , null ) ) . sort ( ) ;
9441040 assert . equal ( pools [ 0 ] . current_capacity , 0 ) ;
9451041 assert . equal ( pools [ 1 ] . current_capacity , 0 ) ;
9461042 } ) ;
9471043 helper . dbTest ( 'single worker (multiple pools)' , async function ( db ) {
9481044 await create_worker_pool ( db ) ;
9491045 await create_worker_pool ( db , { worker_pool_id : 'ff/tt' } ) ;
9501046 await create_worker ( db , { capacity : 4 , state : 'running' } ) ;
951- const pools = ( await db . fns . get_worker_pools_with_capacity ( null , null ) ) . sort ( ) ;
1047+ const pools = ( await db . fns . get_worker_pools_with_capacity_and_counts_by_state ( null , null ) ) . sort ( ) ;
9521048 assert . equal ( pools [ 0 ] . worker_pool_id , 'ff/tt' ) ;
9531049 assert . equal ( pools [ 1 ] . worker_pool_id , 'wp/id' ) ;
9541050 assert . equal ( pools [ 0 ] . current_capacity , 0 ) ;
@@ -962,7 +1058,7 @@ suite(testing.suiteName(), function() {
9621058 await create_worker ( db , { worker_id : 'foo3' , capacity : 10 , state : 'running' , worker_pool_id : 'ff/tt' } ) ;
9631059 await create_worker ( db , { worker_id : 'foo4' , capacity : 3 , state : 'stopped' } ) ;
9641060 await create_worker ( db , { worker_id : 'foo5' , capacity : 7 , state : 'stopped' , worker_pool_id : 'ff/tt' } ) ;
965- const pools = ( await db . fns . get_worker_pools_with_capacity ( null , null ) ) . sort ( ) ;
1061+ const pools = ( await db . fns . get_worker_pools_with_capacity_and_counts_by_state ( null , null ) ) . sort ( ) ;
9661062 assert . equal ( pools [ 0 ] . worker_pool_id , 'ff/tt' ) ;
9671063 assert . equal ( pools [ 1 ] . worker_pool_id , 'wp/id' ) ;
9681064 assert . equal ( pools [ 0 ] . current_capacity , 10 ) ;
0 commit comments