1
0
mirror of https://github.com/prometheus-community/postgres_exporter.git synced 2026-10-23 12:08:57 +03:00
Files
postgres_exporter/exporter/server_test.go
maltere 261c0d217c Bound legacy queries by collection timeout (#1393)
* Bound legacy queries by collection timeout

Signed-off-by: Malte Reddig <maltere@users.noreply.github.com>

* fixup! Bound legacy queries by collection timeout

Signed-off-by: Malte Reddig <malte@namespacelabs.com>

* fixup! Bound legacy queries by collection timeout

Signed-off-by: Malte Reddig <malte@namespacelabs.com>

---------

Signed-off-by: Malte Reddig <maltere@users.noreply.github.com>
Signed-off-by: Malte Reddig <malte@namespacelabs.com>
Co-authored-by: Malte Reddig <maltere@users.noreply.github.com>
2026-09-23 10:04:37 -03:00

37 lines
1.2 KiB
Go

// 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.
package exporter
import (
"context"
"errors"
"testing"
"time"
)
func TestGetServerRetryHonorsContextCancellation(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Millisecond)
defer cancel()
started := time.Now()
_, err := NewServers().GetServer(ctx, "invalid dsn")
if !errors.Is(err, context.DeadlineExceeded) {
t.Fatalf("GetServer() error = %v, want context deadline exceeded", err)
}
if elapsed := time.Since(started); elapsed >= time.Second {
t.Fatalf("GetServer() returned after %v, want cancellation before retry delay completed", elapsed)
}
}