From aa96c7d1418ccfb444f148169b654366cedc152f Mon Sep 17 00:00:00 2001 From: Bernerd Schaefer Date: Tue, 14 May 2013 16:55:18 +0200 Subject: [PATCH] Fix rules_test.go This is smelly, but for now we copy a helper method from the metric tests into rules. --- rules/rules_test.go | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/rules/rules_test.go b/rules/rules_test.go index 6ade851af..c7a69af61 100644 --- a/rules/rules_test.go +++ b/rules/rules_test.go @@ -49,8 +49,46 @@ func vectorComparisonString(expected []string, actual []string) string { separator) } +type testTieredStorageCloser struct { + storage *metric.TieredStorage + directory test.Closer +} + +func (t testTieredStorageCloser) Close() { + t.storage.Close() + t.directory.Close() +} + +// This is copied from storage/metric/helpers_test.go, which is unfortunate but +// presently required to make things work. +func NewTestTieredStorage(t test.Tester) (storage *metric.TieredStorage, closer test.Closer) { + var directory test.TemporaryDirectory + directory = test.NewTemporaryDirectory("test_tiered_storage", t) + storage, err := metric.NewTieredStorage(2500, 1000, 5*time.Second, 15*time.Second, 0*time.Second, directory.Path()) + + if err != nil { + if storage != nil { + storage.Close() + } + directory.Close() + t.Fatalf("Error creating storage: %s", err) + } + + if storage == nil { + directory.Close() + t.Fatalf("storage == nil") + } + + go storage.Serve() + closer = &testTieredStorageCloser{ + storage: storage, + directory: directory, + } + return +} + func newTestStorage(t test.Tester) (storage *metric.TieredStorage, closer test.Closer) { - storage, closer = metric.NewTestTieredStorage(t) + storage, closer = NewTestTieredStorage(t) if storage == nil { t.Fatal("storage == nil") }