From 23be9380f51de9d8b3dffe588da41ce628706c9e Mon Sep 17 00:00:00 2001 From: Jon Seymour Date: Wed, 17 Feb 2016 16:58:21 +1100 Subject: [PATCH] This test illustrates a problem with Points.newFieldsFromBinary. Prior to #5697 it causes a panic, after #5697 it causes an infinite loop Signed-off-by: Jon Seymour --- models/points_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/models/points_test.go b/models/points_test.go index db3065ae338..c3b33717c2f 100644 --- a/models/points_test.go +++ b/models/points_test.go @@ -1772,3 +1772,21 @@ t159,label=another a=2i,value=1i 1` t.Fatalf("expected 2 points, got %d", len(points)) } } + +func TestAddFieldWithEmptyName(t *testing.T) { + ch := make(chan struct{}) + go func() { + p, err := models.NewPoint("foo", nil, models.Fields{"a": 1}, time.Now()) + if err != nil { + t.Fatalf("%v", err) + } + p.AddField("", 2) + p.AddField("b", 3) // causes infinite loop in newFieldsFromBinary + close(ch) + }() + select { + case _ = <-ch: + case _ = <-time.NewTimer(time.Second).C: + t.Fatalf("failed: probable infite loop") + } +}