Skip to content

Commit

Permalink
Fixed: Races caught by backend integration testing (#66)
Browse files Browse the repository at this point in the history
* Fixed: Avoid race from audit

* Update: Simplify running unit tests

* Fixed: Do deep copy of context and fix another race

* Update: Move back to serial

* Fixed: Protect read on claims

* Update: Enable typecheck

* Update: Address review comments

* Update: Move to other method for copying slices

* Update: Use more elegant method of slice copy

* Fixed: Align unit tests with recent master commit
  • Loading branch information
Eric Powers authored and primalmotion committed Jul 25, 2019
1 parent 7f042fd commit 7bb86bf
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,11 @@ lint:
--enable=misspell \
--enable=prealloc \
--enable=nakedret \
--enable=typecheck \
./...

test:
@ echo 'mode: atomic' > unit_coverage.cov
@ for d in $(shell go list ./... | grep -v vendor); do \
go test -race -coverprofile=profile.out -covermode=atomic "$$d"; \
if [ -f profile.out ]; then tail -q -n +2 profile.out >> unit_coverage.cov; rm -f profile.out; fi; \
done;
@ go test ./... -race -cover -covermode=atomic -coverprofile=unit_coverage.cov

coverage_aggregate:
@ mkdir -p artifacts
Expand Down
2 changes: 1 addition & 1 deletion dispatchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func audit(auditer Auditer, ctx *bcontext, err error) {
return
}

go auditer.Audit(ctx, err)
auditer.Audit(ctx, err)
}

func notImplementedErr(request *elemental.Request) error {
Expand Down
12 changes: 6 additions & 6 deletions dispatchers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ func TestDispatchers_dispatchCreateOperation(t *testing.T) {
processorFinder,
testmodel.Manager(),
func(*elemental.Request) (elemental.Identifiable, error) {
return nil, fmt.Errorf("boom")
return nil, fmt.Errorf(expectedError)
},
nil,
nil,
Expand All @@ -578,7 +578,7 @@ func TestDispatchers_dispatchCreateOperation(t *testing.T) {
)

Convey("Then I should get a bahamut error and no context", func() {
So(err.Error(), ShouldEqual, expectedError)
So(err.Error(), ShouldEqual, fmt.Sprintf("error 400 (bahamut): Bad Request: %s", expectedError))
})
})

Expand Down Expand Up @@ -973,7 +973,7 @@ func TestDispatchers_dispatchUpdateOperation(t *testing.T) {
processorFinder,
testmodel.Manager(),
func(*elemental.Request) (elemental.Identifiable, error) {
return nil, fmt.Errorf("boom")
return nil, fmt.Errorf(expectedError)
},
nil,
nil,
Expand All @@ -984,7 +984,7 @@ func TestDispatchers_dispatchUpdateOperation(t *testing.T) {
)

Convey("Then I should get a bahamut error and no context", func() {
So(err.Error(), ShouldEqual, expectedError)
So(err.Error(), ShouldEqual, fmt.Sprintf("error 400 (bahamut): Bad Request: %s", expectedError))
})
})
}
Expand Down Expand Up @@ -1494,7 +1494,7 @@ func TestDispatchers_dispatchPatchOperation(t *testing.T) {
processorFinder,
testmodel.Manager(),
func(*elemental.Request) (elemental.Identifiable, error) {
return nil, fmt.Errorf("boom")
return nil, fmt.Errorf(expectedError)
},
nil,
nil,
Expand All @@ -1505,7 +1505,7 @@ func TestDispatchers_dispatchPatchOperation(t *testing.T) {
)

Convey("Then I should get a bahamut error and no context", func() {
So(err.Error(), ShouldEqual, expectedError)
So(err.Error(), ShouldEqual, fmt.Sprintf("error 400 (bahamut): Bad Request: %s", expectedError))
})
})
}
Expand Down
18 changes: 14 additions & 4 deletions websocket_push_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,23 @@ func (s *wsPushSession) String() string {
// SetClaims implements elemental.ClaimsHolder.
func (s *wsPushSession) SetClaims(claims []string) {

s.claims = claims
s.claimsMap = claimsToMap(claims)
s.claims = append([]string{}, claims...)
s.claimsMap = claimsToMap(s.claims)
}

func (s *wsPushSession) ClaimsMap() map[string]string {

copiedClaimsMap := map[string]string{}

for k, v := range s.claimsMap {
copiedClaimsMap[k] = v
}

return copiedClaimsMap
}

func (s *wsPushSession) Identifier() string { return s.id }
func (s *wsPushSession) Claims() []string { return s.claims }
func (s *wsPushSession) ClaimsMap() map[string]string { return s.claimsMap }
func (s *wsPushSession) Claims() []string { return append([]string{}, s.claims...) }
func (s *wsPushSession) Token() string { return s.Parameter("token") }
func (s *wsPushSession) Context() context.Context { return s.ctx }
func (s *wsPushSession) TLSConnectionState() *tls.ConnectionState { return s.tlsConnectionState }
Expand Down

0 comments on commit 7bb86bf

Please sign in to comment.