diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index b79d1fa09..7ccb84011 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -33,13 +33,12 @@ jobs: test: name: Tests - runs-on: ubuntu-latest - needs: supportedVersions - strategy: matrix: go_version: ${{ fromJSON(needs.supportedVersions.outputs.supported_versions) }} - + os: [ubuntu-latest, macos-latest, windows-latest] # Matrix for OS + runs-on: ${{ matrix.os }} + needs: supportedVersions steps: - name: Checkout code uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 @@ -54,12 +53,29 @@ jobs: uses: actions/cache@v4 with: path: ~/go/pkg/mod - key: v1-go${{ matrix.go_version }} + key: v1-go${{ matrix.go_version }}-${{ matrix.os }} + + - name: Set environment variables for platform without cgo + run: | + echo "Setting environment variables for ${{ matrix.os }}" + if [[ ${{ matrix.os }} == 'macos-latest' ]]; then + echo "GOOS=darwin" >> $GITHUB_ENV + echo "GOARCH=amd64" >> $GITHUB_ENV + elif [[ ${{ matrix.os }} == 'windows-latest' ]]; then + echo "GOOS=windows" >> $GITHUB_ENV + echo "GOARCH=amd64" >> $GITHUB_ENV + echo "TMPDIR=C:\\Temp" >> $GITHUB_ENV + elif [[ ${{ matrix.os }} == 'ubuntu-latest' ]]; then + echo "GOOS=linux" >> $GITHUB_ENV + echo "GOARCH=amd64" >> $GITHUB_ENV + fi + shell: bash - name: Run tests and check license run: make check_license test env: CI: true + CGO_ENABLED: 1 - name: Run style and unused if: ${{ matrix.go_version == '1.22' }} diff --git a/prometheus/go_collector_test.go b/prometheus/go_collector_test.go index 47b944db5..7d2bed4d0 100644 --- a/prometheus/go_collector_test.go +++ b/prometheus/go_collector_test.go @@ -102,6 +102,10 @@ func TestGoCollectorGC(t *testing.T) { c.Collect(metricCh) // force GC runtime.GC() + // for windows, wait longer to make sure the garbage collection + if runtime.GOOS == "windows" { + time.Sleep(3 * time.Second) + } <-waitCh c.Collect(metricCh) close(endCollectionCh) @@ -148,7 +152,7 @@ func TestGoCollectorGC(t *testing.T) { if diff := *pb.GetSummary().SampleSum - oldPause; diff <= 0 { t.Errorf("want an increase in pause time, got a change of %f", diff) } - case <-time.After(1 * time.Second): + case <-time.After(4 * time.Second): t.Fatalf("expected collect timed out") } break diff --git a/prometheus/histogram_test.go b/prometheus/histogram_test.go index 1a19df2e2..0420b676f 100644 --- a/prometheus/histogram_test.go +++ b/prometheus/histogram_test.go @@ -55,6 +55,11 @@ func benchmarkHistogramObserve(w int, b *testing.B) { }() } + // Extra delay for Windows to ensure synchronization + if runtime.GOOS == "windows" { + time.Sleep(50 * time.Millisecond) + } + b.StartTimer() g.Done() wg.Wait() diff --git a/prometheus/process_collector_windows_test.go b/prometheus/process_collector_windows_test.go index 670c0fc53..1d590d132 100644 --- a/prometheus/process_collector_windows_test.go +++ b/prometheus/process_collector_windows_test.go @@ -51,14 +51,12 @@ func TestWindowsProcessCollector(t *testing.T) { regexp.MustCompile("\nprocess_cpu_seconds_total [0-9]"), regexp.MustCompile("\nprocess_max_fds [1-9]"), regexp.MustCompile("\nprocess_open_fds [1-9]"), - regexp.MustCompile("\nprocess_virtual_memory_max_bytes (-1|[1-9])"), regexp.MustCompile("\nprocess_virtual_memory_bytes [1-9]"), regexp.MustCompile("\nprocess_resident_memory_bytes [1-9]"), regexp.MustCompile("\nprocess_start_time_seconds [0-9.]{10,}"), regexp.MustCompile("\nfoobar_process_cpu_seconds_total [0-9]"), regexp.MustCompile("\nfoobar_process_max_fds [1-9]"), regexp.MustCompile("\nfoobar_process_open_fds [1-9]"), - regexp.MustCompile("\nfoobar_process_virtual_memory_max_bytes (-1|[1-9])"), regexp.MustCompile("\nfoobar_process_virtual_memory_bytes [1-9]"), regexp.MustCompile("\nfoobar_process_resident_memory_bytes [1-9]"), regexp.MustCompile("\nfoobar_process_start_time_seconds [0-9.]{10,}"), diff --git a/prometheus/timer_test.go b/prometheus/timer_test.go index a27912dbe..632bbef25 100644 --- a/prometheus/timer_test.go +++ b/prometheus/timer_test.go @@ -16,6 +16,7 @@ package prometheus import ( "reflect" "testing" + "time" "google.golang.org/protobuf/proto" @@ -33,6 +34,10 @@ func TestTimerObserve(t *testing.T) { hisTimer := NewTimer(his) sumTimer := NewTimer(sum) gaugeTimer := NewTimer(ObserverFunc(gauge.Set)) + + // Allow a little delay before observations to help on Windows. + time.Sleep(time.Millisecond * 10) + defer hisTimer.ObserveDuration() defer sumTimer.ObserveDuration() defer gaugeTimer.ObserveDuration()