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

Commit

Permalink
fix windows tests (#469)
Browse files Browse the repository at this point in the history
Signed-off-by: Krasi Georgiev <[email protected]>
  • Loading branch information
krasi-georgiev authored Dec 13, 2018
1 parent a2779cc commit 2962202
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
9 changes: 8 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@
sudo: required
dist: trusty
language: go
os:
- windows
- linux
- osx

go:
- 1.10.x
- 1.11.x

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
3 changes: 1 addition & 2 deletions head.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
9 changes: 6 additions & 3 deletions head_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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...)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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.
Expand All @@ -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")

})
}
}
6 changes: 3 additions & 3 deletions wal/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand Down
9 changes: 1 addition & 8 deletions wal/wal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"os"
"testing"

"github.com/pkg/errors"
"github.com/prometheus/tsdb/testutil"
)

Expand Down Expand Up @@ -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")))

testutil.Ok(t, w.Repair(r.Err()))
sr, err = NewSegmentsReader(dir)
testutil.Ok(t, err)
r = NewReader(sr)
Expand Down
2 changes: 2 additions & 0 deletions wal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// +build !windows

package tsdb

import (
Expand Down

0 comments on commit 2962202

Please sign in to comment.