Skip to content

Commit

Permalink
Test idempotency
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed Feb 14, 2023
1 parent 367fae6 commit e41fd60
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
5 changes: 2 additions & 3 deletions sdk/metric/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,16 @@ func (p *pipeline) addSync(id instrumentID, scope instrumentation.Scope, iSync i
p.Lock()
defer p.Unlock()
if p.seen == nil {
p.seen = map[instrumentID]struct{}{}
p.seen = make(map[instrumentID]struct{})
} else {
if _, ok := p.seen[id]; ok {
return
}
}
if p.aggregations == nil {
p.aggregations = map[instrumentation.Scope][]instrumentSync{
scope: {iSync},
scope: make([]instrumentSync, 0, 1),
}
return
}
p.seen[id] = struct{}{}
p.aggregations[scope] = append(p.aggregations[scope], iSync)
Expand Down
20 changes: 20 additions & 0 deletions sdk/metric/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,26 @@ func TestPipelineConcurrency(t *testing.T) {
wg.Wait()
}

func TestPipelineAddSyncIdempotentcy(t *testing.T) {
scope := instrumentation.Scope{Name: "TestPipelineAddSyncIdempotentcy"}
const name0 = "i0"
id0, i0 := instrumentID{Name: name0}, instrumentSync{name: name0}

p := newPipeline(resource.Empty(), NewManualReader(), nil)
p.addSync(id0, scope, i0)

assert.Contains(t, p.seen, id0, "id not tracked")

require.Len(t, p.aggregations[scope], 1, "instrumentSync in pipeline")
require.Equal(t, name0, p.aggregations[scope][0].name, "wrong instrumentSync added")

i1 := instrumentSync{name: "i1"}
p.addSync(id0, scope, i1)

require.Len(t, p.aggregations[scope], 1, "additional instrumentSync in pipeline")
assert.Equal(t, name0, p.aggregations[scope][0].name, "instrumentSync modified")
}

func TestDefaultViewImplicit(t *testing.T) {
t.Run("Int64", testDefaultViewImplicit[int64]())
t.Run("Float64", testDefaultViewImplicit[float64]())
Expand Down

0 comments on commit e41fd60

Please sign in to comment.