mirror of https://github.com/prometheus/prometheus
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
1.3 KiB
78 lines
1.3 KiB
12 years ago
|
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")
|
||
|
}
|
||
|
}
|