-
Notifications
You must be signed in to change notification settings - Fork 698
[apiserver] ListAllServices with pagination #3490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 11 commits
dbad35d
c51babb
17f1e9a
e8b2af4
4909ecc
ccf46e1
db4211c
4455c0f
5ca1ca1
b301cd2
c309510
17dad98
f125607
836a9b1
49dc3b9
9ff305a
bf9f67d
5e29a93
d6694bd
b73f747
9d6f938
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -216,7 +216,7 @@ func TestGetAllServices(t *testing.T) { | |
| tCtx.DeleteRayService(t, testServiceRequest.Service.Name) | ||
| }) | ||
|
|
||
| response, actualRPCStatus, err := tCtx.GetRayAPIServerClient().ListAllRayServices() | ||
| response, actualRPCStatus, err := tCtx.GetRayAPIServerClient().ListAllRayServices(&api.ListAllRayServicesRequest{}) | ||
| require.NoError(t, err, "No error expected") | ||
| require.Nil(t, actualRPCStatus, "No RPC status expected") | ||
| require.NotNil(t, response, "A response is expected") | ||
|
|
@@ -225,6 +225,125 @@ func TestGetAllServices(t *testing.T) { | |
| require.Equal(t, tCtx.GetNamespaceName(), response.Services[0].Namespace) | ||
| } | ||
|
|
||
| func TestGetAllServicesWithPagination(t *testing.T) { | ||
| const numberOfNamespaces = 3 | ||
| const numberOfService = 2 | ||
| const totalServices = numberOfNamespaces * numberOfService | ||
|
|
||
| type targetService struct { | ||
| namespace string | ||
| service string | ||
| } | ||
|
|
||
| tCtxs := make([]*End2EndTestingContext, 0, numberOfNamespaces) | ||
| expectedServices := make([]targetService, 0, totalServices) | ||
|
|
||
| // Create services for each namespace | ||
| for i := 0; i < numberOfNamespaces; i++ { | ||
| tCtx, err := NewEnd2EndTestingContext(t) | ||
| require.NoError(t, err, "No error expected when creating testing context") | ||
|
|
||
| tCtx.CreateComputeTemplate(t) | ||
| t.Cleanup(func() { | ||
| tCtx.DeleteComputeTemplate(t) | ||
| }) | ||
|
|
||
| for j := 0; j < numberOfService; j++ { | ||
| testServiceRequest := createTestServiceV2(t, tCtx) | ||
| t.Cleanup(func() { | ||
| tCtx.DeleteRayService(t, testServiceRequest.Service.Name) | ||
| }) | ||
| expectedServices = append(expectedServices, targetService{ | ||
| namespace: tCtx.GetNamespaceName(), | ||
| service: testServiceRequest.Service.Name, | ||
| }) | ||
| } | ||
|
|
||
| tCtxs = append(tCtxs, tCtx) | ||
| } | ||
|
|
||
| var pageToken string | ||
| tCtx := tCtxs[0] | ||
| // Test pagination with limit 1, which is less than the total number of services in all namespaces. | ||
| t.Run("Test pagination return part of the result services", func(t *testing.T) { | ||
| pageToken = "" | ||
| gotServices := make(map[targetService]bool, totalServices) | ||
| for _, expectedService := range expectedServices { | ||
| gotServices[expectedService] = false | ||
| } | ||
|
|
||
| for i := 0; i < totalServices; i++ { | ||
| response, actualRPCStatus, err := tCtx.GetRayAPIServerClient().ListAllRayServices(&api.ListAllRayServicesRequest{ | ||
| PageToken: pageToken, | ||
| PageSize: int32(1), | ||
| }) | ||
| require.NoError(t, err, "No error expected") | ||
| require.Nil(t, actualRPCStatus, "No RPC status expected") | ||
| require.NotNil(t, response, "A response is expected") | ||
| require.NotEmpty(t, response.Services, "A list of service is required") | ||
| require.Len(t, response.Services, 1) | ||
|
|
||
| pageToken = response.NextPageToken | ||
| if i == totalServices-1 { | ||
dentiny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| require.Empty(t, pageToken, "No continue token is expected") | ||
| } else { | ||
| require.NotEmpty(t, pageToken, "A continue token is expected") | ||
| } | ||
|
|
||
| for _, service := range response.Services { | ||
| gotServices[targetService{ | ||
|
||
| namespace: service.Namespace, | ||
| service: service.Name, | ||
| }] = true | ||
| } | ||
| } | ||
|
|
||
| // Check all services were found | ||
| for _, expectedService := range expectedServices { | ||
| if !gotServices[expectedService] { | ||
| t.Errorf("ListAllRayServices did not return expected service %s from namespace %s", | ||
|
||
| expectedService.service, expectedService.namespace) | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| // Test pagination with limit 7, which is larger than the total number of services in all namespaces. | ||
|
||
| t.Run("Test pagination return all result services", func(t *testing.T) { | ||
| pageToken = "" | ||
| gotServices := make(map[targetService]bool, totalServices) | ||
| for _, expectedService := range expectedServices { | ||
| gotServices[expectedService] = false | ||
| } | ||
|
|
||
| response, actualRPCStatus, err := tCtx.GetRayAPIServerClient().ListAllRayServices(&api.ListAllRayServicesRequest{ | ||
| PageToken: pageToken, | ||
| PageSize: int32(totalServices + 1), | ||
| }) | ||
|
|
||
| require.NoError(t, err, "No error expected") | ||
| require.Nil(t, actualRPCStatus, "No RPC status expected") | ||
| require.NotNil(t, response, "A response is expected") | ||
| require.NotEmpty(t, response.Services, "A list of services is required") | ||
| require.Len(t, response.Services, totalServices) | ||
| require.Empty(t, response.NextPageToken, "Page token should be empty") | ||
|
|
||
| for _, service := range response.Services { | ||
| gotServices[targetService{ | ||
|
||
| namespace: service.Namespace, | ||
| service: service.Name, | ||
| }] = true | ||
| } | ||
|
|
||
| // Check all services were found | ||
| for _, expectedService := range expectedServices { | ||
| if !gotServices[expectedService] { | ||
| t.Errorf("ListAllRayServices did not return expected service %s from namespace %s", | ||
|
||
| expectedService.service, expectedService.namespace) | ||
| } | ||
| } | ||
| }) | ||
| } | ||
dentiny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| func TestGetServicesInNamespace(t *testing.T) { | ||
| tCtx, err := NewEnd2EndTestingContext(t) | ||
| require.NoError(t, err, "No error expected when creating testing context") | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: print service content or size for debugging purpose