(t *testing.T)
| 126 | } |
| 127 | |
| 128 | func 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 | } |
nothing calls this directly
no test coverage detected