forked from getsentry/sentry-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
traces_profiler_test.go
73 lines (64 loc) · 2.12 KB
/
traces_profiler_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package sentry
import (
"io"
"sync"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func testTraceProfiling(t *testing.T, rate float64) (*Span, *Event) {
ticker := setupProfilerTestTicker(io.Discard)
defer restoreProfilerTicker()
transport := &TransportMock{}
ctx := NewTestContext(ClientOptions{
Transport: transport,
EnableTracing: true,
TracesSampleRate: 1.0,
ProfilesSampleRate: rate,
Environment: "env",
Release: "rel",
Dist: "dist",
})
span := StartSpan(ctx, "top")
ticker.Tick()
span.Finish()
require.Equal(t, 1, len(transport.events))
return span, transport.events[0]
}
func TestTraceProfiling(t *testing.T) {
// Disable the automatically started global profiler after the test has finished.
defer func() {
startProfilerOnce = sync.Once{}
if globalProfiler != nil {
globalProfiler.Stop(true)
globalProfiler = nil
}
}()
var require = require.New(t)
require.Nil(globalProfiler)
var timeBeforeStarting = time.Now()
span, event := testTraceProfiling(t, 1.0)
require.Equal(transactionType, event.Type)
require.NotNil(event.sdkMetaData.transactionProfile)
var profileInfo = event.sdkMetaData.transactionProfile
require.Equal("go", profileInfo.Platform)
require.Equal(event.Environment, profileInfo.Environment)
require.Equal(event.Release, profileInfo.Release)
require.Equal(event.Dist, profileInfo.Dist)
require.GreaterOrEqual(profileInfo.Timestamp, timeBeforeStarting)
require.LessOrEqual(profileInfo.Timestamp, time.Now())
require.Equal(event.EventID, profileInfo.Transaction.ID)
require.Greater(profileInfo.Transaction.ActiveThreadID, uint64(0))
require.Equal(span.TraceID.String(), profileInfo.Transaction.TraceID)
validateProfile(t, profileInfo.Trace, span.EndTime.Sub(span.StartTime))
require.NotNil(globalProfiler)
}
func TestTraceProfilingDisabled(t *testing.T) {
if testing.Short() {
t.Skip("Skipping in short mode because of the timeout we wait for in Tick().")
}
var require = require.New(t)
_, event := testTraceProfiling(t, 0)
require.Equal(transactionType, event.Type)
require.Nil(event.sdkMetaData.transactionProfile)
}