mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-14 09:34:05 -08:00
c3b282bd14
- Most of this is the actual regression test in tiered_test.go. - Working on that regression tests uncovered problems in tiered_test.go that are fixed in this commit. - The 'op.consumed = false' line added to freelist.go was actually not fixing a bug. Instead, there was no bug at all. So this commit removes that line again, but adds a regression test to make sure that the assumed bug is indeed not there (cf. freelist_test.go). - Removed more code duplication in operation.go (following the same approach as before, i.e. embedding op type A into op type B if everything in A is the same as in B with the exception of String() and ExtractSample()). (This change make struct literals for ops more clunky, but that only affects tests. No code change whatsoever was necessary in the actual code after this refactoring.) - Fix another op leak in tiered.go. Change-Id: Ia165c52e33290ad4f6aba9c83d92318d4f583517
38 lines
1.2 KiB
Go
38 lines
1.2 KiB
Go
// Copyright 2014 Prometheus Team
|
|
// 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 metric
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/prometheus/client_golang/model"
|
|
)
|
|
|
|
// TestValueAtTimeListGet tests if the timestamp is set properly in the op
|
|
// retrieved from the free list and if the 'consumed' member is zeroed properly.
|
|
func TestValueAtTimeListGet(t *testing.T) {
|
|
l := newValueAtTimeList(1)
|
|
op := l.Get(&model.Fingerprint{}, 42)
|
|
op.consumed = true
|
|
l.Give(op)
|
|
|
|
op2 := l.Get(&model.Fingerprint{}, 4711)
|
|
if op2.Consumed() {
|
|
t.Error("Op retrieved from freelist is already consumed.")
|
|
}
|
|
if got, expected := op2.CurrentTime(), model.Timestamp(4711); got != expected {
|
|
t.Errorf("op2.CurrentTime() = %d; want %d.", got, expected)
|
|
}
|
|
}
|