Skip to content
This repository was archived by the owner on Apr 12, 2019. It is now read-only.

Commit f453b38

Browse files
author
Mura Li
committed
Add tests for RunInDirTimeoutPipeline
1 parent 135704d commit f453b38

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

command_test.go

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2017 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
// +build race
6+
7+
package git
8+
9+
import (
10+
"testing"
11+
"time"
12+
)
13+
14+
func TestRunInDirTimeoutPipelineNoTimeout(t *testing.T) {
15+
16+
maxLoops := 1000
17+
18+
// 'git --version' does not block so it must be finished before the timeout triggered.
19+
cmd := NewCommand("--version")
20+
for i := 0; i < maxLoops; i++ {
21+
if err := cmd.RunInDirTimeoutPipeline(-1, "", nil, nil); err != nil {
22+
t.Fatal(err)
23+
}
24+
}
25+
}
26+
27+
func TestRunInDirTimeoutPipelineAlwaysTimeout(t *testing.T) {
28+
29+
maxLoops := 1000
30+
31+
// 'git hash-object --stdin' blocks on stdin so we can have the timeout triggered.
32+
cmd := NewCommand("hash-object --stdin")
33+
for i := 0; i < maxLoops; i++ {
34+
if err := cmd.RunInDirTimeoutPipeline(1*time.Microsecond, "", nil, nil); err != nil {
35+
// 'context deadline exceeded' when the error is returned by exec.Start
36+
// 'signal: killed' when the error is returned by exec.Wait
37+
// It depends on the point of the time (before or after exec.Start returns) at which the timeout is triggered.
38+
if err.Error() != "context deadline exceeded" && err.Error() != "signal: killed" {
39+
t.Fatalf("Testing %d/%d: %v", i, maxLoops, err)
40+
}
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)