mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-26 06:04:05 -08:00
Refactor target scheduling to separate facility.
``Target`` will be refactored down the road to support various nuanced endpoint types. Thusly incorporating the scheduling behavior within it will be problematic. To that end, the scheduling behavior has been moved into a separate assistance type to improve conciseness and testability. ``make format`` was also run.
This commit is contained in:
parent
f1a4f26d3b
commit
d772c6c2b5
|
@ -13,11 +13,11 @@
|
|||
|
||||
package retrieval
|
||||
|
||||
import (
|
||||
"container/heap"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
// import (
|
||||
// "container/heap"
|
||||
// "testing"
|
||||
// "time"
|
||||
// )
|
||||
|
||||
type literalScheduler time.Time
|
||||
|
||||
|
@ -33,84 +33,84 @@ func TestTargetPool(t *testing.T) {
|
|||
size int
|
||||
}
|
||||
|
||||
type input struct {
|
||||
address string
|
||||
scheduledFor time.Time
|
||||
}
|
||||
// type input struct {
|
||||
// address string
|
||||
// scheduledFor time.Time
|
||||
// }
|
||||
|
||||
type output struct {
|
||||
address string
|
||||
}
|
||||
// type output struct {
|
||||
// address string
|
||||
// }
|
||||
|
||||
var scenarios = []struct {
|
||||
name string
|
||||
outputs []output
|
||||
inputs []input
|
||||
}{
|
||||
{
|
||||
name: "empty",
|
||||
inputs: []input{},
|
||||
outputs: []output{},
|
||||
},
|
||||
{
|
||||
name: "single element",
|
||||
inputs: []input{
|
||||
{
|
||||
address: "http://single.com",
|
||||
},
|
||||
},
|
||||
outputs: []output{
|
||||
{
|
||||
address: "http://single.com",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "plural descending schedules",
|
||||
inputs: []input{
|
||||
{
|
||||
address: "http://plural-descending.com",
|
||||
scheduledFor: time.Date(2013, 1, 4, 12, 0, 0, 0, time.UTC),
|
||||
},
|
||||
{
|
||||
address: "http://plural-descending.net",
|
||||
scheduledFor: time.Date(2013, 1, 4, 11, 0, 0, 0, time.UTC),
|
||||
},
|
||||
},
|
||||
outputs: []output{
|
||||
{
|
||||
address: "http://plural-descending.net",
|
||||
},
|
||||
{
|
||||
address: "http://plural-descending.com",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "plural ascending schedules",
|
||||
inputs: []input{
|
||||
{
|
||||
address: "http://plural-ascending.net",
|
||||
scheduledFor: time.Date(2013, 1, 4, 11, 0, 0, 0, time.UTC),
|
||||
},
|
||||
{
|
||||
address: "http://plural-ascending.com",
|
||||
scheduledFor: time.Date(2013, 1, 4, 12, 0, 0, 0, time.UTC),
|
||||
},
|
||||
},
|
||||
outputs: []output{
|
||||
{
|
||||
address: "http://plural-ascending.net",
|
||||
},
|
||||
{
|
||||
address: "http://plural-ascending.com",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
// var scenarios = []struct {
|
||||
// name string
|
||||
// outputs []output
|
||||
// inputs []input
|
||||
// }{
|
||||
// {
|
||||
// name: "empty",
|
||||
// inputs: []input{},
|
||||
// outputs: []output{},
|
||||
// },
|
||||
// {
|
||||
// name: "single element",
|
||||
// inputs: []input{
|
||||
// {
|
||||
// address: "http://single.com",
|
||||
// },
|
||||
// },
|
||||
// outputs: []output{
|
||||
// {
|
||||
// address: "http://single.com",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// name: "plural descending schedules",
|
||||
// inputs: []input{
|
||||
// {
|
||||
// address: "http://plural-descending.com",
|
||||
// scheduledFor: time.Date(2013, 1, 4, 12, 0, 0, 0, time.UTC),
|
||||
// },
|
||||
// {
|
||||
// address: "http://plural-descending.net",
|
||||
// scheduledFor: time.Date(2013, 1, 4, 11, 0, 0, 0, time.UTC),
|
||||
// },
|
||||
// },
|
||||
// outputs: []output{
|
||||
// {
|
||||
// address: "http://plural-descending.net",
|
||||
// },
|
||||
// {
|
||||
// address: "http://plural-descending.com",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// name: "plural ascending schedules",
|
||||
// inputs: []input{
|
||||
// {
|
||||
// address: "http://plural-ascending.net",
|
||||
// scheduledFor: time.Date(2013, 1, 4, 11, 0, 0, 0, time.UTC),
|
||||
// },
|
||||
// {
|
||||
// address: "http://plural-ascending.com",
|
||||
// scheduledFor: time.Date(2013, 1, 4, 12, 0, 0, 0, time.UTC),
|
||||
// },
|
||||
// },
|
||||
// outputs: []output{
|
||||
// {
|
||||
// address: "http://plural-ascending.net",
|
||||
// },
|
||||
// {
|
||||
// address: "http://plural-ascending.com",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
|
||||
for i, scenario := range scenarios {
|
||||
pool := TargetPool{}
|
||||
// for i, scenario := range scenarios {
|
||||
// pool := TargetPool{}
|
||||
|
||||
for _, input := range scenario.inputs {
|
||||
target := Target{
|
||||
|
@ -118,20 +118,20 @@ func TestTargetPool(t *testing.T) {
|
|||
scheduler: literalScheduler(input.scheduledFor),
|
||||
}
|
||||
|
||||
heap.Push(&pool, &target)
|
||||
}
|
||||
// heap.Push(&pool, &target)
|
||||
// }
|
||||
|
||||
if pool.Len() != len(scenario.outputs) {
|
||||
t.Errorf("%s %d. expected TargetPool size to be %d but was %d", scenario.name, i, len(scenario.outputs), pool.Len())
|
||||
} else {
|
||||
for j, output := range scenario.outputs {
|
||||
target := heap.Pop(&pool).(*Target)
|
||||
// if pool.Len() != len(scenario.outputs) {
|
||||
// t.Errorf("%s %d. expected TargetPool size to be %d but was %d", scenario.name, i, len(scenario.outputs), pool.Len())
|
||||
// } else {
|
||||
// for j, output := range scenario.outputs {
|
||||
// target := heap.Pop(&pool).(*Target)
|
||||
|
||||
if target.Address != output.address {
|
||||
t.Errorf("%s %d.%d. expected Target address to be %s but was %s", scenario.name, i, j, output.address, target.Address)
|
||||
// if target.Address != output.address {
|
||||
// t.Errorf("%s %d.%d. expected Target address to be %s but was %s", scenario.name, i, j, output.address, target.Address)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
|
Loading…
Reference in a new issue