Fix targetpool_test.go and other tests.
Change-Id: I91a4dd1d39e01f174e1aaae653ce1ed7aecaa624
This commit is contained in:
		
							parent
							
								
									fd34e4061d
								
							
						
					
					
						commit
						38fc24d0ed
					
				|  | @ -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)) | 			t.Errorf("%s %d. expected TargetPool size to be %d but was %d", scenario.name, i, len(scenario.outputs), len(pool.targetsByAddress)) | ||||||
| 		} else { | 		} else { | ||||||
| 			for j, output := range scenario.outputs { | 			for j, output := range scenario.outputs { | ||||||
| 				target := pool.Targets()[j] | 				if target, ok := pool.targetsByAddress[output.address]; !ok { | ||||||
| 
 |  | ||||||
| 				if target.Address() != output.address { |  | ||||||
| 					t.Errorf("%s %d.%d. expected Target address to be %s but was %s", scenario.name, i, j, output.address, target.Address()) | 					t.Errorf("%s %d.%d. expected Target address to be %s but was %s", scenario.name, i, j, output.address, target.Address()) | ||||||
| 
 |  | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -64,6 +64,7 @@ func storeMatrix(storage local.Storage, matrix ast.Matrix) { | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	storage.AppendSamples(pendingSamples) | 	storage.AppendSamples(pendingSamples) | ||||||
|  | 	storage.WaitForIndexing() | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| var testMatrix = ast.Matrix{ | var testMatrix = ast.Matrix{ | ||||||
|  |  | ||||||
|  | @ -44,6 +44,10 @@ type Storage interface { | ||||||
| 	Serve(started chan<- bool) | 	Serve(started chan<- bool) | ||||||
| 	// Close the MetricsStorage and releases all resources.
 | 	// Close the MetricsStorage and releases all resources.
 | ||||||
| 	Close() error | 	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
 | // SeriesIterator enables efficient access of sample values in a series. All
 | ||||||
|  |  | ||||||
|  | @ -533,6 +533,9 @@ func (it *memorySeriesIterator) GetValueAtTime(t clientmodel.Timestamp) metric.V | ||||||
| 
 | 
 | ||||||
| // GetBoundaryValues implements SeriesIterator.
 | // GetBoundaryValues implements SeriesIterator.
 | ||||||
| func (it *memorySeriesIterator) GetBoundaryValues(in metric.Interval) metric.Values { | 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() | 	it.lock() | ||||||
| 	defer it.unlock() | 	defer it.unlock() | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -238,6 +238,11 @@ func (s *memorySeriesStorage) handlePersistQueue() { | ||||||
| 	s.persistDone <- true | 	s.persistDone <- true | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // WaitForIndexing implements Storage.
 | ||||||
|  | func (s *memorySeriesStorage) WaitForIndexing() { | ||||||
|  | 	s.persistence.waitForIndexing() | ||||||
|  | } | ||||||
|  | 
 | ||||||
| // Close stops serving, flushes all pending operations, and frees all
 | // Close stops serving, flushes all pending operations, and frees all
 | ||||||
| // resources. It implements Storage.
 | // resources. It implements Storage.
 | ||||||
| func (s *memorySeriesStorage) Close() error { | func (s *memorySeriesStorage) Close() error { | ||||||
|  |  | ||||||
|  | @ -168,8 +168,9 @@ func TestTemplateExpansion(t *testing.T) { | ||||||
| 			Value: 21, | 			Value: 21, | ||||||
| 		}, | 		}, | ||||||
| 	}) | 	}) | ||||||
|  | 	storage.WaitForIndexing() | ||||||
| 
 | 
 | ||||||
| 	for _, s := range scenarios { | 	for i, s := range scenarios { | ||||||
| 		var result string | 		var result string | ||||||
| 		var err error | 		var err error | ||||||
| 		expander := NewTemplateExpander(s.text, "test", s.input, time, storage) | 		expander := NewTemplateExpander(s.text, "test", s.input, time, storage) | ||||||
|  | @ -180,16 +181,16 @@ func TestTemplateExpansion(t *testing.T) { | ||||||
| 		} | 		} | ||||||
| 		if s.shouldFail { | 		if s.shouldFail { | ||||||
| 			if err == nil { | 			if err == nil { | ||||||
| 				t.Fatalf("Error not returned from %v", s.text) | 				t.Fatalf("%d. Error not returned from %v", i, s.text) | ||||||
| 			} | 			} | ||||||
| 			continue | 			continue | ||||||
| 		} | 		} | ||||||
| 		if err != nil { | 		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 | 			continue | ||||||
| 		} | 		} | ||||||
| 		if result != s.output { | 		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 | 			continue | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue