diff options
author | Mura Li <typeless@users.noreply.github.com> | 2017-11-13 08:51:45 -0600 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-11-13 22:51:45 +0800 |
commit | f4d12f8d9711d54b022ef28c39c670f36700f8f7 (patch) | |
tree | 9ce1511be1d5406e26e55eaf75ff41b4a66ea7a1 /modules/process/manager_test.go | |
parent | e9728bf3b4c763464db30e1259501cf38a7a20c7 (diff) | |
download | gitea-f4d12f8d9711d54b022ef28c39c670f36700f8f7.tar.gz gitea-f4d12f8d9711d54b022ef28c39c670f36700f8f7.zip |
Fix run command race (#1470)
* Use exec.CommandContext to simplfy timeout handling
And fixing the data races which can be identified by the added tests when -race enabled.
* Use sleep commmand instead of reading from stdin
* Make the error handling go-esque
Diffstat (limited to 'modules/process/manager_test.go')
-rw-r--r-- | modules/process/manager_test.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/modules/process/manager_test.go b/modules/process/manager_test.go index e638264ce1..9980aba921 100644 --- a/modules/process/manager_test.go +++ b/modules/process/manager_test.go @@ -3,6 +3,7 @@ package process import ( "os/exec" "testing" + "time" "github.com/stretchr/testify/assert" ) @@ -31,3 +32,27 @@ func TestManager_Remove(t *testing.T) { _, exists := pm.Processes[pid2] assert.False(t, exists, "PID %d is in the list but shouldn't", pid2) } + +func TestExecTimeoutNever(t *testing.T) { + + // TODO Investigate how to improve the time elapsed per round. + maxLoops := 10 + for i := 1; i < maxLoops; i++ { + _, stderr, err := GetManager().ExecTimeout(5*time.Second, "ExecTimeout", "git", "--version") + if err != nil { + t.Fatalf("git --version: %v(%s)", err, stderr) + } + } +} + +func TestExecTimeoutAlways(t *testing.T) { + + maxLoops := 100 + for i := 1; i < maxLoops; i++ { + _, stderr, err := GetManager().ExecTimeout(100*time.Microsecond, "ExecTimeout", "sleep", "5") + // TODO Simplify logging and errors to get precise error type. E.g. checking "if err != context.DeadlineExceeded". + if err == nil { + t.Fatalf("sleep 5 secs: %v(%s)", err, stderr) + } + } +} |