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

commit_graph_test.go « stats « git « internal - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 894070b99a2de6ce13a01e0de6694d4c87e777c3 (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package stats

import (
	"testing"
	"time"

	"github.com/stretchr/testify/require"
	"gitlab.com/gitlab-org/gitaly/v16/internal/git/gittest"
	"gitlab.com/gitlab-org/gitaly/v16/internal/testhelper"
	"gitlab.com/gitlab-org/gitaly/v16/internal/testhelper/testcfg"
)

func TestCommitGraphInfoForRepository(t *testing.T) {
	t.Parallel()

	ctx := testhelper.Context(t)
	cfg := testcfg.Build(t)

	for _, tc := range []struct {
		desc         string
		setup        func(t *testing.T, repoPath string)
		expectedErr  error
		expectedInfo CommitGraphInfo
	}{
		{
			desc:         "no commit graph filter",
			setup:        func(*testing.T, string) {},
			expectedInfo: CommitGraphInfo{},
		},
		{
			desc: "single commit graph without bloom filter and generation data",
			setup: func(t *testing.T, repoPath string) {
				gittest.Exec(t, cfg, "-C", repoPath,
					"-c", "commitGraph.generationVersion=1",
					"commit-graph", "write", "--reachable",
				)
			},
			expectedInfo: CommitGraphInfo{
				Exists: true,
			},
		},
		{
			desc: "single commit graph with bloom filter",
			setup: func(t *testing.T, repoPath string) {
				gittest.Exec(t, cfg, "-C", repoPath,
					"-c", "commitGraph.generationVersion=1",
					"commit-graph", "write", "--reachable", "--changed-paths",
				)
			},
			expectedInfo: CommitGraphInfo{
				Exists:          true,
				HasBloomFilters: true,
			},
		},
		{
			desc: "single commit graph with generation numbers",
			setup: func(t *testing.T, repoPath string) {
				gittest.Exec(t, cfg, "-C", repoPath,
					"-c", "commitGraph.generationVersion=2",
					"commit-graph", "write", "--reachable", "--changed-paths",
				)
			},
			expectedInfo: CommitGraphInfo{
				Exists:            true,
				HasBloomFilters:   true,
				HasGenerationData: true,
			},
		},
		{
			desc: "split commit graph without bloom filter and generation data",
			setup: func(t *testing.T, repoPath string) {
				gittest.Exec(t, cfg, "-C", repoPath,
					"-c", "commitGraph.generationVersion=1",
					"commit-graph", "write", "--reachable", "--split",
				)
			},
			expectedInfo: CommitGraphInfo{
				Exists:                 true,
				CommitGraphChainLength: 1,
			},
		},
		{
			desc: "split commit graph with bloom filter without generation data",
			setup: func(t *testing.T, repoPath string) {
				gittest.Exec(t, cfg, "-C", repoPath,
					"-c", "commitGraph.generationVersion=1",
					"commit-graph", "write", "--reachable", "--split", "--changed-paths",
				)
			},
			expectedInfo: CommitGraphInfo{
				Exists:                 true,
				CommitGraphChainLength: 1,
				HasBloomFilters:        true,
			},
		},
		{
			desc: "split commit-graph with generation numbers",
			setup: func(t *testing.T, repoPath string) {
				gittest.Exec(t, cfg, "-C", repoPath,
					"-c", "commitGraph.generationVersion=2",
					"commit-graph", "write", "--reachable", "--split", "--changed-paths",
				)
			},
			expectedInfo: CommitGraphInfo{
				Exists:                 true,
				CommitGraphChainLength: 1,
				HasBloomFilters:        true,
				HasGenerationData:      true,
			},
		},
		{
			desc: "split commit-graph with generation data overflow",
			setup: func(t *testing.T, repoPath string) {
				// We write two commits, where the parent commit is far away in the
				// future and its child commit is in the past. This means we'll have
				// to write a corrected committer date, and because the corrected
				// date is longer than 31 bits we'll have to also write overflow
				// data.
				futureParent := gittest.WriteCommit(t, cfg, repoPath,
					gittest.WithCommitterDate(time.Date(2077, 1, 1, 0, 0, 0, 0, time.UTC)),
				)
				gittest.WriteCommit(t, cfg, repoPath,
					gittest.WithBranch("overflow"),
					gittest.WithParents(futureParent),
					gittest.WithCommitterDate(time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC)),
				)

				gittest.Exec(t, cfg, "-C", repoPath,
					"-c", "commitGraph.generationVersion=2",
					"commit-graph", "write", "--reachable", "--split", "--changed-paths",
				)
			},
			expectedInfo: CommitGraphInfo{
				Exists:                    true,
				CommitGraphChainLength:    1,
				HasBloomFilters:           true,
				HasGenerationData:         true,
				HasGenerationDataOverflow: true,
			},
		},
	} {
		t.Run(tc.desc, func(t *testing.T) {
			_, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
				SkipCreationViaService: true,
			})
			gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("main"))
			tc.setup(t, repoPath)

			info, err := CommitGraphInfoForRepository(repoPath)
			require.Equal(t, tc.expectedErr, err)
			require.Equal(t, tc.expectedInfo, info)
		})
	}
}