[apiserver] ListAllServices with pagination#3490
[apiserver] ListAllServices with pagination#3490kevin85421 merged 21 commits intoray-project:masterfrom
Conversation
|
Feel free to ping me when ready to review :) |
| } | ||
|
|
||
| func createOneServiceInEachNamespace(t *testing.T, numberOfNamespaces int) ([]*End2EndTestingContext, []string) { | ||
| tCtxs := make([]*End2EndTestingContext, numberOfNamespaces) |
There was a problem hiding this comment.
nit: can we unify the same array creation pattern? I think it's easy to get wrong.
There was a problem hiding this comment.
Fixed in the latest push.
The array creation pattern is now unified using make([]T, 0, cap)
| tCtx.DeleteComputeTemplate(t) | ||
| }) | ||
|
|
||
| expectedServiceNames[i] = make([]string, 0, numberOfService) |
There was a problem hiding this comment.
nit: as I suggested last time, I would appreciate if we could keep consistency for array usage.
| const totalServices = numberOfNamespaces * numberOfService | ||
|
|
||
| tCtxs := make([]*End2EndTestingContext, numberOfNamespaces) | ||
| expectedServiceNames := make([][]string, numberOfNamespaces) |
There was a problem hiding this comment.
suggest to add some comments for the 2d array, not easy to figure out at first glance
There was a problem hiding this comment.
I think the two-level for loop and 2d array is a little hard to understand, would it be better if we store an array of a struct
type targetSvc struct {
namespace string
svc string
}There was a problem hiding this comment.
Thanks for your suggestion! I’ve updated it in the latest fix.
| t.Run("Test pagination return part of the result services", func(t *testing.T) { | ||
| pageToken = "" | ||
| gotServices := make([][]bool, numberOfNamespaces) | ||
| for i := 0; i < numberOfNamespaces; i++ { |
There was a problem hiding this comment.
suggest to add some comments for the 2d array, not easy to figure out at first glance
| if service.Namespace == ctx.GetNamespaceName() && | ||
| service.Name == expectedServiceNames[namespaceIdx][serviceIdx] { | ||
| gotServices[namespaceIdx][serviceIdx] = true | ||
| break |
There was a problem hiding this comment.
break only breaks out on loop, so even after the target service is found, you still go extra unnecessary for loop (external loop); what about we use a found boolean.
| // 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) |
There was a problem hiding this comment.
this is bug, you need to initialize all possibility with false
There was a problem hiding this comment.
otherwise L300 always gets true
There was a problem hiding this comment.
@dentiny Thanks for catching that. It has been fixed and it is ready to be reviewed.
|
ping me when ready :) |
f4d121c to
67981e3
Compare
Signed-off-by: Tina Wu <j6vupz97@gmail.com>
Signed-off-by: Tina Wu <j6vupz97@gmail.com>
Signed-off-by: Tina Wu <j6vupz97@gmail.com>
Signed-off-by: Tina Wu <j6vupz97@gmail.com>
Signed-off-by: Tina Wu <j6vupz97@gmail.com>
Signed-off-by: Tina Wu <j6vupz97@gmail.com>
67981e3 to
5ca1ca1
Compare
Signed-off-by: Tina <j6vupz97@gmail.com>
| 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) |
There was a problem hiding this comment.
nit: print service content or size for debugging purpose
| } | ||
| }) | ||
|
|
||
| // Test pagination with limit 7, which is larger than the total number of services in all namespaces. |
There was a problem hiding this comment.
nitpick: I suggest to drop the detailed number (7 here), because it could be changed in the future, which adds maintenance overhead.
| require.Empty(t, response.NextPageToken, "Page token should be empty") | ||
|
|
||
| for _, service := range response.Services { | ||
| gotServices[targetService{ |
There was a problem hiding this comment.
sorry there's bug here, you need to check whether the key exist in the gotServices also
| } | ||
|
|
||
| for _, service := range response.Services { | ||
| gotServices[targetService{ |
There was a problem hiding this comment.
same here, you need to check service existence
Signed-off-by: Tina <j6vupz97@gmail.com>
Signed-off-by: Tina <j6vupz97@gmail.com>
Signed-off-by: Tina <j6vupz97@gmail.com>
Signed-off-by: Tina <j6vupz97@gmail.com>
|
Test failed, could you please take a look? @tinaxfwu |
Signed-off-by: Tina Wu <j6vupz97@gmail.com>
| // Check all services were found | ||
| for _, expectedService := range expectedServices { | ||
| if !gotServices[expectedService] { | ||
| t.Errorf("ListAllRayServices did not return expected service %s from namespace %s", |
There was a problem hiding this comment.
Two things,
- You use multiple styles to assert in the test,
t.Errorf,t.Fatalfandrequire, can we unify them into one? t.Errorfdoesn't look like a valid assertion
I would suggest use require or assert everywhere
There was a problem hiding this comment.
I have replaced t.Errorf and t.Fatalf with require in both TestGetServicesInNamespaceWithPagination and TestGetAllServicesWithPagination.
| // Check all services were found | ||
| for _, expectedService := range expectedServices { | ||
| if !gotServices[expectedService] { | ||
| t.Errorf("ListAllRayServices did not return expected service %s from namespace %s", |
Signed-off-by: Tina Wu <j6vupz97@gmail.com>
Signed-off-by: Tina Wu <j6vupz97@gmail.com>
|
Feel free to ping me when ready thanks |
Signed-off-by: Tina Wu <j6vupz97@gmail.com>
| 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) | ||
| t.Logf("Got %d services in response, expected %d", len(response.Services), 1) |
There was a problem hiding this comment.
what's the purpose for this logging?
There was a problem hiding this comment.
You left a nit comment earlier about
printing service content or size for debugging purpose. So I add this line to log the size of services received.
There was a problem hiding this comment.
Sorry for the confusion, I mean log when error
| } | ||
|
|
||
| for _, service := range response.Services { | ||
| t.Logf("Got service: namespace=%s, name=%s", service.Namespace, service.Name) |
There was a problem hiding this comment.
same here, what's the purpose of logging?
There was a problem hiding this comment.
I have removed this line, as the information it printed might be too trivial.
| 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") | ||
| t.Logf("Got %d services in response, expected %d", len(response.Services), totalServices) |
Signed-off-by: Tina Wu <j6vupz97@gmail.com>
dentiny
left a comment
There was a problem hiding this comment.
LGTM, thanks for the effort!
Why are these changes needed?
This PR implements pagination for listing all ray services.
ListAllServicesin resource_managerListAllRayServicesin serve_server reusesListAllServicesin resource_managerTestGetAllServicesWithPaginationis added to validate the functionality.Related issue number
Closes #3289
Checks