Fix targetpool_test.go and other tests.

Change-Id: I91a4dd1d39e01f174e1aaae653ce1ed7aecaa624
This commit is contained in:
Bjoern Rabenstein 2014-10-08 16:22:54 +02:00
parent fd34e4061d
commit 38fc24d0ed
6 changed files with 19 additions and 8 deletions

View file

@ -91,11 +91,8 @@ func testTargetPool(t testing.TB) {
t.Errorf("%s %d. expected TargetPool size to be %d but was %d", scenario.name, i, len(scenario.outputs), len(pool.targetsByAddress))
} else {
for j, output := range scenario.outputs {
target := pool.Targets()[j]
if target.Address() != output.address {
if target, ok := pool.targetsByAddress[output.address]; !ok {
t.Errorf("%s %d.%d. expected Target address to be %s but was %s", scenario.name, i, j, output.address, target.Address())
}
}

View file

@ -64,6 +64,7 @@ func storeMatrix(storage local.Storage, matrix ast.Matrix) {
}
}
storage.AppendSamples(pendingSamples)
storage.WaitForIndexing()
}
var testMatrix = ast.Matrix{

View file

@ -44,6 +44,10 @@ type Storage interface {
Serve(started chan<- bool)
// Close the MetricsStorage and releases all resources.
Close() error
// WaitForIndexing returns once all samples in the storage are
// indexed. Indexing is needed for GetFingerprintsForLabelMatchers and
// GetLabelValuesForLabelName and may lag behind.
WaitForIndexing()
}
// SeriesIterator enables efficient access of sample values in a series. All

View file

@ -533,6 +533,9 @@ func (it *memorySeriesIterator) GetValueAtTime(t clientmodel.Timestamp) metric.V
// GetBoundaryValues implements SeriesIterator.
func (it *memorySeriesIterator) GetBoundaryValues(in metric.Interval) metric.Values {
return it.GetRangeValues(in)
// TODO: The following doesn't work as expected. Fix it.
it.lock()
defer it.unlock()

View file

@ -238,6 +238,11 @@ func (s *memorySeriesStorage) handlePersistQueue() {
s.persistDone <- true
}
// WaitForIndexing implements Storage.
func (s *memorySeriesStorage) WaitForIndexing() {
s.persistence.waitForIndexing()
}
// Close stops serving, flushes all pending operations, and frees all
// resources. It implements Storage.
func (s *memorySeriesStorage) Close() error {

View file

@ -168,8 +168,9 @@ func TestTemplateExpansion(t *testing.T) {
Value: 21,
},
})
storage.WaitForIndexing()
for _, s := range scenarios {
for i, s := range scenarios {
var result string
var err error
expander := NewTemplateExpander(s.text, "test", s.input, time, storage)
@ -180,16 +181,16 @@ func TestTemplateExpansion(t *testing.T) {
}
if s.shouldFail {
if err == nil {
t.Fatalf("Error not returned from %v", s.text)
t.Fatalf("%d. Error not returned from %v", i, s.text)
}
continue
}
if err != nil {
t.Fatalf("Error returned from %v: %v", s.text, err)
t.Fatalf("%d. Error returned from %v: %v", i, s.text, err)
continue
}
if result != s.output {
t.Fatalf("Error in result from %v: Expected '%v' Got '%v'", s.text, s.output, result)
t.Fatalf("%d. Error in result from %v: Expected '%v' Got '%v'", i, s.text, s.output, result)
continue
}
}