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_race_test.go 905B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. //go:build race
  4. package git
  5. import (
  6. "context"
  7. "testing"
  8. "time"
  9. )
  10. func TestRunWithContextNoTimeout(t *testing.T) {
  11. maxLoops := 10
  12. // 'git --version' does not block so it must be finished before the timeout triggered.
  13. cmd := NewCommand(context.Background(), "--version")
  14. for i := 0; i < maxLoops; i++ {
  15. if err := cmd.Run(&RunOpts{}); err != nil {
  16. t.Fatal(err)
  17. }
  18. }
  19. }
  20. func TestRunWithContextTimeout(t *testing.T) {
  21. maxLoops := 10
  22. // 'git hash-object --stdin' blocks on stdin so we can have the timeout triggered.
  23. cmd := NewCommand(context.Background(), "hash-object", "--stdin")
  24. for i := 0; i < maxLoops; i++ {
  25. if err := cmd.Run(&RunOpts{Timeout: 1 * time.Millisecond}); err != nil {
  26. if err != context.DeadlineExceeded {
  27. t.Fatalf("Testing %d/%d: %v", i, maxLoops, err)
  28. }
  29. }
  30. }
  31. }