mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-10-17 18:19:04 +02:00
56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
// Copyright The Prometheus Authors
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
//go:build windows
|
|
|
|
package net_test
|
|
|
|
import (
|
|
"log/slog"
|
|
"sync"
|
|
"testing"
|
|
|
|
"github.com/prometheus-community/windows_exporter/internal/collector/net"
|
|
"github.com/prometheus-community/windows_exporter/internal/utils/testutils"
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// BenchmarkCollector builds the collector from its config instead of
|
|
// testutils.FuncBenchmarkCollector, which doesn't parse the flags and so
|
|
// leaves every sub collector disabled.
|
|
func BenchmarkCollector(b *testing.B) {
|
|
c := net.New(nil)
|
|
require.NoError(b, c.Build(slog.New(slog.DiscardHandler), nil))
|
|
|
|
metrics := make(chan prometheus.Metric)
|
|
|
|
var wg sync.WaitGroup
|
|
wg.Go(func() {
|
|
for range metrics {
|
|
}
|
|
})
|
|
b.Cleanup(func() {
|
|
close(metrics)
|
|
wg.Wait()
|
|
assert.NoError(b, c.Close())
|
|
})
|
|
|
|
for b.Loop() {
|
|
require.NoError(b, testutils.Collect(c, metrics, 0))
|
|
}
|
|
}
|