job names causes errors when searching other contexts, only log but not return this err

This commit is contained in:
Chelsea Holland Komlo 2017-08-15 17:43:50 +00:00
parent 95c68156bc
commit 74c51e63bd
2 changed files with 43 additions and 3 deletions

View File

@ -120,10 +120,14 @@ func (s *Search) PrefixSearch(args *structs.SearchRequest,
for _, ctx := range contexts {
iter, err := getResourceIter(ctx, roundUUIDDownIfOdd(args.Prefix, args.Context), ws, state)
// When searching all Contexts, Job ids will cause errors when searched
// in the context of allocs, nodes, and/or evals.
if err != nil {
return err
s.srv.logger.Printf("[WARN] nomad.resources: error when searching context %s for id %s", ctx, args.Prefix)
} else {
iters[ctx] = iter
}
iters[ctx] = iter
}
// Return matches for the given prefix

View File

@ -25,7 +25,7 @@ func registerAndVerifyJob(s *Server, t *testing.T, prefix string, counter int) s
return job.ID
}
func TestSearch_PrefixSearch(t *testing.T) {
func TestSearch_PrefixSearch_Job(t *testing.T) {
assert := assert.New(t)
prefix := "aaaaaaaa-e8f7-fd38-c855-ab94ceb8970"
@ -88,6 +88,42 @@ func TestSearch_PrefixSearch_Truncate(t *testing.T) {
assert.Equal(uint64(jobIndex), resp.Index)
}
func TestSearch_PrefixSearch_AllWithJob(t *testing.T) {
assert := assert.New(t)
prefix := "aaaaaaaa-e8f7-fd38-c855-ab94ceb8970"
t.Parallel()
s := testServer(t, func(c *Config) {
c.NumSchedulers = 0
})
defer s.Shutdown()
codec := rpcClient(t, s)
testutil.WaitForLeader(t, s.RPC)
jobID := registerAndVerifyJob(s, t, prefix, 0)
eval1 := mock.Eval()
eval1.ID = jobID
s.fsm.State().UpsertEvals(2000, []*structs.Evaluation{eval1})
req := &structs.SearchRequest{
Prefix: prefix,
Context: structs.All,
}
var resp structs.SearchResponse
if err := msgpackrpc.CallWithCodec(codec, "Search.PrefixSearch", req, &resp); err != nil {
t.Fatalf("err: %v", err)
}
assert.Equal(1, len(resp.Matches[structs.Jobs]))
assert.Equal(jobID, resp.Matches[structs.Jobs][0])
assert.Equal(1, len(resp.Matches[structs.Evals]))
assert.Equal(eval1.ID, resp.Matches[structs.Evals][0])
}
func TestSearch_PrefixSearch_Evals(t *testing.T) {
assert := assert.New(t)
t.Parallel()