-
Notifications
You must be signed in to change notification settings - Fork 39
/
snapshot_test.go
53 lines (44 loc) · 1.34 KB
/
snapshot_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
// (c) Copyright IBM Corp. 2021
// (c) Copyright Instana Inc. 2020
package instana_test
import (
"runtime"
"testing"
"time"
instana "github.com/instana/go-sensor"
"github.com/instana/go-sensor/acceptor"
"github.com/stretchr/testify/assert"
)
func TestSnapshotCollector_Collect(t *testing.T) {
sc := instana.SnapshotCollector{
ServiceName: "test",
CollectionInterval: 500 * time.Millisecond,
}
assert.Equal(t, &acceptor.RuntimeInfo{
Name: sc.ServiceName,
Version: runtime.Version(),
Root: runtime.GOROOT(),
MaxProcs: runtime.GOMAXPROCS(0),
Compiler: runtime.Compiler,
NumCPU: runtime.NumCPU(),
SensorVersion: instana.Version,
}, sc.Collect())
t.Run("second call before collection interval", func(t *testing.T) {
assert.Nil(t, sc.Collect())
})
t.Run("second call after collection interval", func(t *testing.T) {
oldNumProcs := runtime.GOMAXPROCS(0)
defer runtime.GOMAXPROCS(oldNumProcs)
time.Sleep(sc.CollectionInterval)
runtime.GOMAXPROCS(oldNumProcs + 1)
assert.Equal(t, &acceptor.RuntimeInfo{
Name: sc.ServiceName,
Version: runtime.Version(),
Root: runtime.GOROOT(),
MaxProcs: oldNumProcs + 1,
Compiler: runtime.Compiler,
NumCPU: runtime.NumCPU(),
SensorVersion: instana.Version,
}, sc.Collect())
})
}