Skip to content

Commit cd9aa72

Browse files
[Internal] Some runner tests fail on macOS #2878
1 parent eba15c2 commit cd9aa72

2 files changed

Lines changed: 42 additions & 9 deletions

File tree

runner/internal/executor/executor.go

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"os/exec"
1212
osuser "os/user"
1313
"path/filepath"
14+
"runtime"
1415
"strconv"
1516
"strings"
1617
"sync"
@@ -51,9 +52,20 @@ type RunExecutor struct {
5152
timestamp *MonotonicTimestamp
5253

5354
killDelay time.Duration
54-
connectionTracker *connections.ConnectionTracker
55+
connectionTracker interface {
56+
GetNoConnectionsSecs() int64
57+
Track(ticker <-chan time.Time)
58+
Stop()
59+
}
5560
}
5661

62+
// stubConnectionTracker is a no-op implementation for when procfs is not available (only required for tests on darwin)
63+
type stubConnectionTracker struct{}
64+
65+
func (s *stubConnectionTracker) GetNoConnectionsSecs() int64 { return 0 }
66+
func (s *stubConnectionTracker) Track(ticker <-chan time.Time) {}
67+
func (s *stubConnectionTracker) Stop() {}
68+
5769
func NewRunExecutor(tempDir string, homeDir string, workingDir string, sshPort int) (*RunExecutor, error) {
5870
mu := &sync.RWMutex{}
5971
timestamp := NewMonotonicTimestamp()
@@ -65,15 +77,29 @@ func NewRunExecutor(tempDir string, homeDir string, workingDir string, sshPort i
6577
if err != nil {
6678
return nil, fmt.Errorf("failed to parse current user uid: %w", err)
6779
}
68-
proc, err := procfs.NewDefaultFS()
69-
if err != nil {
70-
return nil, fmt.Errorf("failed to initialize procfs: %w", err)
80+
81+
// Try to initialize procfs, but don't fail if it's not available (e.g., on macOS)
82+
var connectionTracker interface {
83+
GetNoConnectionsSecs() int64
84+
Track(ticker <-chan time.Time)
85+
Stop()
7186
}
72-
connectionTracker := connections.NewConnectionTracker(connections.ConnectionTrackerConfig{
73-
Port: uint64(sshPort),
74-
MinConnDuration: 10 * time.Second, // shorter connections are likely from dstack-server
75-
Procfs: proc,
76-
})
87+
88+
if runtime.GOOS == "linux" {
89+
proc, err := procfs.NewDefaultFS()
90+
if err != nil {
91+
return nil, fmt.Errorf("failed to initialize procfs: %w", err)
92+
}
93+
connectionTracker = connections.NewConnectionTracker(connections.ConnectionTrackerConfig{
94+
Port: uint64(sshPort),
95+
MinConnDuration: 10 * time.Second, // shorter connections are likely from dstack-server
96+
Procfs: proc,
97+
})
98+
} else {
99+
// Use stub connection tracker (only required for tests on darwin)
100+
connectionTracker = &stubConnectionTracker{}
101+
}
102+
77103
return &RunExecutor{
78104
tempDir: tempDir,
79105
homeDir: homeDir,

runner/internal/metrics/metrics_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package metrics
22

33
import (
4+
"runtime"
45
"testing"
56

67
"github.com/dstackai/dstack/runner/internal/schemas"
78
"github.com/stretchr/testify/assert"
89
)
910

1011
func TestGetAMDGPUMetrics_OK(t *testing.T) {
12+
if runtime.GOOS == "darwin" {
13+
t.Skip("Skipping on macOS")
14+
}
1115
collector, err := NewMetricsCollector()
1216
assert.NoError(t, err)
1317

@@ -39,6 +43,9 @@ func TestGetAMDGPUMetrics_OK(t *testing.T) {
3943
}
4044

4145
func TestGetAMDGPUMetrics_ErrorGPUUtilNA(t *testing.T) {
46+
if runtime.GOOS == "darwin" {
47+
t.Skip("Skipping on macOS")
48+
}
4249
collector, err := NewMetricsCollector()
4350
assert.NoError(t, err)
4451
metrics, err := collector.getAMDGPUMetrics("gpu,gfx,gfx_clock,vram_used,vram_total\n0,N/A,N/A,283,196300\n")

0 commit comments

Comments
 (0)