metrics_test.go 671 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package stat
  2. import (
  3. "strconv"
  4. "testing"
  5. "time"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestMetrics(t *testing.T) {
  9. counts := []int{1, 5, 10, 100, 1000, 1000}
  10. for _, count := range counts {
  11. m := NewMetrics("foo")
  12. m.SetName("bar")
  13. for i := 0; i < count; i++ {
  14. m.Add(Task{
  15. Duration: time.Millisecond * time.Duration(i),
  16. Description: strconv.Itoa(i),
  17. })
  18. }
  19. m.AddDrop()
  20. var writer mockedWriter
  21. SetReportWriter(&writer)
  22. m.executor.Flush()
  23. assert.Equal(t, "bar", writer.report.Name)
  24. }
  25. }
  26. type mockedWriter struct {
  27. report *StatReport
  28. }
  29. func (m *mockedWriter) Write(report *StatReport) error {
  30. m.report = report
  31. return nil
  32. }