Skip to content

Commit

Permalink
Fix go-generate calling, do more before running tests (#1377)
Browse files Browse the repository at this point in the history
Does a couple things:
- `make $(BUILD)/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 authored Nov 1, 2024
1 parent a71b70f commit 41c2a12
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
16 changes: 9 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,9 @@ $(THRIFT_GEN): $(THRIFT_FILES) $(BIN)/thriftrw $(BIN)/thriftrw-plugin-yarpc
$Q touch $@

# 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
# as long as the //go:generate line is in the file that defines the thing to mock, this will auto-discover it.
# if we build any fancier generators, like the server's wrappers, this might need adjusting / switch to completely manual.
$(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 +304,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, tests all do this for you if needed)
$(call remake,generate)

.PHONY: tidy
tidy:
Expand Down Expand Up @@ -372,7 +374,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 +385,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 41c2a12

Please sign in to comment.