breaker_test.go 430 B

123456789101112131415161718192021222324
  1. package collector
  2. import (
  3. "fmt"
  4. "testing"
  5. "go-common/app/service/main/dapper/model"
  6. )
  7. func TestServiceBreaker(t *testing.T) {
  8. breaker := NewServiceBreakerProcess(10)
  9. for i := 0; i < 20; i++ {
  10. err := breaker.Process(&model.Span{ServiceName: "test", OperationName: fmt.Sprintf("opt_%d", i)})
  11. if i < 10 {
  12. if err != nil {
  13. t.Error(err)
  14. }
  15. } else {
  16. if err == nil {
  17. t.Error("expect breaked")
  18. }
  19. }
  20. }
  21. }