Skip to content

Commit

Permalink
Merge pull request #67 from someone1/lint-race
Browse files Browse the repository at this point in the history
Add lint and race checks with associated fixes
  • Loading branch information
someone1 committed Aug 5, 2019
2 parents 66b7fd6 + 66b184b commit 4b0cefc
Show file tree
Hide file tree
Showing 14 changed files with 227 additions and 112 deletions.
12 changes: 7 additions & 5 deletions .travis.yml
@@ -1,10 +1,10 @@
language: go
sudo: false
go:
- 1.10.x
- 1.11.x
- 1.12.x
env:
- REDIS_ADDR="localhost:6379" APPENGINE_DEV_APPSERVER="$HOME/google-cloud-sdk/bin/dev_appserver.py" GO111MODULE="on"
- REDIS_ADDR="localhost:6379" APPENGINE_DEV_APPSERVER="$HOME/google-cloud-sdk/bin/dev_appserver.py" GO111MODULE="on" DATASTORE_EMULATOR_HOST="localhost:8432" DATASTORE_PROJECT_ID="nds-test"
services:
- redis-server
before_install:
Expand All @@ -16,13 +16,15 @@ install:
- "$HOME/google-cloud-sdk/bin/gcloud components install app-engine-python --quiet"
- "$HOME/google-cloud-sdk/bin/gcloud components install app-engine-go --quiet"
- go get -v -d -t ./...
- go get github.com/golangci/golangci-lint/cmd/golangci-lint
before_script:
- "$HOME/google-cloud-sdk/bin/gcloud config set project nds-test"
- "$HOME/google-cloud-sdk/bin/gcloud beta emulators datastore start --quiet &"
- sleep 15
- "$($HOME/google-cloud-sdk/bin/gcloud beta emulators datastore env-init)"
- "$HOME/google-cloud-sdk/bin/gcloud beta emulators datastore start --quiet --no-store-on-disk --consistency=1 --host-port=localhost:8432 &"
- timeout 300 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' $DATASTORE_EMULATOR_HOST)" != "200" ]]; do sleep 5; done' || false
script:
- go test -covermode=count -coverprofile=profile.cov -coverpkg=$(go list ./... | grep -v '/vendor/' | paste -sd, -) ./...
- go test -race ./...
- golangci-lint run ./...
after_success:
- go get -v github.com/mattn/goveralls
- export PATH=$PATH:$HOME/gopath/bin
Expand Down
2 changes: 1 addition & 1 deletion cache_test.go
Expand Up @@ -232,7 +232,7 @@ func CacherImplementationTest(ctx context.Context, cacher nds.Cacher) func(t *te
} else if got == nil {
if result, err := cacher.GetMulti(tt.args.c, keys); err != nil {
t.Errorf("expected err = nil, got %v", err)
} else if result != nil && len(result) != 0 {
} else if len(result) != 0 {
t.Errorf("expected len(cacher.GetMulti()) = 0, got %d", len(result))
}
}
Expand Down
2 changes: 1 addition & 1 deletion cachers/memcache/memcache.go
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/qedus/nds/v2"
)

type backend struct {}
type backend struct{}

// NewCacher will return a nds.Cacher backed by AppEngine's memcache.
func NewCacher() nds.Cacher {
Expand Down
10 changes: 5 additions & 5 deletions cachers/memory/memory.go
Expand Up @@ -72,9 +72,9 @@ func (m *memory) CompareAndSwapMulti(ctx context.Context, items []*nds.Item) err
Value: append([]byte(nil), obj.value...),
}
hasher := sha1.New()
binary.Write(hasher, binary.LittleEndian, ndsItem.Flags)
hasher.Write(ndsItem.Value) // err is always nil
if bytes.Compare(item.GetCASInfo().([]byte), hasher.Sum(nil)) == 0 {
_ = binary.Write(hasher, binary.LittleEndian, ndsItem.Flags)
_, _ = hasher.Write(ndsItem.Value) // err is always nil
if bytes.Equal(item.GetCASInfo().([]byte), hasher.Sum(nil)) {
m.store.Set(item.Key, &object{flags: item.Flags, value: append([]byte(nil), item.Value...)}, item.Expiration)
} else {
hasErr = true
Expand Down Expand Up @@ -134,8 +134,8 @@ func (m *memory) GetMulti(ctx context.Context, keys []string) (map[string]*nds.I
Value: append([]byte(nil), obj.value...),
}
hasher := sha1.New()
binary.Write(hasher, binary.LittleEndian, ndsItem.Flags)
hasher.Write(ndsItem.Value)
_ = binary.Write(hasher, binary.LittleEndian, ndsItem.Flags)
_, _ = hasher.Write(ndsItem.Value)
ndsItem.SetCASInfo(hasher.Sum(nil))
result[key] = ndsItem
}
Expand Down

0 comments on commit 4b0cefc

Please sign in to comment.