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
|
package praefect_test
import (
"testing"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/praefect"
"gitlab.com/gitlab-org/gitaly/internal/praefect/config"
"gitlab.com/gitlab-org/gitaly/internal/praefect/models"
)
// TestMemoryDatastoreWhitelist verifies that the in-memory datastore will
// populate itself with the correct replication jobs and shards when initialized
// with a configuration file specifying the shard and whitelisted repositories.
func TestMemoryDatastoreWhitelist(t *testing.T) {
cfg := config.Config{
PrimaryServer: &models.GitalyServer{
Name: "default",
},
SecondaryServers: []*models.GitalyServer{
{
Name: "backup-1",
},
{
Name: "backup-2",
},
},
Whitelist: []string{"abcd1234", "5678efgh"},
}
mds := praefect.NewMemoryDatastore(cfg)
repo1 := models.Repository{
RelativePath: cfg.Whitelist[0],
Storage: cfg.PrimaryServer.Name,
}
repo2 := models.Repository{
RelativePath: cfg.Whitelist[1],
Storage: cfg.PrimaryServer.Name,
}
expectSecondaries := []models.GitalyServer{
models.GitalyServer{Name: cfg.SecondaryServers[0].Name},
models.GitalyServer{Name: cfg.SecondaryServers[1].Name},
}
for _, repo := range []models.Repository{repo1, repo2} {
actualSecondaries, err := mds.GetShardSecondaries(repo)
require.NoError(t, err)
require.ElementsMatch(t, expectSecondaries, actualSecondaries)
}
backup1 := cfg.SecondaryServers[0]
backup2 := cfg.SecondaryServers[1]
backup1ExpectedJobs := []praefect.ReplJob{
praefect.ReplJob{
ID: 1,
Target: backup1.Name,
Source: repo1,
State: praefect.JobStateReady,
},
praefect.ReplJob{
ID: 3,
Target: backup1.Name,
Source: repo2,
State: praefect.JobStateReady,
},
}
backup2ExpectedJobs := []praefect.ReplJob{
praefect.ReplJob{
ID: 2,
Target: backup2.Name,
Source: repo1,
State: praefect.JobStateReady,
},
praefect.ReplJob{
ID: 4,
Target: backup2.Name,
Source: repo2,
State: praefect.JobStateReady,
},
}
backup1ActualJobs, err := mds.GetJobs(praefect.JobStatePending|praefect.JobStateReady, backup1.Name, 10)
require.NoError(t, err)
require.Equal(t, backup1ExpectedJobs, backup1ActualJobs)
backup2ActualJobs, err := mds.GetJobs(praefect.JobStatePending|praefect.JobStateReady, backup2.Name, 10)
require.NoError(t, err)
require.Equal(t, backup2ActualJobs, backup2ExpectedJobs)
}
|