-
Notifications
You must be signed in to change notification settings - Fork 0
233 lines (191 loc) · 6.83 KB
/
test.yml
File metadata and controls
233 lines (191 loc) · 6.83 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
name: Test
on:
push:
branches:
- '*'
tags-ignore:
- '*'
pull_request:
workflow_dispatch:
jobs:
build:
name: Build image
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Build Docker image
run: docker buildx build . --platform linux/amd64 --tag mongo-provision
- name: Export image
run: docker save mongo-provision | gzip > mongo-provision.tar.gz
- name: Upload image artifact
uses: actions/upload-artifact@v4
with:
name: mongo-provision-image
path: mongo-provision.tar.gz
retention-days: 1
test-single:
name: "single / ${{ matrix.version }}"
needs: build
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
version: ["4.0", "4.2", "4.4", "5.0", "6.0", "7.0", "8.0"]
steps:
- name: Download image artifact
uses: actions/download-artifact@v4
with:
name: mongo-provision-image
- name: Load Docker image
run: docker load < mongo-provision.tar.gz
- name: Install mongosh
run: npm install -g mongosh
- name: Test
env:
EXPECTED_VERSION: ${{ matrix.version }}
run: |
set -euo pipefail
cleanup() { docker rm -f mongo-test 2>/dev/null || true; }
trap cleanup EXIT
docker run -d --name mongo-test \
-p 27017:27017 \
mongo-provision "$EXPECTED_VERSION" --single
echo "Waiting for cluster to be ready…"
timeout 5m bash -c 'until docker exec mongo-test [ -e ready ]; do sleep 2; done'
mongosh --quiet mongodb://localhost:27017 --eval '
const expected = process.env.EXPECTED_VERSION;
const im = db.adminCommand({ isMaster: 1 });
const ver = db.version();
assert(
ver.startsWith(expected),
"Version mismatch: expected " + expected + ".x, got " + ver
);
assert(
!im.setName,
"Expected standalone (no replica set), got setName=" + im.setName
);
print("PASS: version=" + ver + ", standalone");
'
test-replset:
name: "replset-3 / ${{ matrix.version }}"
needs: build
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
version: ["4.0", "4.2", "4.4", "5.0", "6.0", "7.0", "8.0"]
steps:
- name: Download image artifact
uses: actions/download-artifact@v4
with:
name: mongo-provision-image
- name: Load Docker image
run: docker load < mongo-provision.tar.gz
- name: Install mongosh
run: npm install -g mongosh
- name: Test
env:
EXPECTED_VERSION: ${{ matrix.version }}
run: |
set -euo pipefail
cleanup() { docker rm -f mongo-test 2>/dev/null || true; }
trap cleanup EXIT
docker run -d --name mongo-test \
-p 27017-27019:27017-27019 \
mongo-provision "$EXPECTED_VERSION" --replicaset --nodes 3
echo "Waiting for cluster to be ready…"
timeout 5m bash -c 'until docker exec mongo-test [ -e ready ]; do sleep 2; done'
mongosh --quiet \
"mongodb://localhost:27017,localhost:27018,localhost:27019" \
--eval '
const expected = process.env.EXPECTED_VERSION;
const im = db.adminCommand({ isMaster: 1 });
const ver = db.version();
assert(
ver.startsWith(expected),
"Version mismatch: expected " + expected + ".x, got " + ver
);
assert(
im.setName,
"Expected a replica set, got standalone"
);
const status = db.adminCommand({ replSetGetStatus: 1 });
assert.eq(
status.members.length,
3,
"Expected 3 nodes, got " + status.members.length
);
print(
"PASS: version=" + ver +
", replica set \"" + im.setName + "\"" +
", " + status.members.length + " nodes"
);
'
test-sharded:
name: "sharded-2x3 / ${{ matrix.version }}"
needs: build
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
version: ["4.0", "4.2", "4.4", "5.0", "6.0", "7.0", "8.0"]
steps:
- name: Download image artifact
uses: actions/download-artifact@v4
with:
name: mongo-provision-image
- name: Load Docker image
run: docker load < mongo-provision.tar.gz
- name: Install mongosh
run: npm install -g mongosh
- name: Test
env:
EXPECTED_VERSION: ${{ matrix.version }}
run: |
set -euo pipefail
cleanup() { docker rm -f mongo-test 2>/dev/null || true; }
trap cleanup EXIT
# Only the mongos port (27017) needs to be exposed; shard ports are internal.
docker run -d --name mongo-test \
-p 27017:27017 \
mongo-provision "$EXPECTED_VERSION" --replicaset --sharded 2 --nodes 3
echo "Waiting for cluster to be ready…"
timeout 10m bash -c 'until docker exec mongo-test [ -e ready ]; do sleep 2; done'
mongosh --quiet mongodb://localhost:27017 --eval '
const expected = process.env.EXPECTED_VERSION;
const im = db.adminCommand({ isMaster: 1 });
const ver = db.version();
assert(
ver.startsWith(expected),
"Version mismatch: expected " + expected + ".x, got " + ver
);
assert.eq(
im.msg,
"isdbgrid",
"Expected mongos (isdbgrid), got: " + tojson(im)
);
const listShards = db.adminCommand({ listShards: 1 });
assert.eq(
listShards.shards.length,
2,
"Expected 2 shards, got " + listShards.shards.length
);
// Shard host strings look like "rsName/host:port,host:port,host:port".
// Count the members in the first shard to verify nodes-per-shard.
const firstShardHost = listShards.shards[0].host;
const hostsStr = firstShardHost.includes("/")
? firstShardHost.split("/")[1]
: firstShardHost;
const nodeCount = hostsStr.split(",").length;
assert.eq(
nodeCount,
3,
"Expected 3 nodes/shard, got " + nodeCount + " (host: " + firstShardHost + ")"
);
print(
"PASS: version=" + ver +
", " + listShards.shards.length + " shards" +
", " + nodeCount + " nodes/shard"
);
'