mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 05:34:05 -08:00
561974308d
The curator requires the existence of a curator remark table, which stores the progress for a given curation policy. The tests for the curator create an ad hoc table, but core Prometheus presently lacks said table, which this commit adds. Secondarily, the error handling for the LevelDB lifecycle functions in the metric persistence have been wrapped into an UncertaintyGroup, which mirrors some of the functions of sync.WaitGroup but adds error capturing capability to the mix.
78 lines
1.3 KiB
Go
78 lines
1.3 KiB
Go
package utility
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestGroupSuccess(t *testing.T) {
|
|
uncertaintyGroup := NewUncertaintyGroup(10)
|
|
|
|
for i := 0; i < 10; i++ {
|
|
go uncertaintyGroup.Succeed()
|
|
}
|
|
|
|
result := make(chan bool)
|
|
go func() {
|
|
result <- uncertaintyGroup.Wait()
|
|
}()
|
|
select {
|
|
case v := <-result:
|
|
if !v {
|
|
t.Fatal("expected success")
|
|
}
|
|
case <-time.After(time.Second):
|
|
t.Fatal("deadline exceeded")
|
|
}
|
|
}
|
|
|
|
func TestGroupFail(t *testing.T) {
|
|
uncertaintyGroup := NewUncertaintyGroup(10)
|
|
|
|
for i := 0; i < 10; i++ {
|
|
go uncertaintyGroup.Fail(fmt.Errorf(""))
|
|
}
|
|
|
|
result := make(chan bool)
|
|
go func() {
|
|
result <- uncertaintyGroup.Wait()
|
|
}()
|
|
select {
|
|
case v := <-result:
|
|
if v {
|
|
t.Fatal("expected failure")
|
|
}
|
|
case <-time.After(time.Second):
|
|
t.Fatal("deadline exceeded")
|
|
}
|
|
}
|
|
|
|
func TestGroupFailMix(t *testing.T) {
|
|
uncertaintyGroup := NewUncertaintyGroup(10)
|
|
|
|
for i := 0; i < 10; i++ {
|
|
go func(i int) {
|
|
switch {
|
|
case i%2 == 0:
|
|
uncertaintyGroup.Fail(fmt.Errorf(""))
|
|
default:
|
|
uncertaintyGroup.Succeed()
|
|
}
|
|
}(i)
|
|
}
|
|
|
|
result := make(chan bool)
|
|
go func() {
|
|
result <- uncertaintyGroup.Wait()
|
|
}()
|
|
select {
|
|
case v := <-result:
|
|
if v {
|
|
t.Fatal("expected failure")
|
|
}
|
|
case <-time.After(time.Second):
|
|
t.Fatal("deadline exceeded")
|
|
}
|
|
}
|