Skip to content

Commit

Permalink
Merge pull request #215 from signalfx/gendims
Browse files Browse the repository at this point in the history
Update dptest to copy dims so fewer data races
  • Loading branch information
mdubbyap authored Feb 25, 2021
2 parents d500531 + ffbeb0b commit 317e4fe
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion datapoint/dptest/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,19 @@ func init() {
globalSpanSource.Name = "test-span"
}

func copyMap(in map[string]string) map[string]string {
ret := make(map[string]string, len(in))
for k, v := range in {
ret[k] = v
}
return ret
}

// Next returns a unique datapoint
func (d *DatapointSource) Next() *datapoint.Datapoint {
d.mu.Lock()
defer d.mu.Unlock()
return datapoint.New(d.Metric+":"+strconv.FormatInt(atomic.AddInt64(&d.CurrentIndex, 1), 10), d.Dims, datapoint.NewIntValue(0), d.Dptype, d.TimeSource())
return datapoint.New(d.Metric+":"+strconv.FormatInt(atomic.AddInt64(&d.CurrentIndex, 1), 10), copyMap(d.Dims), datapoint.NewIntValue(0), d.Dptype, d.TimeSource())
}

// DP generates and returns a unique datapoint to use for testing purposes
Expand Down

0 comments on commit 317e4fe

Please sign in to comment.