fix windows tests (#469)

Signed-off-by: Krasi Georgiev <kgeorgie@redhat.com>
This commit is contained in:
Krasi Georgiev 2018-12-13 16:29:29 +03:00 committed by GitHub
parent a2779cc901
commit 2962202ed3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 17 deletions

View File

@ -2,6 +2,10 @@
sudo: required
dist: trusty
language: go
os:
- windows
- linux
- osx
go:
- 1.10.x
@ -9,9 +13,12 @@ go:
go_import_path: github.com/prometheus/tsdb
before_install:
- if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then choco install make; fi
install:
- go get -v -t ./...
script:
# `staticcheck` target is omitted due to linting errors
- make check_license style unused test
- if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then make test; else make style unused test; fi

View File

@ -473,14 +473,13 @@ func (h *Head) Init(minValidTime int64) error {
if err != nil {
return errors.Wrap(err, "open WAL segments")
}
defer sr.Close()
err = h.loadWAL(wal.NewReader(sr))
sr.Close() // Close the reader so that if there was an error the repair can remove the corrupted file under Windows.
if err == nil {
return nil
}
level.Warn(h.logger).Log("msg", "encountered WAL error, attempting repair", "err", err)
if err := h.wal.Repair(err); err != nil {
return errors.Wrap(err, "repair corrupted WAL")
}

View File

@ -118,11 +118,11 @@ func TestHead_ReadWAL(t *testing.T) {
w, err := wal.New(nil, nil, dir)
testutil.Ok(t, err)
defer w.Close()
populateTestWAL(t, w, entries)
head, err := NewHead(nil, nil, w, 1000)
testutil.Ok(t, err)
defer head.Close()
testutil.Ok(t, head.Init(math.MinInt64))
testutil.Equals(t, uint64(100), head.lastSeriesID)
@ -282,11 +282,11 @@ func TestHeadDeleteSeriesWithoutSamples(t *testing.T) {
w, err := wal.New(nil, nil, dir)
testutil.Ok(t, err)
defer w.Close()
populateTestWAL(t, w, entries)
head, err := NewHead(nil, nil, w, 1000)
testutil.Ok(t, err)
defer head.Close()
testutil.Ok(t, head.Init(math.MinInt64))
@ -389,6 +389,7 @@ Outer:
func TestDeleteUntilCurMax(t *testing.T) {
numSamples := int64(10)
hb, err := NewHead(nil, nil, nil, 1000000)
defer hb.Close()
testutil.Ok(t, err)
app := hb.Appender()
smpls := make([]float64, numSamples)
@ -478,6 +479,7 @@ func TestDelete_e2e(t *testing.T) {
defer os.RemoveAll(dir)
hb, err := NewHead(nil, nil, nil, 100000)
testutil.Ok(t, err)
defer hb.Close()
app := hb.Appender()
for _, l := range lbls {
ls := labels.New(l...)
@ -845,6 +847,7 @@ func TestHead_LogRollback(t *testing.T) {
w, err := wal.New(nil, nil, dir)
testutil.Ok(t, err)
defer w.Close()
h, err := NewHead(nil, nil, w, 1000)
testutil.Ok(t, err)
@ -911,6 +914,7 @@ func TestWalRepair(t *testing.T) {
w, err := wal.New(nil, nil, dir)
testutil.Ok(t, err)
defer w.Close()
for i := 1; i <= test.totalRecs; i++ {
// At this point insert a corrupted record.
@ -936,7 +940,6 @@ func TestWalRepair(t *testing.T) {
}
testutil.Ok(t, r.Err())
testutil.Equals(t, test.expRecs, actRec, "Wrong number of intact records")
})
}
}

View File

@ -298,9 +298,6 @@ func (w *WAL) Repair(origErr error) error {
level.Warn(w.logger).Log("msg", "deleting all segments behind corruption", "segment", cerr.Segment)
for _, s := range segs {
if s.index <= cerr.Segment {
continue
}
if w.segment.i == s.index {
// The active segment needs to be removed,
// close it first (Windows!). Can be closed safely
@ -310,6 +307,9 @@ func (w *WAL) Repair(origErr error) error {
return errors.Wrap(err, "close active segment")
}
}
if s.index <= cerr.Segment {
continue
}
if err := os.Remove(filepath.Join(w.dir, s.name)); err != nil {
return errors.Wrapf(err, "delete segment:%v", s.index)
}

View File

@ -23,7 +23,6 @@ import (
"os"
"testing"
"github.com/pkg/errors"
"github.com/prometheus/tsdb/testutil"
)
@ -336,14 +335,8 @@ func TestWAL_Repair(t *testing.T) {
}
testutil.NotOk(t, r.Err())
testutil.Ok(t, sr.Close())
testutil.Ok(t, w.Repair(r.Err()))
// See https://github.com/prometheus/prometheus/issues/4603
// We need to close w.segment because it needs to be deleted.
// But this is to mainly artificially test Repair() again.
testutil.Ok(t, w.segment.Close())
testutil.Ok(t, w.Repair(errors.Wrap(r.Err(), "err")))
sr, err = NewSegmentsReader(dir)
testutil.Ok(t, err)
r = NewReader(sr)

View File

@ -11,6 +11,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// +build !windows
package tsdb
import (