diff --git a/nomad/mock/job.go b/nomad/mock/job.go index e6f960304..a40fed67a 100644 --- a/nomad/mock/job.go +++ b/nomad/mock/job.go @@ -568,3 +568,93 @@ func MaxParallelJob() *structs.Job { job.Canonicalize() return job } + +// BigBenchmarkJob creates a job with many fields set, ideal for benchmarking +// stuff involving jobs. +// +// Should not be used outside of benchmarking - folks should feel free to add +// more fields without risk of breaking test cases down the line. +func BigBenchmarkJob() *structs.Job { + job := MultiTaskGroupJob() + + // job affinities + job.Affinities = structs.Affinities{{ + LTarget: "left", + RTarget: "right", + Operand: "!=", + Weight: 100, + }, { + LTarget: "a", + RTarget: "b", + Operand: "<", + Weight: 50, + }} + + // job spreads + job.Spreads = []*structs.Spread{{ + Attribute: "foo.x", + Weight: 100, + SpreadTarget: []*structs.SpreadTarget{{ + Value: "x", + Percent: 90, + }, { + Value: "x2", + Percent: 99, + }}, + }, { + Attribute: "foo.y", + Weight: 90, + SpreadTarget: []*structs.SpreadTarget{{ + Value: "y", + Percent: 10, + }}, + }} + + // group affinities + job.TaskGroups[0].Affinities = structs.Affinities{{ + LTarget: "L", + RTarget: "R", + Operand: "!=", + Weight: 100, + }, { + LTarget: "b", + RTarget: "a", + Operand: ">", + Weight: 50, + }} + + // group spreads + job.TaskGroups[0].Spreads = []*structs.Spread{{ + Attribute: "bar.x", + Weight: 100, + SpreadTarget: []*structs.SpreadTarget{{ + Value: "x", + Percent: 90, + }, { + Value: "x2", + Percent: 99, + }}, + }, { + Attribute: "bar.y", + Weight: 90, + SpreadTarget: []*structs.SpreadTarget{{ + Value: "y", + Percent: 10, + }}, + }} + + // task affinities + job.TaskGroups[0].Tasks[0].Affinities = structs.Affinities{{ + LTarget: "Left", + RTarget: "Right", + Operand: "!=", + Weight: 100, + }, { + LTarget: "A", + RTarget: "B", + Operand: "<", + Weight: 50, + }} + + return job +} diff --git a/scheduler/util_test.go b/scheduler/util_test.go index 8d853f5bc..76ad2b425 100644 --- a/scheduler/util_test.go +++ b/scheduler/util_test.go @@ -17,6 +17,17 @@ import ( "github.com/hashicorp/nomad/nomad/structs" ) +func BenchmarkTasksUpdated(b *testing.B) { + jobA := mock.BigBenchmarkJob() + jobB := jobA.Copy() + group := jobA.TaskGroups[0].Name + for n := 0; n < b.N; n++ { + if tasksUpdated(jobA, jobB, group) { + b.Fatal("tasks should be the same") + } + } +} + func newNode(name string) *structs.Node { n := mock.Node() n.Name = name