Skip to content

Commit 8388a64

Browse files
jiangxingitster
authored andcommitted
t5411: use different out file to prevent overwriting
SZEDER reported that t5411 failed in Travis CI's s390x environment a couple of times, and could be reproduced with '--stress' test on this specific environment. The test failure messages might look like this: + test_cmp expect actual --- expect 2021-01-17 21:55:23.430750004 +0000 +++ actual 2021-01-17 21:55:23.430750004 +0000 @@ -1 +1 @@ -<COMMIT-A> refs/heads/main +<COMMIT-A> refs/heads/maifatal: the remote end hung up unexpectedly error: last command exited with $?=1 not ok 86 - proc-receive: not support push options (builtin protocol) The file 'actual' is filtered from the file 'out' which contains result of 'git show-ref' command. Due to the error messages from other process is written into the file 'out' accidentally, t5411 failed. SZEDER finds the root cause of this issue: - 'git push' is executed with its standard output and error redirected to the file 'out'. - 'git push' executes 'git receive-pack' internally, which inherits the open file descriptors, so its output and error goes into that same 'out' file. - 'git push' ends without waiting for the close of 'git-receive-pack' for some cases, and the file 'out' is reused for test of 'git show-ref' afterwards. - A mixture of the output of 'git show-ref' abd 'git receive-pack' leads to this issue. The first intuitive reaction to resolve this issue is to remove the file 'out' after use, so that the newly created file 'out' will have a different file descriptor and will not be overwritten by the 'git receive-pack' process. But Johannes pointed out that removing an open file is not possible on Windows. So we use different temporary file names to store the output of 'git push' to solve this issue. Reported-by: SZEDER Gábor <[email protected]> Helped-by: Johannes Sixt <[email protected]> Helped-by: SZEDER Gábor <[email protected]> Signed-off-by: Jiang Xin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 71ca53e commit 8388a64

20 files changed

+98
-98
lines changed

t/t5411/test-0000-standard-git-push.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ test_expect_success "git-push --atomic ($PROTOCOL)" '
3535
test_must_fail git -C workbench push --atomic origin \
3636
main \
3737
$B:refs/heads/next \
38-
>out 2>&1 &&
38+
>out-$test_count 2>&1 &&
3939
filter_out_user_friendly_and_stable_output \
4040
-e "/^To / { p; }" \
4141
-e "/^ ! / { p; }" \
42-
<out >actual &&
42+
<out-$test_count >actual &&
4343
cat >expect <<-EOF &&
4444
To <URL/of/upstream.git>
4545
! [rejected] main -> main (non-fast-forward)
@@ -65,8 +65,8 @@ test_expect_success "non-fast-forward git-push ($PROTOCOL)" '
6565
push origin \
6666
main \
6767
$B:refs/heads/next \
68-
>out 2>&1 &&
69-
make_user_friendly_and_stable_output <out >actual &&
68+
>out-$test_count 2>&1 &&
69+
make_user_friendly_and_stable_output <out-$test_count >actual &&
7070
cat >expect <<-EOF &&
7171
remote: # pre-receive hook
7272
remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/next

t/t5411/test-0001-standard-git-push--porcelain.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ test_expect_success "git-push --atomic ($PROTOCOL/porcelain)" '
3636
test_must_fail git -C workbench push --atomic --porcelain origin \
3737
main \
3838
$B:refs/heads/next \
39-
>out 2>&1 &&
39+
>out-$test_count 2>&1 &&
4040
filter_out_user_friendly_and_stable_output \
4141
-e "s/^# GETTEXT POISON #//" \
4242
-e "/^To / { p; }" \
4343
-e "/^! / { p; }" \
44-
<out >actual &&
44+
<out-$test_count >actual &&
4545
cat >expect <<-EOF &&
4646
To <URL/of/upstream.git>
4747
! refs/heads/main:refs/heads/main [rejected] (non-fast-forward)
@@ -67,8 +67,8 @@ test_expect_success "non-fast-forward git-push ($PROTOCOL/porcelain)" '
6767
push --porcelain origin \
6868
main \
6969
$B:refs/heads/next \
70-
>out 2>&1 &&
71-
make_user_friendly_and_stable_output <out >actual &&
70+
>out-$test_count 2>&1 &&
71+
make_user_friendly_and_stable_output <out-$test_count >actual &&
7272
cat >expect <<-EOF &&
7373
remote: # pre-receive hook
7474
remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/next

t/t5411/test-0002-pre-receive-declined.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ test_expect_success "git-push is declined ($PROTOCOL)" '
1212
test_must_fail git -C workbench push origin \
1313
$B:refs/heads/main \
1414
HEAD:refs/heads/next \
15-
>out 2>&1 &&
16-
make_user_friendly_and_stable_output <out >actual &&
15+
>out-$test_count 2>&1 &&
16+
make_user_friendly_and_stable_output <out-$test_count >actual &&
1717
cat >expect <<-EOF &&
1818
To <URL/of/upstream.git>
1919
! [remote rejected] <COMMIT-B> -> main (pre-receive hook declined)

t/t5411/test-0003-pre-receive-declined--porcelain.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ test_expect_success "git-push is declined ($PROTOCOL/porcelain)" '
1212
test_must_fail git -C workbench push --porcelain origin \
1313
$B:refs/heads/main \
1414
HEAD:refs/heads/next \
15-
>out 2>&1 &&
16-
make_user_friendly_and_stable_output <out >actual &&
15+
>out-$test_count 2>&1 &&
16+
make_user_friendly_and_stable_output <out-$test_count >actual &&
1717
cat >expect <<-EOF &&
1818
To <URL/of/upstream.git>
1919
! <COMMIT-B>:refs/heads/main [remote rejected] (pre-receive hook declined)

t/t5411/test-0011-no-hook-error.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ test_expect_success "proc-receive: no hook, fail to push special ref ($PROTOCOL)
55
test_must_fail git -C workbench push origin \
66
HEAD:next \
77
HEAD:refs/for/main/topic \
8-
>out 2>&1 &&
9-
make_user_friendly_and_stable_output <out >actual &&
8+
>out-$test_count 2>&1 &&
9+
make_user_friendly_and_stable_output <out-$test_count >actual &&
1010
cat >expect <<-EOF &&
1111
remote: # pre-receive hook
1212
remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
@@ -41,8 +41,8 @@ test_expect_success "proc-receive: no hook, all failed for atomic push ($PROTOCO
4141
test_must_fail git -C workbench push --atomic origin \
4242
$B:main \
4343
HEAD:next \
44-
HEAD:refs/for/main/topic >out 2>&1 &&
45-
make_user_friendly_and_stable_output <out >actual &&
44+
HEAD:refs/for/main/topic >out-$test_count 2>&1 &&
45+
make_user_friendly_and_stable_output <out-$test_count >actual &&
4646
cat >expect <<-EOF &&
4747
remote: # pre-receive hook
4848
remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/main

t/t5411/test-0012-no-hook-error--porcelain.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ test_expect_success "proc-receive: no hook, fail to push special ref ($PROTOCOL/
55
test_must_fail git -C workbench push --porcelain origin \
66
HEAD:next \
77
HEAD:refs/for/main/topic \
8-
>out 2>&1 &&
9-
make_user_friendly_and_stable_output <out >actual &&
8+
>out-$test_count 2>&1 &&
9+
make_user_friendly_and_stable_output <out-$test_count >actual &&
1010
cat >expect <<-EOF &&
1111
remote: # pre-receive hook
1212
remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
@@ -42,8 +42,8 @@ test_expect_success "proc-receive: no hook, all failed for atomic push ($PROTOCO
4242
test_must_fail git -C workbench push --porcelain --atomic origin \
4343
$B:main \
4444
HEAD:next \
45-
HEAD:refs/for/main/topic >out 2>&1 &&
46-
make_user_friendly_and_stable_output <out >actual &&
45+
HEAD:refs/for/main/topic >out-$test_count 2>&1 &&
46+
make_user_friendly_and_stable_output <out-$test_count >actual &&
4747
cat >expect <<-EOF &&
4848
remote: # pre-receive hook
4949
remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/main

t/t5411/test-0013-bad-protocol.sh

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ test_expect_success "setup proc-receive hook (unknown version, $PROTOCOL)" '
1111
test_expect_success "proc-receive: bad protocol (unknown version, $PROTOCOL)" '
1212
test_must_fail git -C workbench push origin \
1313
HEAD:refs/for/main/topic \
14-
>out 2>&1 &&
15-
make_user_friendly_and_stable_output <out >actual &&
14+
>out-$test_count 2>&1 &&
15+
make_user_friendly_and_stable_output <out-$test_count >actual &&
1616
1717
# Check status report for git-push
1818
sed -n \
@@ -55,18 +55,18 @@ test_expect_success "setup proc-receive hook (hook --die-read-version, $PROTOCOL
5555
test_expect_success "proc-receive: bad protocol (hook --die-read-version, $PROTOCOL)" '
5656
test_must_fail git -C workbench push origin \
5757
HEAD:refs/for/main/topic \
58-
>out 2>&1 &&
58+
>out-$test_count 2>&1 &&
5959
filter_out_user_friendly_and_stable_output \
6060
-e "/^To / { p; }" \
6161
-e "/^ ! / { p; }" \
62-
<out >actual &&
62+
<out-$test_count >actual &&
6363
cat >expect <<-EOF &&
6464
To <URL/of/upstream.git>
6565
! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook)
6666
EOF
6767
test_cmp expect actual &&
68-
grep "remote: fatal: die with the --die-read-version option" out &&
69-
grep "remote: error: fail to negotiate version with proc-receive hook" out &&
68+
grep "remote: fatal: die with the --die-read-version option" out-$test_count &&
69+
grep "remote: error: fail to negotiate version with proc-receive hook" out-$test_count &&
7070
7171
git -C "$upstream" show-ref >out &&
7272
make_user_friendly_and_stable_output <out >actual &&
@@ -89,18 +89,18 @@ test_expect_success "setup proc-receive hook (hook --die-write-version, $PROTOCO
8989
test_expect_success "proc-receive: bad protocol (hook --die-write-version, $PROTOCOL)" '
9090
test_must_fail git -C workbench push origin \
9191
HEAD:refs/for/main/topic \
92-
>out 2>&1 &&
92+
>out-$test_count 2>&1 &&
9393
filter_out_user_friendly_and_stable_output \
9494
-e "/^To / { p; }" \
9595
-e "/^ ! / { p; }" \
96-
<out >actual &&
96+
<out-$test_count >actual &&
9797
cat >expect <<-EOF &&
9898
To <URL/of/upstream.git>
9999
! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook)
100100
EOF
101101
test_cmp expect actual &&
102-
grep "remote: fatal: die with the --die-write-version option" out &&
103-
grep "remote: error: fail to negotiate version with proc-receive hook" out &&
102+
grep "remote: fatal: die with the --die-write-version option" out-$test_count &&
103+
grep "remote: error: fail to negotiate version with proc-receive hook" out-$test_count &&
104104
105105
git -C "$upstream" show-ref >out &&
106106
make_user_friendly_and_stable_output <out >actual &&
@@ -123,17 +123,17 @@ test_expect_success "setup proc-receive hook (hook --die-read-commands, $PROTOCO
123123
test_expect_success "proc-receive: bad protocol (hook --die-read-commands, $PROTOCOL)" '
124124
test_must_fail git -C workbench push origin \
125125
HEAD:refs/for/main/topic \
126-
>out 2>&1 &&
126+
>out-$test_count 2>&1 &&
127127
filter_out_user_friendly_and_stable_output \
128128
-e "/^To / { p; }" \
129129
-e "/^ ! / { p; }" \
130-
<out >actual &&
130+
<out-$test_count >actual &&
131131
cat >expect <<-EOF &&
132132
To <URL/of/upstream.git>
133133
! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook)
134134
EOF
135135
test_cmp expect actual &&
136-
grep "remote: fatal: die with the --die-read-commands option" out &&
136+
grep "remote: fatal: die with the --die-read-commands option" out-$test_count &&
137137
138138
git -C "$upstream" show-ref >out &&
139139
make_user_friendly_and_stable_output <out >actual &&
@@ -158,17 +158,17 @@ test_expect_success "proc-receive: bad protocol (hook --die-read-push-options, $
158158
test_must_fail git -C workbench push origin \
159159
-o reviewers=user1,user2 \
160160
HEAD:refs/for/main/topic \
161-
>out 2>&1 &&
161+
>out-$test_count 2>&1 &&
162162
filter_out_user_friendly_and_stable_output \
163163
-e "/^To / { p; }" \
164164
-e "/^ ! / { p; }" \
165-
<out >actual &&
165+
<out-$test_count >actual &&
166166
cat >expect <<-EOF &&
167167
To <URL/of/upstream.git>
168168
! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook)
169169
EOF
170170
test_cmp expect actual &&
171-
grep "remote: fatal: die with the --die-read-push-options option" out &&
171+
grep "remote: fatal: die with the --die-read-push-options option" out-$test_count &&
172172
173173
git -C "$upstream" show-ref >out &&
174174
make_user_friendly_and_stable_output <out >actual &&
@@ -191,17 +191,17 @@ test_expect_success "setup proc-receive hook (hook --die-write-report, $PROTOCOL
191191
test_expect_success "proc-receive: bad protocol (hook --die-write-report, $PROTOCOL)" '
192192
test_must_fail git -C workbench push origin \
193193
HEAD:refs/for/main/topic \
194-
>out 2>&1 &&
194+
>out-$test_count 2>&1 &&
195195
filter_out_user_friendly_and_stable_output \
196196
-e "/^To / { p; }" \
197197
-e "/^ ! / { p; }" \
198-
<out >actual &&
198+
<out-$test_count >actual &&
199199
cat >expect <<-EOF &&
200200
To <URL/of/upstream.git>
201201
! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook)
202202
EOF
203203
test_cmp expect actual &&
204-
grep "remote: fatal: die with the --die-write-report option" out &&
204+
grep "remote: fatal: die with the --die-write-report option" out-$test_count &&
205205
206206
git -C "$upstream" show-ref >out &&
207207
make_user_friendly_and_stable_output <out >actual &&
@@ -224,8 +224,8 @@ test_expect_success "setup proc-receive hook (no report, $PROTOCOL)" '
224224
test_expect_success "proc-receive: bad protocol (no report, $PROTOCOL)" '
225225
test_must_fail git -C workbench push origin \
226226
HEAD:refs/heads/next \
227-
HEAD:refs/for/main/topic >out 2>&1 &&
228-
make_user_friendly_and_stable_output <out >actual &&
227+
HEAD:refs/for/main/topic >out-$test_count 2>&1 &&
228+
make_user_friendly_and_stable_output <out-$test_count >actual &&
229229
cat >expect <<-EOF &&
230230
remote: # pre-receive hook
231231
remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
@@ -270,8 +270,8 @@ test_expect_success "setup proc-receive hook (no ref, $PROTOCOL)" '
270270
test_expect_success "proc-receive: bad protocol (no ref, $PROTOCOL)" '
271271
test_must_fail git -C workbench push origin \
272272
HEAD:refs/for/main/topic\
273-
>out 2>&1 &&
274-
make_user_friendly_and_stable_output <out >actual &&
273+
>out-$test_count 2>&1 &&
274+
make_user_friendly_and_stable_output <out-$test_count >actual &&
275275
cat >expect <<-EOF &&
276276
remote: # pre-receive hook
277277
remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
@@ -306,8 +306,8 @@ test_expect_success "setup proc-receive hook (unknown status, $PROTOCOL)" '
306306
test_expect_success "proc-receive: bad protocol (unknown status, $PROTOCOL)" '
307307
test_must_fail git -C workbench push origin \
308308
HEAD:refs/for/main/topic \
309-
>out 2>&1 &&
310-
make_user_friendly_and_stable_output <out >actual &&
309+
>out-$test_count 2>&1 &&
310+
make_user_friendly_and_stable_output <out-$test_count >actual &&
311311
cat >expect <<-EOF &&
312312
remote: # pre-receive hook
313313
remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic

0 commit comments

Comments
 (0)