Skip to content

Commit 517179f

Browse files
committed
Improve e2e tests
Change the use of pkill with 'docker rm' as this will work more reliably (at least on MacOS). Trap the EXIT signal so we can perform a clean-up even if a test fails, so we don't pollute the system with a bunch of stopped containers. Increase the timeout from two to three seconds in order for the tests to work reliably on MacOS (the two second waiting period was consistenly to short for all tests to work). Update the Makefile so when we run the container in order to compile the package we make sure the (stopped) container is removed.
1 parent 267a78b commit 517179f

File tree

2 files changed

+49
-31
lines changed

2 files changed

+49
-31
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ bin/$(ARCH)/$(BIN): build-dirs
9393
-v $$(pwd)/bin/$(ARCH):/go/bin/linux_$(ARCH) \
9494
-v $$(pwd)/.go/std/$(ARCH):/usr/local/go/pkg/linux_$(ARCH)_static \
9595
-w /go/src/$(PKG) \
96+
--rm \
9697
$(BUILD_IMAGE) \
9798
/bin/sh -c " \
9899
ARCH=$(ARCH) \

test_e2e.sh

+48-31
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ function testcase() {
1313

1414
function fail() {
1515
echo "FAIL: " "$@"
16-
sleep 2
17-
pkill git-sync || true
18-
ps auxw | grep git-sync
16+
sleep 3
17+
remove_sync_container || true
1918
exit 1
2019
}
2120

@@ -47,6 +46,16 @@ function assert_file_eq() {
4746
fail "file $1 does not contain '$2': $(cat $1)"
4847
}
4948

49+
function finish() {
50+
if [ $? -ne 0 ]; then
51+
echo "The directory $DIR was not removed as it contains"\
52+
"log files useful for debugging"
53+
remove_sync_container
54+
fi
55+
}
56+
57+
trap finish INT EXIT
58+
5059
#########################
5160
# main
5261
#########################
@@ -65,16 +74,24 @@ if [[ -z "$DIR" ]]; then
6574
fi
6675
echo "test root is $DIR"
6776

77+
CONTAINER_NAME=git-sync-$RANDOM
6878
function GIT_SYNC() {
6979
#./bin/amd64/git-sync "$@"
7080
docker run \
81+
--name $CONTAINER_NAME \
7182
-i \
7283
-u $(id -u):$(id -g) \
7384
-v "$DIR":"$DIR" \
85+
--rm \
7486
e2e/git-sync-amd64:$(make -s version) \
7587
"$@"
7688
}
7789

90+
function remove_sync_container() {
91+
# Verify the container is running using 'docker top' before removing
92+
docker top $CONTAINER_NAME >/dev/null 2>&1 && docker rm -f $CONTAINER_NAME
93+
}
94+
7895
REPO="$DIR/repo"
7996
mkdir "$REPO"
8097

@@ -124,25 +141,25 @@ GIT_SYNC \
124141
--repo="$REPO" \
125142
--root="$ROOT" \
126143
--dest="link" > "$DIR"/log."$TESTCASE" 2>&1 &
127-
sleep 2
144+
sleep 3
128145
assert_link_exists "$ROOT"/link
129146
assert_file_exists "$ROOT"/link/file
130147
assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
131148
# Move forward
132149
echo "$TESTCASE 2" > "$REPO"/file
133150
git -C "$REPO" commit -qam "$TESTCASE 2"
134-
sleep 2
151+
sleep 3
135152
assert_link_exists "$ROOT"/link
136153
assert_file_exists "$ROOT"/link/file
137154
assert_file_eq "$ROOT"/link/file "$TESTCASE 2"
138155
# Move backward
139156
git -C "$REPO" reset -q --hard HEAD^
140-
sleep 2
157+
sleep 3
141158
assert_link_exists "$ROOT"/link
142159
assert_file_exists "$ROOT"/link/file
143160
assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
144161
# Wrap up
145-
pkill git-sync
162+
remove_sync_container
146163
wait
147164
pass
148165

@@ -160,25 +177,25 @@ GIT_SYNC \
160177
--rev=HEAD \
161178
--root="$ROOT" \
162179
--dest="link" > "$DIR"/log."$TESTCASE" 2>&1 &
163-
sleep 2
180+
sleep 3
164181
assert_link_exists "$ROOT"/link
165182
assert_file_exists "$ROOT"/link/file
166183
assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
167184
# Move HEAD forward
168185
echo "$TESTCASE 2" > "$REPO"/file
169186
git -C "$REPO" commit -qam "$TESTCASE 2"
170-
sleep 2
187+
sleep 3
171188
assert_link_exists "$ROOT"/link
172189
assert_file_exists "$ROOT"/link/file
173190
assert_file_eq "$ROOT"/link/file "$TESTCASE 2"
174191
# Move HEAD backward
175192
git -C "$REPO" reset -q --hard HEAD^
176-
sleep 2
193+
sleep 3
177194
assert_link_exists "$ROOT"/link
178195
assert_file_exists "$ROOT"/link/file
179196
assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
180197
# Wrap up
181-
pkill git-sync
198+
remove_sync_container
182199
wait
183200
pass
184201

@@ -198,7 +215,7 @@ GIT_SYNC \
198215
--branch="$BRANCH" \
199216
--root="$ROOT" \
200217
--dest="link" > "$DIR"/log."$TESTCASE" 2>&1 &
201-
sleep 2
218+
sleep 3
202219
assert_link_exists "$ROOT"/link
203220
assert_file_exists "$ROOT"/link/file
204221
assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
@@ -207,20 +224,20 @@ git -C "$REPO" checkout -q "$BRANCH"
207224
echo "$TESTCASE 2" > "$REPO"/file
208225
git -C "$REPO" commit -qam "$TESTCASE 2"
209226
git -C "$REPO" checkout -q master
210-
sleep 2
227+
sleep 3
211228
assert_link_exists "$ROOT"/link
212229
assert_file_exists "$ROOT"/link/file
213230
assert_file_eq "$ROOT"/link/file "$TESTCASE 2"
214231
# Move the branch backward
215232
git -C "$REPO" checkout -q "$BRANCH"
216233
git -C "$REPO" reset -q --hard HEAD^
217234
git -C "$REPO" checkout -q master
218-
sleep 2
235+
sleep 3
219236
assert_link_exists "$ROOT"/link
220237
assert_file_exists "$ROOT"/link/file
221238
assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
222239
# Wrap up
223-
pkill git-sync
240+
remove_sync_container
224241
wait
225242
pass
226243

@@ -239,34 +256,34 @@ GIT_SYNC \
239256
--rev="$TAG" \
240257
--root="$ROOT" \
241258
--dest="link" > "$DIR"/log."$TESTCASE" 2>&1 &
242-
sleep 2
259+
sleep 3
243260
assert_link_exists "$ROOT"/link
244261
assert_file_exists "$ROOT"/link/file
245262
assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
246263
# Add something and move the tag forward
247264
echo "$TESTCASE 2" > "$REPO"/file
248265
git -C "$REPO" commit -qam "$TESTCASE 2"
249266
git -C "$REPO" tag -af "$TAG" -m "$TESTCASE 2" >/dev/null
250-
sleep 2
267+
sleep 3
251268
assert_link_exists "$ROOT"/link
252269
assert_file_exists "$ROOT"/link/file
253270
assert_file_eq "$ROOT"/link/file "$TESTCASE 2"
254271
# Move the tag backward
255272
git -C "$REPO" reset -q --hard HEAD^
256273
git -C "$REPO" tag -af "$TAG" -m "$TESTCASE 3" >/dev/null
257-
sleep 2
274+
sleep 3
258275
assert_link_exists "$ROOT"/link
259276
assert_file_exists "$ROOT"/link/file
260277
assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
261278
# Add something after the tag
262279
echo "$TESTCASE 3" > "$REPO"/file
263280
git -C "$REPO" commit -qam "$TESTCASE 3"
264-
sleep 2
281+
sleep 3
265282
assert_link_exists "$ROOT"/link
266283
assert_file_exists "$ROOT"/link/file
267284
assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
268285
# Wrap up
269-
pkill git-sync
286+
remove_sync_container
270287
wait
271288
pass
272289

@@ -288,7 +305,7 @@ GIT_SYNC \
288305
--rev="$TAG" \
289306
--root="$ROOT" \
290307
--dest="link" > "$DIR"/log."$TESTCASE" 2>&1 &
291-
sleep 2
308+
sleep 3
292309
assert_link_exists "$ROOT"/link
293310
assert_file_exists "$ROOT"/link/file
294311
assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
@@ -298,7 +315,7 @@ echo "$TESTCASE 2" > "$REPO"/file
298315
git -C "$REPO" commit -qam "$TESTCASE 2"
299316
git -C "$REPO" tag -af "$TAG" -m "$TESTCASE 1" >/dev/null
300317
git -C "$REPO" checkout -q master
301-
sleep 2
318+
sleep 3
302319
assert_link_exists "$ROOT"/link
303320
assert_file_exists "$ROOT"/link/file
304321
assert_file_eq "$ROOT"/link/file "$TESTCASE 2"
@@ -307,7 +324,7 @@ git -C "$REPO" checkout -q "$BRANCH"
307324
git -C "$REPO" reset -q --hard HEAD^
308325
git -C "$REPO" tag -af "$TAG" -m "$TESTCASE 1" >/dev/null
309326
git -C "$REPO" checkout -q master
310-
sleep 2
327+
sleep 3
311328
assert_link_exists "$ROOT"/link
312329
assert_file_exists "$ROOT"/link/file
313330
assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
@@ -316,20 +333,20 @@ git -C "$REPO" checkout -q "$BRANCH"
316333
echo "$TESTCASE 3" > "$REPO"/file
317334
git -C "$REPO" commit -qam "$TESTCASE 3"
318335
git -C "$REPO" checkout -q master
319-
sleep 2
336+
sleep 3
320337
assert_link_exists "$ROOT"/link
321338
assert_file_exists "$ROOT"/link/file
322339
assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
323340
# Move the tag forward again
324341
git -C "$REPO" checkout -q "$BRANCH"
325342
git -C "$REPO" tag -af "$TAG" -m "$TESTCASE 3" >/dev/null
326343
git -C "$REPO" checkout -q master
327-
sleep 2
344+
sleep 3
328345
assert_link_exists "$ROOT"/link
329346
assert_file_exists "$ROOT"/link/file
330347
assert_file_eq "$ROOT"/link/file "$TESTCASE 3"
331348
# Wrap up
332-
pkill git-sync
349+
remove_sync_container
333350
wait
334351
pass
335352

@@ -347,25 +364,25 @@ GIT_SYNC \
347364
--rev="$REV" \
348365
--root="$ROOT" \
349366
--dest="link" > "$DIR"/log."$TESTCASE" 2>&1 &
350-
sleep 2
367+
sleep 3
351368
assert_link_exists "$ROOT"/link
352369
assert_file_exists "$ROOT"/link/file
353370
assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
354371
# Commit something new
355372
echo "$TESTCASE 2" > "$REPO"/file
356373
git -C "$REPO" commit -qam "$TESTCASE 2"
357-
sleep 2
374+
sleep 3
358375
assert_link_exists "$ROOT"/link
359376
assert_file_exists "$ROOT"/link/file
360377
assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
361378
# Revert the last change
362379
git -C "$REPO" reset -q --hard HEAD^
363-
sleep 2
380+
sleep 3
364381
assert_link_exists "$ROOT"/link
365382
assert_file_exists "$ROOT"/link/file
366383
assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
367384
# Wrap up
368-
pkill git-sync
385+
remove_sync_container
369386
wait
370387
pass
371388

@@ -384,7 +401,7 @@ GIT_SYNC \
384401
--root="$ROOT" \
385402
--dest="link" \
386403
--one-time > "$DIR"/log."$TESTCASE" 2>&1
387-
sleep 2
404+
sleep 3
388405
assert_link_exists "$ROOT"/link
389406
assert_file_exists "$ROOT"/link/file
390407
assert_file_eq "$ROOT"/link/file "$TESTCASE"

0 commit comments

Comments
 (0)