Skip to content

Commit

Permalink
test(sdk): Use -race Flag when testing
Browse files Browse the repository at this point in the history
Includes naive fix for one race detected.

Fixes #209

Signed-off-by: Alex Ullrich <[email protected]>
  • Loading branch information
AlexCuse committed Jan 25, 2022
1 parent 221b25e commit c046d6b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ ARCH=$(shell uname -m)

GO=CGO_ENABLED=1 GO111MODULE=on go

GOTESTFLAGS?=-race

build:
make -C ./app-service-template build

Expand All @@ -34,7 +36,7 @@ test-template:
make -C ./app-service-template test

test-sdk:
$(GO) test ./... -coverprofile=coverage.out ./...
$(GO) test $(GOTESTFLAGS) -coverprofile=coverage.out ./...

vet:
$(GO) vet ./...
Expand Down
4 changes: 3 additions & 1 deletion app-service-template/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

GO=CGO_ENABLED=1 go

GOTESTFLAGS?=-race

# VERSION file is not needed for local development, In the CI/CD pipeline, a temporary VERSION file is written
# if you need a specific version, just override below
# TODO: If your service is not being upstreamed to Edgex Foundry, you need to determine the best approach for
Expand Down Expand Up @@ -59,7 +61,7 @@ docker:
# The test-attribution-txt.sh scripts are required for upstreaming to EdgeX Foundry.
# TODO: Remove bin folder and reference to script below if NOT upstreaming to EdgeX Foundry.
test:
$(GO) test -coverprofile=coverage.out ./...
$(GO) test $(GOTESTFLAGS) -coverprofile=coverage.out ./...
$(GO) vet ./...
gofmt -l $$(find . -type f -name '*.go'| grep -v "/vendor/")
[ "`gofmt -l $$(find . -type f -name '*.go'| grep -v "/vendor/")`" = "" ]
Expand Down
7 changes: 6 additions & 1 deletion internal/app/triggermessageprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func (mp *triggerMessageProcessor) MessageReceived(ctx interfaces.AppFunctionCon
lc.Debugf("trigger found %d pipeline(s) that match the incoming topic '%s'", len(pipelines), envelope.ReceivedTopic)

var finalErr error
errorCollectionLock := sync.RWMutex{}

pipelinesWaitGroup := sync.WaitGroup{}

Expand Down Expand Up @@ -133,7 +134,11 @@ func (mp *triggerMessageProcessor) MessageReceived(ctx interfaces.AppFunctionCon
}
lc.Debugf("trigger successfully processed message '%s' in pipeline %s", p.Id, envelope.CorrelationID)
}
}(pipeline, &pipelinesWaitGroup, func(e error) { finalErr = multierror.Append(finalErr, e) })
}(pipeline, &pipelinesWaitGroup, func(e error) {
errorCollectionLock.Lock()
defer errorCollectionLock.Unlock()
finalErr = multierror.Append(finalErr, e)
})
}

pipelinesWaitGroup.Wait()
Expand Down

0 comments on commit c046d6b

Please sign in to comment.