Permalink
Browse files

client: add support and fix tests

  • Loading branch information...
1 parent 7643da8 commit 6190476e7fb08eae42fe33f2ba74573566ce88d5 @suyash suyash committed Aug 9, 2016
Showing with 44 additions and 4 deletions.
  1. +5 −0 client.go
  2. +39 −4 client_test.go
View
@@ -477,6 +477,11 @@ func (c *PCPClient) writeMetrics() {
c.writeInstanceMetric(metric)
wg.Done()
}(metric)
+ case *PCPCounter:
+ go func(metric *PCPCounter) {
+ c.writeSingletonMetric(metric.PCPSingletonMetric)
+ wg.Done()
+ }(metric)
}
}
View
@@ -845,7 +845,7 @@ func TestMMV2InstanceWriting(t *testing.T) {
}
func TestCounter(t *testing.T) {
- c, err := NewPCPClient("test", ProcessFlag)
+ c, err := NewPCPClient("test")
if err != nil {
t.Errorf("cannot create client, error: %v", err)
}
@@ -860,12 +860,47 @@ func TestCounter(t *testing.T) {
c.MustStart()
defer c.MustStop()
- _, _, metrics, values, _, _, _, err := mmvdump.Dump(c.buffer.Bytes())
+ _, _, metrics, values, _, _, strings, err := mmvdump.Dump(c.writer.Bytes())
if err != nil {
t.Errorf("cannot get dump: %v", err)
return
}
- matchMetricsAndValues(metrics, values, c, t)
-}
+ matchMetricsAndValues(metrics, values, strings, c, t)
+
+ m.Up()
+
+ _, _, metrics, values, _, _, _, err = mmvdump.Dump(c.writer.Bytes())
+
+ off, _ := findMetric(m, metrics)
+ _, v := findValue(off, values)
+
+ if val, _ := mmvdump.FixedVal(v.Val, mmvdump.Int64Type); val != int64(1) {
+ t.Errorf("expected counter to be 1 after Up(), got %v", val)
+ }
+
+ m.MustInc(9)
+
+ _, _, metrics, values, _, _, _, err = mmvdump.Dump(c.writer.Bytes())
+ off, _ = findMetric(m, metrics)
+ _, v = findValue(off, values)
+
+ if val, _ := mmvdump.FixedVal(v.Val, mmvdump.Int64Type); val != int64(10) {
+ t.Errorf("expected counter to be 10 after Set(10), got %v", val)
+ }
+
+ err = m.Inc(-9)
+ if err == nil {
+ t.Errorf("expected decrementing a counter to generate an error")
+ }
+
+ _, _, metrics, values, _, _, _, err = mmvdump.Dump(c.writer.Bytes())
+
+ off, _ = findMetric(m, metrics)
+ _, v = findValue(off, values)
+
+ if val, _ := mmvdump.FixedVal(v.Val, mmvdump.Int64Type); val != int64(10) {
+ t.Errorf("expected counter to stay at 10 after Set(-9), got %v", val)
+ }
+}

0 comments on commit 6190476

Please sign in to comment.