counter_test.go 679 B

12345678910111213141516171819202122232425262728293031
  1. package stats_test
  2. import (
  3. "context"
  4. "testing"
  5. . "github.com/v2fly/v2ray-core/v4/app/stats"
  6. "github.com/v2fly/v2ray-core/v4/common"
  7. "github.com/v2fly/v2ray-core/v4/features/stats"
  8. )
  9. func TestStatsCounter(t *testing.T) {
  10. raw, err := common.CreateObject(context.Background(), &Config{})
  11. common.Must(err)
  12. m := raw.(stats.Manager)
  13. c, err := m.RegisterCounter("test.counter")
  14. common.Must(err)
  15. if v := c.Add(1); v != 1 {
  16. t.Fatal("unpexcted Add(1) return: ", v, ", wanted ", 1)
  17. }
  18. if v := c.Set(0); v != 1 {
  19. t.Fatal("unexpected Set(0) return: ", v, ", wanted ", 1)
  20. }
  21. if v := c.Value(); v != 0 {
  22. t.Fatal("unexpected Value() return: ", v, ", wanted ", 0)
  23. }
  24. }