MCPcopy Create free account
hub / github.com/cli/cli / TestServiceCollectsConcurrentFacts

Function TestServiceCollectsConcurrentFacts

internal/telemetry/service_test.go:128–157  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

126}
127
128func TestServiceCollectsConcurrentFacts(t *testing.T) {
129 t.Cleanup(stubDeviceID("test-device"))
130
131 // Given two command activities contributing to the same pending event
132 var payload SendTelemetryPayload
133 service := NewService(func(p SendTelemetryPayload) { payload = p })
134 pending := service.Begin(ghtelemetry.Event{Type: "attachment_invocation"})
135
136 // When both activities finish before command completion
137 var workers sync.WaitGroup
138 workers.Go(func() {
139 pending.UpsertDimensions(ghtelemetry.Dimensions{"command": "gh issue create"})
140 pending.UpsertMeasures(ghtelemetry.Measures{"append_ops_count": 1})
141 })
142 workers.Go(func() {
143 pending.UpsertDimensions(ghtelemetry.Dimensions{"flags": "attach"})
144 pending.UpsertMeasures(ghtelemetry.Measures{"replace_ops_count": 2})
145 })
146 workers.Wait()
147 service.Finish()
148
149 // Then the completed event contains both activities' facts
150 require.Len(t, payload.Events, 1)
151 assert.Equal(t, "gh issue create", payload.Events[0].Dimensions["command"])
152 assert.Equal(t, "attach", payload.Events[0].Dimensions["flags"])
153 assert.Equal(t, map[string]int64{
154 "append_ops_count": 1,
155 "replace_ops_count": 2,
156 }, payload.Events[0].Measures)
157}

Callers

nothing calls this directly

Calls 9

FinishMethod · 0.95
stubDeviceIDFunction · 0.85
NewServiceFunction · 0.85
EqualMethod · 0.80
BeginMethod · 0.65
UpsertDimensionsMethod · 0.65
UpsertMeasuresMethod · 0.65
WaitMethod · 0.65
LenMethod · 0.65

Tested by

no test coverage detected