Skip to content

Commit db55a99

Browse files
[Internal] Some runner tests fail on macOS (#2879)
1 parent 7435ecf commit db55a99

File tree

3 files changed

+44
-10
lines changed

3 files changed

+44
-10
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ jobs:
123123
defaults:
124124
run:
125125
working-directory: runner
126-
runs-on: ubuntu-latest
126+
runs-on: ${{ matrix.os }}
127+
strategy:
128+
matrix:
129+
os: [ubuntu-latest, macos-latest]
127130
steps:
128131
- uses: actions/checkout@v4
129132
- name: Set up Go

runner/internal/executor/executor.go

Lines changed: 33 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"
@@ -27,6 +28,12 @@ import (
2728
"github.com/prometheus/procfs"
2829
)
2930

31+
type ConnectionTracker interface {
32+
GetNoConnectionsSecs() int64
33+
Track(ticker <-chan time.Time)
34+
Stop()
35+
}
36+
3037
type RunExecutor struct {
3138
tempDir string
3239
homeDir string
@@ -51,9 +58,16 @@ type RunExecutor struct {
5158
timestamp *MonotonicTimestamp
5259

5360
killDelay time.Duration
54-
connectionTracker *connections.ConnectionTracker
61+
connectionTracker ConnectionTracker
5562
}
5663

64+
// stubConnectionTracker is a no-op implementation for when procfs is not available (only required for tests on darwin)
65+
type stubConnectionTracker struct{}
66+
67+
func (s *stubConnectionTracker) GetNoConnectionsSecs() int64 { return 0 }
68+
func (s *stubConnectionTracker) Track(ticker <-chan time.Time) {}
69+
func (s *stubConnectionTracker) Stop() {}
70+
5771
func NewRunExecutor(tempDir string, homeDir string, workingDir string, sshPort int) (*RunExecutor, error) {
5872
mu := &sync.RWMutex{}
5973
timestamp := NewMonotonicTimestamp()
@@ -65,15 +79,25 @@ func NewRunExecutor(tempDir string, homeDir string, workingDir string, sshPort i
6579
if err != nil {
6680
return nil, fmt.Errorf("failed to parse current user uid: %w", err)
6781
}
68-
proc, err := procfs.NewDefaultFS()
69-
if err != nil {
70-
return nil, fmt.Errorf("failed to initialize procfs: %w", err)
82+
83+
// Try to initialize procfs, but don't fail if it's not available (e.g., on macOS)
84+
var connectionTracker ConnectionTracker
85+
86+
if runtime.GOOS == "linux" {
87+
proc, err := procfs.NewDefaultFS()
88+
if err != nil {
89+
return nil, fmt.Errorf("failed to initialize procfs: %w", err)
90+
}
91+
connectionTracker = connections.NewConnectionTracker(connections.ConnectionTrackerConfig{
92+
Port: uint64(sshPort),
93+
MinConnDuration: 10 * time.Second, // shorter connections are likely from dstack-server
94+
Procfs: proc,
95+
})
96+
} else {
97+
// Use stub connection tracker (only required for tests on darwin)
98+
connectionTracker = &stubConnectionTracker{}
7199
}
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-
})
100+
77101
return &RunExecutor{
78102
tempDir: tempDir,
79103
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)