limit resources results to 20
This commit is contained in:
parent
197c411767
commit
5192dacf85
|
@ -13,7 +13,6 @@ type Resources struct {
|
|||
// List is used to list the jobs registered in the system
|
||||
// TODO logic to determine context, to return only that context if needed
|
||||
// TODO if no context, return all
|
||||
// TODO return top n matches
|
||||
// TODO refactor to prevent duplication
|
||||
func (r *Resources) List(args *structs.ResourcesRequest,
|
||||
reply *structs.ResourcesResponse) error {
|
||||
|
@ -36,7 +35,7 @@ func (r *Resources) List(args *structs.ResourcesRequest,
|
|||
}
|
||||
|
||||
var jobs []string
|
||||
for {
|
||||
for i := 0; i < 20; i++ {
|
||||
raw := iter.Next()
|
||||
if raw == nil {
|
||||
break
|
||||
|
|
|
@ -39,7 +39,7 @@ func TestResourcesEndpoint_List(t *testing.T) {
|
|||
jobID := registerAndVerifyJob(s, t, prefix, 0)
|
||||
|
||||
req := &structs.ResourcesRequest{
|
||||
QueryOptions: structs.QueryOptions{Region: "global", Prefix: jobID},
|
||||
QueryOptions: structs.QueryOptions{Region: "global", Prefix: prefix},
|
||||
}
|
||||
|
||||
var resp structs.ResourcesResponse
|
||||
|
@ -54,3 +54,34 @@ func TestResourcesEndpoint_List(t *testing.T) {
|
|||
|
||||
assert.Equal(t, jobID, resp.Resources.Matches["jobs"][0])
|
||||
}
|
||||
|
||||
func TestResourcesEndpoint_List_ShouldTruncateResultsToUnder20(t *testing.T) {
|
||||
prefix := "aaaaaaaa-e8f7-fd38-c855-ab94ceb8970"
|
||||
|
||||
t.Parallel()
|
||||
s := testServer(t, func(c *Config) {
|
||||
c.NumSchedulers = 0 // Prevent automatic dequeue
|
||||
})
|
||||
|
||||
defer s.Shutdown()
|
||||
codec := rpcClient(t, s)
|
||||
testutil.WaitForLeader(t, s.RPC)
|
||||
|
||||
for counter := 0; counter < 25; counter++ {
|
||||
registerAndVerifyJob(s, t, prefix, counter)
|
||||
}
|
||||
|
||||
req := &structs.ResourcesRequest{
|
||||
QueryOptions: structs.QueryOptions{Region: "global", Prefix: prefix},
|
||||
}
|
||||
|
||||
var resp structs.ResourcesResponse
|
||||
if err := msgpackrpc.CallWithCodec(codec, "Resources.List", req, &resp); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
num_matches := len(resp.Resources.Matches["jobs"])
|
||||
if num_matches != 20 {
|
||||
t.Fatalf(fmt.Sprintf("err: the number of jobs expected %d does not match the number of jobs returned %d", 20, num_matches))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue