@@ -2,6 +2,7 @@ import { describe, it, expect } from "vitest";
22import {
33 regionForQueue ,
44 backingForQueue ,
5+ containerQueueForComputeQueue ,
56 type WorkerGroupRegionRow ,
67} from "~/v3/workerRegions.server" ;
78
@@ -12,20 +13,26 @@ const groups: WorkerGroupRegionRow[] = [
1213 workloadType : "CONTAINER" ,
1314 hidden : false ,
1415 enableFastPath : false ,
16+ type : "MANAGED" ,
17+ projectId : null ,
1518 } ,
1619 {
1720 masterQueue : "us-east-1-next" ,
1821 region : "us-east-1" ,
1922 workloadType : "MICROVM" ,
2023 hidden : false ,
2124 enableFastPath : true ,
25+ type : "MANAGED" ,
26+ projectId : null ,
2227 } ,
2328 {
2429 masterQueue : "eu-central-1" ,
2530 region : "eu-central-1" ,
2631 workloadType : "CONTAINER" ,
2732 hidden : false ,
2833 enableFastPath : false ,
34+ type : "MANAGED" ,
35+ projectId : null ,
2936 } ,
3037] ;
3138
@@ -48,6 +55,8 @@ describe("regionForQueue", () => {
4855 workloadType : "CONTAINER" ,
4956 hidden : false ,
5057 enableFastPath : false ,
58+ type : "MANAGED" ,
59+ projectId : null ,
5160 } ,
5261 ] )
5362 ) . toBe ( "x" ) ;
@@ -73,6 +82,8 @@ describe("backingForQueue", () => {
7382 workloadType : "CONTAINER" ,
7483 hidden : false ,
7584 enableFastPath : false ,
85+ type : "MANAGED" ,
86+ projectId : null ,
7687 } ,
7788 ] )
7889 ) . toBeUndefined ( ) ;
@@ -85,15 +96,160 @@ describe("backingForQueue", () => {
8596 workloadType : "CONTAINER" ,
8697 hidden : false ,
8798 enableFastPath : false ,
99+ type : "MANAGED" ,
100+ projectId : null ,
88101 } ,
89102 {
90103 masterQueue : "us-east-1-next" ,
91104 region : "us-east-1" ,
92105 workloadType : "MICROVM" ,
93106 hidden : true ,
94107 enableFastPath : true ,
108+ type : "MANAGED" ,
109+ projectId : null ,
95110 } ,
96111 ] ;
97112 expect ( backingForQueue ( "us-east-1" , g ) ) . toBeUndefined ( ) ;
98113 } ) ;
99114} ) ;
115+
116+ describe ( "containerQueueForComputeQueue" , ( ) => {
117+ it ( "maps a legacy compute queue to its region's container queue" , ( ) => {
118+ expect ( containerQueueForComputeQueue ( "us-east-1-next" , groups ) ) . toBe ( "us-east-1" ) ;
119+ } ) ;
120+ it ( "keeps the scheduled class of a legacy queue" , ( ) => {
121+ expect ( containerQueueForComputeQueue ( "us-east-1-next:scheduled" , groups ) ) . toBe (
122+ "us-east-1:scheduled"
123+ ) ;
124+ } ) ;
125+ it ( "returns undefined for a container queue" , ( ) => {
126+ expect ( containerQueueForComputeQueue ( "us-east-1" , groups ) ) . toBeUndefined ( ) ;
127+ } ) ;
128+ it ( "returns undefined for an unknown queue" , ( ) => {
129+ expect ( containerQueueForComputeQueue ( "mystery" , groups ) ) . toBeUndefined ( ) ;
130+ } ) ;
131+ it ( "returns undefined when the region has no container group" , ( ) => {
132+ expect (
133+ containerQueueForComputeQueue ( "ap-1-next" , [
134+ {
135+ masterQueue : "ap-1-next" ,
136+ region : "ap-1" ,
137+ workloadType : "MICROVM" ,
138+ hidden : false ,
139+ enableFastPath : false ,
140+ type : "MANAGED" ,
141+ projectId : null ,
142+ } ,
143+ ] )
144+ ) . toBeUndefined ( ) ;
145+ } ) ;
146+ it ( "prefers the container group named after the region" , ( ) => {
147+ const g : WorkerGroupRegionRow [ ] = [
148+ {
149+ masterQueue : "private-us-east-1" ,
150+ region : "us-east-1" ,
151+ workloadType : "CONTAINER" ,
152+ hidden : false ,
153+ enableFastPath : false ,
154+ type : "MANAGED" ,
155+ projectId : null ,
156+ } ,
157+ ...groups ,
158+ ] ;
159+ expect ( containerQueueForComputeQueue ( "us-east-1-next" , g ) ) . toBe ( "us-east-1" ) ;
160+ } ) ;
161+ it ( "moves a v2 compute queue to the stable container lane of its region" , ( ) => {
162+ expect (
163+ containerQueueForComputeQueue ( "us-east-1:v2:scheduled:fresh:compute:canary" , groups )
164+ ) . toBe ( "us-east-1:v2:scheduled:fresh:container:stable" ) ;
165+ } ) ;
166+ it ( "accepts a container group without a region that serves the queue's region by name" , ( ) => {
167+ expect (
168+ containerQueueForComputeQueue ( "eu-west-1:v2:ondemand:fresh:compute:stable" , [
169+ {
170+ masterQueue : "eu-west-1" ,
171+ region : null ,
172+ workloadType : "CONTAINER" ,
173+ hidden : false ,
174+ enableFastPath : false ,
175+ type : "MANAGED" ,
176+ projectId : null ,
177+ } ,
178+ ] )
179+ ) . toBe ( "eu-west-1:v2:ondemand:fresh:container:stable" ) ;
180+ } ) ;
181+ it ( "returns undefined for a v2 compute queue in a region with no container group" , ( ) => {
182+ expect (
183+ containerQueueForComputeQueue ( "ap-1:v2:ondemand:fresh:compute:stable" , groups )
184+ ) . toBeUndefined ( ) ;
185+ } ) ;
186+ it ( "moves a v2 queue that any runtime can take to containers" , ( ) => {
187+ expect ( containerQueueForComputeQueue ( "us-east-1:v2:ondemand:fresh:any:stable" , groups ) ) . toBe (
188+ "us-east-1:v2:ondemand:fresh:container:stable"
189+ ) ;
190+ } ) ;
191+ it ( "returns undefined for a v2 container queue" , ( ) => {
192+ expect (
193+ containerQueueForComputeQueue ( "us-east-1:v2:ondemand:fresh:container:stable" , groups )
194+ ) . toBeUndefined ( ) ;
195+ } ) ;
196+ } ) ;
197+
198+ describe ( "containerQueueForComputeQueue with project-scoped groups" , ( ) => {
199+ const scoped = (
200+ type : "MANAGED" | "UNMANAGED" ,
201+ projectId : string | null
202+ ) : WorkerGroupRegionRow => ( {
203+ masterQueue : "proj_1-us-east-1" ,
204+ region : "us-east-1" ,
205+ workloadType : "CONTAINER" ,
206+ hidden : false ,
207+ enableFastPath : false ,
208+ type,
209+ projectId,
210+ } ) ;
211+ const microvm : WorkerGroupRegionRow = {
212+ masterQueue : "us-east-1-next" ,
213+ region : "us-east-1" ,
214+ workloadType : "MICROVM" ,
215+ hidden : false ,
216+ enableFastPath : true ,
217+ type : "MANAGED" ,
218+ projectId : null ,
219+ } ;
220+
221+ for ( const [ name , group ] of [
222+ [ "an UNMANAGED group" , scoped ( "UNMANAGED" , "proj_1" ) ] ,
223+ [ "another project's MANAGED group" , scoped ( "MANAGED" , "proj_1" ) ] ,
224+ ] as const ) {
225+ it ( `never picks ${ name } for a legacy queue` , ( ) => {
226+ expect ( containerQueueForComputeQueue ( "us-east-1-next" , [ microvm , group ] ) ) . toBeUndefined ( ) ;
227+ } ) ;
228+ it ( `never picks ${ name } for a v2 queue` , ( ) => {
229+ expect (
230+ containerQueueForComputeQueue ( "us-east-1:v2:ondemand:fresh:compute:stable" , [
231+ microvm ,
232+ group ,
233+ ] )
234+ ) . toBeUndefined ( ) ;
235+ } ) ;
236+ it ( `never picks ${ name } that has no region for a v2 queue` , ( ) => {
237+ expect (
238+ containerQueueForComputeQueue ( "proj_1-us-east-1:v2:ondemand:fresh:compute:stable" , [
239+ { ...group , region : null } ,
240+ ] )
241+ ) . toBeUndefined ( ) ;
242+ } ) ;
243+ }
244+
245+ it ( "picks the shared group when a scoped one is also in the region" , ( ) => {
246+ const shared : WorkerGroupRegionRow = { ...scoped ( "MANAGED" , null ) , masterQueue : "us-east-1" } ;
247+ expect (
248+ containerQueueForComputeQueue ( "us-east-1-next" , [
249+ scoped ( "UNMANAGED" , "proj_1" ) ,
250+ microvm ,
251+ shared ,
252+ ] )
253+ ) . toBe ( "us-east-1" ) ;
254+ } ) ;
255+ } ) ;
0 commit comments