github.com/dkerwin/nomad@v0.3.3-0.20160525181927-74554135514b/nomad/system_endpoint_test.go (about) 1 package nomad 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/hashicorp/net-rpc-msgpackrpc" 8 "github.com/hashicorp/nomad/nomad/mock" 9 "github.com/hashicorp/nomad/nomad/structs" 10 "github.com/hashicorp/nomad/testutil" 11 ) 12 13 func TestSystemEndpoint_GarbageCollect(t *testing.T) { 14 //s1 := testServer(t, func(c *Config) { 15 //c.NumSchedulers = 0 // Prevent automatic dequeue 16 //}) 17 s1 := testServer(t, nil) 18 defer s1.Shutdown() 19 codec := rpcClient(t, s1) 20 testutil.WaitForLeader(t, s1.RPC) 21 22 // Insert a job that can be GC'd 23 state := s1.fsm.State() 24 job := mock.Job() 25 job.Type = structs.JobTypeBatch 26 if err := state.UpsertJob(0, job); err != nil { 27 t.Fatalf("UpsertAllocs() failed: %v", err) 28 } 29 30 // Make the GC request 31 req := &structs.GenericRequest{ 32 QueryOptions: structs.QueryOptions{ 33 Region: "global", 34 }, 35 } 36 var resp structs.GenericResponse 37 if err := msgpackrpc.CallWithCodec(codec, "System.GarbageCollect", req, &resp); err != nil { 38 t.Fatalf("expect err") 39 } 40 41 testutil.WaitForResult(func() (bool, error) { 42 // Check if the job has been GC'd 43 exist, err := state.JobByID(job.ID) 44 if err != nil { 45 return false, err 46 } 47 if exist != nil { 48 return false, fmt.Errorf("job %q wasn't garbage collected", job.ID) 49 } 50 return true, nil 51 }, func(err error) { 52 t.Fatalf("err: %s", err) 53 }) 54 }