Welcome to mirror list, hosted at ThFree Co, Russian Federation.

stats_test.go « command « internal - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b4211c11bf416c852bd12de51ac08ad1a6d7dffb (plain)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package command

import (
	"testing"

	"github.com/sirupsen/logrus"
	"github.com/stretchr/testify/require"
	"gitlab.com/gitlab-org/gitaly/v15/internal/testhelper"
)

func TestStatsFromContext_BackgroundContext(t *testing.T) {
	ctx := testhelper.Context(t)

	stats := StatsFromContext(ctx)
	require.Nil(t, stats)
}

func TestStatsFromContext_InitContext(t *testing.T) {
	ctx := testhelper.Context(t)

	ctx = InitContextStats(ctx)

	stats := StatsFromContext(ctx)

	require.NotNil(t, stats)
	require.Equal(t, stats.Fields(), logrus.Fields{})
}

func TestStatsFromContext_RecordSum(t *testing.T) {
	ctx := testhelper.Context(t)

	ctx = InitContextStats(ctx)

	stats := StatsFromContext(ctx)

	stats.RecordSum("foo", 1)
	stats.RecordSum("foo", 1)

	require.NotNil(t, stats)
	require.Equal(t, stats.Fields(), logrus.Fields{"foo": 2})
}

func TestStatsFromContext_RecordSumByRef(t *testing.T) {
	ctx := testhelper.Context(t)

	ctx = InitContextStats(ctx)

	stats := StatsFromContext(ctx)

	stats.RecordSum("foo", 1)
	stats.RecordSum("foo", 1)

	stats2 := StatsFromContext(ctx)

	require.NotNil(t, stats2)
	require.Equal(t, stats2.Fields(), logrus.Fields{"foo": 2})
}

func TestStatsFromContext_RecordMax(t *testing.T) {
	ctx := testhelper.Context(t)

	ctx = InitContextStats(ctx)

	stats := StatsFromContext(ctx)

	stats.RecordMax("foo", 1024)
	stats.RecordMax("foo", 256)
	stats.RecordMax("foo", 512)

	require.NotNil(t, stats)
	require.Equal(t, stats.Fields(), logrus.Fields{"foo": 1024})
}

func TestStatsFromContext_RecordMetadata(t *testing.T) {
	ctx := testhelper.Context(t)

	ctx = InitContextStats(ctx)

	stats := StatsFromContext(ctx)

	stats.RecordMetadata("foo", "bar")
	require.NotNil(t, stats)
	require.Equal(t, stats.Fields(), logrus.Fields{"foo": "bar"})

	stats.RecordMetadata("foo", "baz") // override the existing value
	require.NotNil(t, stats)
	require.Equal(t, stats.Fields(), logrus.Fields{"foo": "baz"})
}