@@ -253,6 +253,107 @@ func TestGetServicesInNamespace(t *testing.T) {
253
253
require .Equal (t , tCtx .GetNamespaceName (), response .Services [0 ].Namespace )
254
254
}
255
255
256
+ func TestGetServicesInNamespaceWithPagination (t * testing.T ) {
257
+ const serviceCount = 2
258
+ expectedServiceNames := make ([]string , 0 , serviceCount )
259
+
260
+ tCtx , err := NewEnd2EndTestingContext (t )
261
+ require .NoError (t , err , "No error expected when creating testing context" )
262
+
263
+ tCtx .CreateComputeTemplate (t )
264
+ t .Cleanup (func () {
265
+ tCtx .DeleteComputeTemplate (t )
266
+ })
267
+
268
+ for ii := 0 ; ii < serviceCount ; ii ++ {
269
+ testServiceRequest := createTestServiceV2 (t , tCtx )
270
+ t .Cleanup (func () {
271
+ tCtx .DeleteRayService (t , testServiceRequest .Service .Name )
272
+ })
273
+ expectedServiceNames = append (expectedServiceNames , testServiceRequest .Service .Name )
274
+ }
275
+
276
+ // Test pagination with limit 1, which is less than the total number of services.
277
+ t .Run ("Test pagination return part of the result services" , func (t * testing.T ) {
278
+ // Used to check all services have been returned.
279
+ gotServices := []bool {false , false }
280
+
281
+ pageToken := ""
282
+ for ii := 0 ; ii < serviceCount ; ii ++ {
283
+ response , actualRPCStatus , err := tCtx .GetRayAPIServerClient ().ListRayServices (& api.ListRayServicesRequest {
284
+ Namespace : tCtx .GetNamespaceName (),
285
+ PageToken : pageToken ,
286
+ PageSize : int32 (1 ),
287
+ })
288
+
289
+ require .NoError (t , err , "No error expected" )
290
+ require .Nil (t , actualRPCStatus , "No RPC status expected" )
291
+ require .NotNil (t , response , "A response is expected" )
292
+ require .NotEmpty (t , response .Services , "A list of service is required" )
293
+ require .Len (t , response .Services , 1 )
294
+
295
+ for _ , curService := range response .Services {
296
+ for jj := 0 ; jj < serviceCount ; jj ++ {
297
+ if expectedServiceNames [jj ] == curService .Name {
298
+ gotServices [jj ] = true
299
+ break
300
+ }
301
+ }
302
+ }
303
+
304
+ // Check next page token.
305
+ pageToken = response .NextPageToken
306
+ if ii == serviceCount - 1 {
307
+ require .Empty (t , pageToken , "Last page token should be empty" )
308
+ } else {
309
+ require .NotEmpty (t , pageToken , "Non-last page token should be non empty" )
310
+ }
311
+ }
312
+
313
+ // Check all services created have been returned.
314
+ for idx := 0 ; idx < serviceCount ; idx ++ {
315
+ if ! gotServices [idx ] {
316
+ t .Errorf ("ListServices did not return expected services %s" , expectedServiceNames [idx ])
317
+ }
318
+ }
319
+ })
320
+
321
+ // Test pagination with limit 3, which is larger than the total number of services.
322
+ t .Run ("Test pagination return all result services" , func (t * testing.T ) {
323
+ // Used to check all services have been returned.
324
+ gotServices := []bool {false , false }
325
+
326
+ pageToken := ""
327
+ response , actualRPCStatus , err := tCtx .GetRayAPIServerClient ().ListRayServices (& api.ListRayServicesRequest {
328
+ Namespace : tCtx .GetNamespaceName (),
329
+ PageToken : pageToken ,
330
+ PageSize : serviceCount + 1 ,
331
+ })
332
+
333
+ require .NoError (t , err , "No error expected" )
334
+ require .Nil (t , actualRPCStatus , "No RPC status expected" )
335
+ require .NotNil (t , response , "A response is expected" )
336
+ require .NotEmpty (t , response .Services , "A list of services is required" )
337
+ require .Len (t , response .Services , serviceCount )
338
+ require .Empty (t , pageToken , "Page token should be empty" )
339
+ for _ , curService := range response .Services {
340
+ for jj := 0 ; jj < serviceCount ; jj ++ {
341
+ if expectedServiceNames [jj ] == curService .Name {
342
+ gotServices [jj ] = true
343
+ break
344
+ }
345
+ }
346
+ }
347
+
348
+ // Check all services created have been returned.
349
+ for idx := 0 ; idx < serviceCount ; idx ++ {
350
+ if ! gotServices [idx ] {
351
+ t .Errorf ("ListServices did not return expected services %s" , expectedServiceNames [idx ])
352
+ }
353
+ }
354
+ })
355
+ }
356
+
256
357
func TestGetService (t * testing.T ) {
257
358
tCtx , err := NewEnd2EndTestingContext (t )
258
359
require .NoError (t , err , "No error expected when creating testing context" )
@@ -366,9 +467,7 @@ func createTestServiceV2(t *testing.T, tCtx *End2EndTestingContext) *api.CreateR
366
467
require .NoError (t , err , "No error expected" )
367
468
require .Nil (t , actualRPCStatus , "No RPC status expected" )
368
469
require .NotNil (t , actualService , "A service is expected" )
369
-
370
470
checkRayServiceCreatedSuccessfully (t , tCtx , actualService .Name )
371
-
372
471
return testServiceRequest
373
472
}
374
473
0 commit comments