Skip to content

Commit

Permalink
*: fix gofmt errors and makefile test
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Romano committed Sep 13, 2017
1 parent a4199f8 commit e39821f
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 44 deletions.
13 changes: 8 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ default: build
race:
@go test -v -race -test.run="TestSimulate_(100op|1000op)"

# go get honnef.co/go/tools/simple
# go get honnef.co/go/tools/unused
fmt:
!(gofmt -l -s -d $(shell find . -name \*.go) | grep '[a-z]')

# go get honnef.co/go/tools/simple
gosimple:
gosimple ./...
unused ./...
gofmt -l -s -d $(find -name \*.go)

# go get honnef.co/go/tools/unused
unused:
unused ./...

# go get github.com/kisielk/errcheck
errcheck:
Expand All @@ -24,4 +27,4 @@ test:
# Note: gets "program not an importable package" in out of path builds
go test -v ./cmd/bolt

.PHONY: race fmt errcheck test
.PHONY: race fmt errcheck test gosimple unused
6 changes: 3 additions & 3 deletions bolt_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import (
func flock(db *DB, mode os.FileMode, exclusive bool, timeout time.Duration) error {
var t time.Time
if timeout != 0 {
t = time.Now()
t = time.Now()
}
fd := db.file.Fd()
flag := syscall.LOCK_NB
if exclusive {
flag |= syscall.LOCK_EX
} else {
flag |= syscall.LOCK_SH
flag |= syscall.LOCK_SH
}
for {
// Attempt to obtain an exclusive lock.
Expand All @@ -33,7 +33,7 @@ func flock(db *DB, mode os.FileMode, exclusive bool, timeout time.Duration) erro
}

// If we timed out then return an error.
if timeout != 0 && time.Since(t) > timeout - flockRetryTimeout {
if timeout != 0 && time.Since(t) > timeout-flockRetryTimeout {
return ErrTimeout
}

Expand Down
4 changes: 2 additions & 2 deletions bolt_unix_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func flock(db *DB, mode os.FileMode, exclusive bool, timeout time.Duration) error {
var t time.Time
if timeout != 0 {
t = time.Now()
t = time.Now()
}
fd := db.file.Fd()
var lockType int16
Expand All @@ -34,7 +34,7 @@ func flock(db *DB, mode os.FileMode, exclusive bool, timeout time.Duration) erro
}

// If we timed out then return an error.
if timeout != 0 && time.Since(t) > timeout - flockRetryTimeout {
if timeout != 0 && time.Since(t) > timeout-flockRetryTimeout {
return ErrTimeout
}

Expand Down
4 changes: 2 additions & 2 deletions bolt_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func flock(db *DB, mode os.FileMode, exclusive bool, timeout time.Duration) erro

var t time.Time
if timeout != 0 {
t = time.Now()
t = time.Now()
}
fd := db.file.Fd()
var flag uint32 = flagLockFailImmediately
Expand All @@ -77,7 +77,7 @@ func flock(db *DB, mode os.FileMode, exclusive bool, timeout time.Duration) erro
}

// If we timed oumercit then return an error.
if timeout != 0 && time.Since(t) > timeout - flockRetryTimeout {
if timeout != 0 && time.Since(t) > timeout-flockRetryTimeout {
return ErrTimeout
}

Expand Down
2 changes: 1 addition & 1 deletion db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ func TestDB_Open_ReadOnly(t *testing.T) {
// Read from a read-only transaction.
if err := readOnlyDB.View(func(tx *bolt.Tx) error {
value := tx.Bucket([]byte("widgets")).Get([]byte("foo"))
if bytes.Compare(value, []byte("bar")) != 0 {
if !bytes.Equal(value, []byte("bar")) {
t.Fatal("expect value 'bar', got", value)
}
return nil
Expand Down
62 changes: 31 additions & 31 deletions freelist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,83 +65,83 @@ func TestFreelist_releaseRange(t *testing.T) {
}{
{
title: "Single pending in range",
pagesIn: []testPage{testPage{id: 3, n: 1, allocTxn: 100, freeTxn: 200}},
releaseRanges: []testRange{testRange{1, 300}},
pagesIn: []testPage{{id: 3, n: 1, allocTxn: 100, freeTxn: 200}},
releaseRanges: []testRange{{1, 300}},
wantFree: []pgid{3},
},
{
title: "Single pending with minimum end range",
pagesIn: []testPage{testPage{id: 3, n: 1, allocTxn: 100, freeTxn: 200}},
releaseRanges: []testRange{testRange{1, 200}},
pagesIn: []testPage{{id: 3, n: 1, allocTxn: 100, freeTxn: 200}},
releaseRanges: []testRange{{1, 200}},
wantFree: []pgid{3},
},
{
title: "Single pending outsize minimum end range",
pagesIn: []testPage{testPage{id: 3, n: 1, allocTxn: 100, freeTxn: 200}},
releaseRanges: []testRange{testRange{1, 199}},
pagesIn: []testPage{{id: 3, n: 1, allocTxn: 100, freeTxn: 200}},
releaseRanges: []testRange{{1, 199}},
wantFree: nil,
},
{
title: "Single pending with minimum begin range",
pagesIn: []testPage{testPage{id: 3, n: 1, allocTxn: 100, freeTxn: 200}},
releaseRanges: []testRange{testRange{100, 300}},
pagesIn: []testPage{{id: 3, n: 1, allocTxn: 100, freeTxn: 200}},
releaseRanges: []testRange{{100, 300}},
wantFree: []pgid{3},
},
{
title: "Single pending outside minimum begin range",
pagesIn: []testPage{testPage{id: 3, n: 1, allocTxn: 100, freeTxn: 200}},
releaseRanges: []testRange{testRange{101, 300}},
pagesIn: []testPage{{id: 3, n: 1, allocTxn: 100, freeTxn: 200}},
releaseRanges: []testRange{{101, 300}},
wantFree: nil,
},
{
title: "Single pending in minimum range",
pagesIn: []testPage{testPage{id: 3, n: 1, allocTxn: 199, freeTxn: 200}},
releaseRanges: []testRange{testRange{199, 200}},
pagesIn: []testPage{{id: 3, n: 1, allocTxn: 199, freeTxn: 200}},
releaseRanges: []testRange{{199, 200}},
wantFree: []pgid{3},
},
{
title: "Single pending and read transaction at 199",
pagesIn: []testPage{testPage{id: 3, n: 1, allocTxn: 199, freeTxn: 200}},
releaseRanges: []testRange{testRange{100, 198}, testRange{200, 300}},
pagesIn: []testPage{{id: 3, n: 1, allocTxn: 199, freeTxn: 200}},
releaseRanges: []testRange{{100, 198}, {200, 300}},
wantFree: nil,
},
{
title: "Adjacent pending and read transactions at 199, 200",
pagesIn: []testPage{
testPage{id: 3, n: 1, allocTxn: 199, freeTxn: 200},
testPage{id: 4, n: 1, allocTxn: 200, freeTxn: 201},
{id: 3, n: 1, allocTxn: 199, freeTxn: 200},
{id: 4, n: 1, allocTxn: 200, freeTxn: 201},
},
releaseRanges: []testRange{
testRange{100, 198},
testRange{200, 199}, // Simulate the ranges db.freePages might produce.
testRange{201, 300},
{100, 198},
{200, 199}, // Simulate the ranges db.freePages might produce.
{201, 300},
},
wantFree: nil,
},
{
title: "Out of order ranges",
pagesIn: []testPage{
testPage{id: 3, n: 1, allocTxn: 199, freeTxn: 200},
testPage{id: 4, n: 1, allocTxn: 200, freeTxn: 201},
{id: 3, n: 1, allocTxn: 199, freeTxn: 200},
{id: 4, n: 1, allocTxn: 200, freeTxn: 201},
},
releaseRanges: []testRange{
testRange{201, 199},
testRange{201, 200},
testRange{200, 200},
{201, 199},
{201, 200},
{200, 200},
},
wantFree: nil,
},
{
title: "Multiple pending, read transaction at 150",
pagesIn: []testPage{
testPage{id: 3, n: 1, allocTxn: 100, freeTxn: 200},
testPage{id: 4, n: 1, allocTxn: 100, freeTxn: 125},
testPage{id: 5, n: 1, allocTxn: 125, freeTxn: 150},
testPage{id: 6, n: 1, allocTxn: 125, freeTxn: 175},
testPage{id: 7, n: 2, allocTxn: 150, freeTxn: 175},
testPage{id: 9, n: 2, allocTxn: 175, freeTxn: 200},
{id: 3, n: 1, allocTxn: 100, freeTxn: 200},
{id: 4, n: 1, allocTxn: 100, freeTxn: 125},
{id: 5, n: 1, allocTxn: 125, freeTxn: 150},
{id: 6, n: 1, allocTxn: 125, freeTxn: 175},
{id: 7, n: 2, allocTxn: 150, freeTxn: 175},
{id: 9, n: 2, allocTxn: 175, freeTxn: 200},
},
releaseRanges: []testRange{testRange{50, 149}, testRange{151, 300}},
releaseRanges: []testRange{{50, 149}, {151, 300}},
wantFree: []pgid{4, 9},
},
}
Expand Down

0 comments on commit e39821f

Please sign in to comment.