(t *testing.T)
| 37 | } |
| 38 | |
| 39 | func TestWaitForDaemonStartReadiness(t *testing.T) { |
| 40 | t.Parallel() |
| 41 | |
| 42 | t.Run("Should timeout when child stays alive and readiness never succeeds", func(t *testing.T) { |
| 43 | t.Parallel() |
| 44 | |
| 45 | child := &timeoutDaemonProcess{done: make(chan struct{})} |
| 46 | deps := newTestDeps(t, &stubClient{ |
| 47 | daemonStatusFn: func(context.Context) (DaemonStatus, error) { |
| 48 | return DaemonStatus{}, errors.New("daemon unavailable") |
| 49 | }, |
| 50 | }) |
| 51 | deps.pollInterval = time.Millisecond |
| 52 | deps.startTimeout = 5 * time.Millisecond |
| 53 | deps.processAlive = func(int) bool { return true } |
| 54 | |
| 55 | _, err := waitForDaemonStart(testutil.Context(t), deps, child) |
| 56 | if err == nil || !strings.Contains(err.Error(), "daemon did not become ready before timeout") { |
| 57 | t.Fatalf("waitForDaemonStart() error = %v, want readiness timeout", err) |
| 58 | } |
| 59 | if calls := child.waitCalls.Load(); calls != 0 { |
| 60 | t.Fatalf("process.Wait() calls = %d, want 0 before child exit", calls) |
| 61 | } |
| 62 | child.complete(nil) |
| 63 | }) |
| 64 | |
| 65 | t.Run("Should return child wait error when detached daemon exits before readiness", func(t *testing.T) { |
| 66 | t.Parallel() |
| 67 | |
| 68 | waitErr := errors.New("exit status 2") |
| 69 | child := &timeoutDaemonProcess{done: make(chan struct{})} |
| 70 | deps := newTestDeps(t, &stubClient{ |
| 71 | daemonStatusFn: func(context.Context) (DaemonStatus, error) { |
| 72 | return DaemonStatus{}, errors.New("daemon unavailable") |
| 73 | }, |
| 74 | }) |
| 75 | deps.pollInterval = time.Millisecond |
| 76 | deps.startTimeout = 100 * time.Millisecond |
| 77 | deps.processAlive = func(int) bool { return true } |
| 78 | child.complete(waitErr) |
| 79 | |
| 80 | _, err := waitForDaemonStart(testutil.Context(t), deps, child) |
| 81 | if !errors.Is(err, waitErr) { |
| 82 | t.Fatalf("waitForDaemonStart() error = %v, want child wait error", err) |
| 83 | } |
| 84 | if !strings.Contains(err.Error(), "detached daemon exited before readiness") { |
| 85 | t.Fatalf("waitForDaemonStart() error = %v, want detached exit context", err) |
| 86 | } |
| 87 | if calls := child.waitCalls.Load(); calls != 1 { |
| 88 | t.Fatalf("process.Wait() calls = %d, want 1", calls) |
| 89 | } |
| 90 | }) |
| 91 | } |
nothing calls this directly
no test coverage detected