You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

command_test.go 1017B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. //go:build race
  5. // +build race
  6. package git
  7. import (
  8. "context"
  9. "testing"
  10. "time"
  11. )
  12. func TestRunInDirTimeoutPipelineNoTimeout(t *testing.T) {
  13. maxLoops := 1000
  14. // 'git --version' does not block so it must be finished before the timeout triggered.
  15. cmd := NewCommand("--version")
  16. for i := 0; i < maxLoops; i++ {
  17. if err := cmd.RunInDirTimeoutPipeline(-1, "", nil, nil); err != nil {
  18. t.Fatal(err)
  19. }
  20. }
  21. }
  22. func TestRunInDirTimeoutPipelineAlwaysTimeout(t *testing.T) {
  23. maxLoops := 1000
  24. // 'git hash-object --stdin' blocks on stdin so we can have the timeout triggered.
  25. cmd := NewCommand("hash-object", "--stdin")
  26. for i := 0; i < maxLoops; i++ {
  27. if err := cmd.RunInDirTimeoutPipeline(1*time.Microsecond, "", nil, nil); err != nil {
  28. if err != context.DeadlineExceeded {
  29. t.Fatalf("Testing %d/%d: %v", i, maxLoops, err)
  30. }
  31. }
  32. }
  33. }