Skip to content

Commit

Permalink
Fix go-generate calling, do more before running tests
Browse files Browse the repository at this point in the history
Does a couple things:
- `make generate` now infers files that might affect generation.  This should work as long as we keep simple codegen (the server has moved beyond this, sadly).
- `make generate` now forces re-generation regardless of need, because it's a nice workaround for dependency issues like happened in #1373
- `make test` and related targets now go-generate and fmt before running tests.  Slower, but you can't forget to re-generate, and they're slow already so it's probably fine.
  • Loading branch information
Groxx committed Nov 1, 2024
1 parent a71b70f commit f2d9bc0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
13 changes: 7 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ $(THRIFT_GEN): $(THRIFT_FILES) $(BIN)/thriftrw $(BIN)/thriftrw-plugin-yarpc

# mockery is quite noisy so it's worth being kinda precise with the files.
# this needs to be both the files defining the generate command, AND the files that define the interfaces.
$(BUILD)/generate: client/client.go encoded/encoded.go internal/internal_workflow_client.go internal/internal_public.go internal/internal_task_pollers.go $(BIN)/mockery
$(BUILD)/generate: $(shell grep --files-with-matches -E '^//go:generate' $(ALL_SRC)) $(BIN)/mockery
$Q $(BIN_PATH) go generate ./...
$Q touch $@

Expand Down Expand Up @@ -303,7 +303,8 @@ errcheck: $(BIN)/errcheck $(BUILD)/fmt ## (re)run errcheck
$(BIN)/errcheck ./...

.PHONY: generate
generate: $(BUILD)/generate ## run go-generate
generate: ## run go-generate (build, lint, fmt all do this for you if needed)
$(call remake,generate)

.PHONY: tidy
tidy:
Expand Down Expand Up @@ -372,7 +373,7 @@ UT_DIRS := $(filter-out $(INTEG_TEST_ROOT)%, $(sort $(dir $(filter %_test.go,$(A
.PHONY: unit_test integ_test_sticky_off integ_test_sticky_on integ_test_grpc cover
test: unit_test integ_test_sticky_off integ_test_sticky_on ## run all tests (requires a running cadence instance)

unit_test: $(ALL_SRC) ## run all unit tests
unit_test: $(BUILD)/fmt ## run all unit tests
$Q mkdir -p $(COVER_ROOT)
$Q echo "mode: atomic" > $(UT_COVER_FILE)
$Q FAIL=""; \
Expand All @@ -383,15 +384,15 @@ unit_test: $(ALL_SRC) ## run all unit tests
done; test -z "$$FAIL" || (echo "Failed packages; $$FAIL"; exit 1)
cat $(UT_COVER_FILE) > .build/cover.out;

integ_test_sticky_off: $(ALL_SRC)
integ_test_sticky_off: $(BUILD)/fmt
$Q mkdir -p $(COVER_ROOT)
STICKY_OFF=true go test $(TEST_ARG) ./test -coverprofile=$(INTEG_STICKY_OFF_COVER_FILE) -coverpkg=./...

integ_test_sticky_on: $(ALL_SRC)
integ_test_sticky_on: $(BUILD)/fmt
$Q mkdir -p $(COVER_ROOT)
STICKY_OFF=false go test $(TEST_ARG) ./test -coverprofile=$(INTEG_STICKY_ON_COVER_FILE) -coverpkg=./...

integ_test_grpc: $(ALL_SRC)
integ_test_grpc: $(BUILD)/fmt
$Q mkdir -p $(COVER_ROOT)
STICKY_OFF=false go test $(TEST_ARG) ./test -coverprofile=$(INTEG_GRPC_COVER_FILE) -coverpkg=./...

Expand Down
2 changes: 0 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
// when adding any, make sure you update the files that it checks in the makefile
//go:generate mockery --srcpkg . --name Client --output ../mocks --boilerplate-file ../LICENSE
//go:generate mockery --srcpkg . --name DomainClient --output ../mocks --boilerplate-file ../LICENSE
//go:generate mockery --srcpkg go.uber.org/cadence/internal --name HistoryEventIterator --output ../mocks --boilerplate-file ../LICENSE
//go:generate mockery --srcpkg go.uber.org/cadence/internal --name WorkflowRun --output ../mocks --boilerplate-file ../LICENSE

// Package client contains functions to create Cadence clients used to communicate to Cadence service.
//
Expand Down
2 changes: 0 additions & 2 deletions encoded/encoded.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

//go:generate mockery --srcpkg go.uber.org/cadence/internal --name Value --output ../mocks --boilerplate-file ../LICENSE

// Package encoded contains wrappers that are used for binary payloads deserialization.
package encoded

Expand Down
2 changes: 2 additions & 0 deletions internal/encoded.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"go.uber.org/cadence/internal/common/util"
)

//go:generate mockery --name Value --output ../mocks --boilerplate-file ../LICENSE

type (
// Value is used to encapsulate/extract encoded value from workflow/activity.
Value interface {
Expand Down
3 changes: 3 additions & 0 deletions internal/internal_workflow_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ import (
"go.uber.org/cadence/internal/common/metrics"
)

//go:generate mockery --name HistoryEventIterator --output ../mocks --boilerplate-file ../LICENSE
//go:generate mockery --name WorkflowRun --output ../mocks --boilerplate-file ../LICENSE

// Assert that structs do indeed implement the interfaces
var _ Client = (*workflowClient)(nil)

Expand Down

0 comments on commit f2d9bc0

Please sign in to comment.