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

Add tests for RunInDirTimeoutPipeline #42

Merged
merged 1 commit into from
Apr 8, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions command_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

// +build race

package git

import (
"testing"
"time"
)

func TestRunInDirTimeoutPipelineNoTimeout(t *testing.T) {

maxLoops := 1000

// 'git --version' does not block so it must be finished before the timeout triggered.
cmd := NewCommand("--version")
for i := 0; i < maxLoops; i++ {
if err := cmd.RunInDirTimeoutPipeline(-1, "", nil, nil); err != nil {
t.Fatal(err)
}
}
}

func TestRunInDirTimeoutPipelineAlwaysTimeout(t *testing.T) {

maxLoops := 1000

// 'git hash-object --stdin' blocks on stdin so we can have the timeout triggered.
cmd := NewCommand("hash-object --stdin")
for i := 0; i < maxLoops; i++ {
if err := cmd.RunInDirTimeoutPipeline(1*time.Microsecond, "", nil, nil); err != nil {
// 'context deadline exceeded' when the error is returned by exec.Start
// 'signal: killed' when the error is returned by exec.Wait
// It depends on the point of the time (before or after exec.Start returns) at which the timeout is triggered.
if err.Error() != "context deadline exceeded" && err.Error() != "signal: killed" {
t.Fatalf("Testing %d/%d: %v", i, maxLoops, err)
}
}
}
}