Skip to content
This repository has been archived by the owner on Aug 13, 2019. It is now read-only.

Commit

Permalink
Fix circular import
Browse files Browse the repository at this point in the history
  • Loading branch information
obitech committed Aug 4, 2019
1 parent 5bd9d4d commit 370bc8e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
6 changes: 3 additions & 3 deletions cmd/tsdb/main_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 The Prometheus Authors
// Copyright 2019 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
Expand All @@ -23,7 +23,7 @@ import (
"text/tabwriter"

"github.com/prometheus/tsdb"
"github.com/prometheus/tsdb/testutil"
testutildb "github.com/prometheus/tsdb/testutil/db"
)

func createTestRODBWithBlock(t *testing.T) (*tsdb.DBReadOnly, func()) {
Expand All @@ -36,7 +36,7 @@ func createTestRODBWithBlock(t *testing.T) (*tsdb.DBReadOnly, func()) {
safeDBOptions := *tsdb.DefaultOptions
safeDBOptions.RetentionDuration = 0

testutil.CreateBlock(nil, tmpdir, testutil.GenSeries(1, 1, 0, 1))
testutildb.CreateBlock(nil, tmpdir, testutildb.GenSeries(1, 1, 0, 1))
db, err := tsdb.Open(tmpdir, nil, nil, &safeDBOptions)
if err != nil {
os.RemoveAll(tmpdir)
Expand Down
46 changes: 23 additions & 23 deletions testutil/db.go → testutil/db/db.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
package testutil
// Copyright 2019 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 db

import (
"context"
"io/ioutil"
"math/rand"
"os"
"path/filepath"
Expand All @@ -11,43 +23,31 @@ import (
"testing"

"github.com/go-kit/kit/log"

"github.com/prometheus/tsdb"
"github.com/prometheus/tsdb/labels"
"github.com/prometheus/tsdb/testutil"
"github.com/prometheus/tsdb/tsdbutil"
)

// OpenTestDB opens a test Database
func OpenTestDB(t testing.TB, opts *tsdb.Options) (db *tsdb.DB, close func()) {
tmpdir, err := ioutil.TempDir("", "test")
Ok(t, err)

db, err = tsdb.Open(tmpdir, nil, nil, opts)
Ok(t, err)

// Do not close the test database by default as it will deadlock on test failures.
return db, func() {
Ok(t, os.RemoveAll(tmpdir))
}
}

// CreateBlock creates a block with given set of series and returns its dir.
func CreateBlock(tb testing.TB, dir string, series []tsdb.Series) string {
head := createHead(tb, series)
compactor, err := tsdb.NewLeveledCompactor(context.Background(), nil, log.NewNopLogger(), []int64{1000000}, nil)
Ok(tb, err)
testutil.Ok(tb, err)

Ok(tb, os.MkdirAll(dir, 0777))
testutil.Ok(tb, os.MkdirAll(dir, 0777))

// Add +1 millisecond to block maxt because block intervals are half-open: [b.MinTime, b.MaxTime).
// Because of this block intervals are always +1 than the total samples it includes.
ulid, err := compactor.Write(dir, head, head.MinTime(), head.MaxTime()+1, nil)
Ok(tb, err)
testutil.Ok(tb, err)
return filepath.Join(dir, ulid.String())
}

func createHead(tb testing.TB, series []tsdb.Series) *tsdb.Head {
head, err := tsdb.NewHead(nil, nil, nil, 2*60*60*1000)
Ok(tb, err)
testutil.Ok(tb, err)
defer head.Close()

app := head.Appender()
Expand All @@ -63,12 +63,12 @@ func createHead(tb testing.TB, series []tsdb.Series) *tsdb.Head {
}
}
ref, err = app.Add(s.Labels(), t, v)
Ok(tb, err)
testutil.Ok(tb, err)
}
Ok(tb, it.Err())
testutil.Ok(tb, it.Err())
}
err = app.Commit()
Ok(tb, err)
testutil.Ok(tb, err)
return head
}

Expand Down

0 comments on commit 370bc8e

Please sign in to comment.