Skip to content

fix(mg): allow resetting dependency cache in tests#556

Open
ychampion wants to merge 1 commit into
magefile:masterfrom
ychampion:reset-deps-cache-for-tests
Open

fix(mg): allow resetting dependency cache in tests#556
ychampion wants to merge 1 commit into
magefile:masterfrom
ychampion:reset-deps-cache-for-tests

Conversation

@ychampion

Copy link
Copy Markdown

Summary

  • add mg.ResetDeps to clear the dependency cache between same-process test cases
  • cover rerunning the same dependency after a reset

Why

mg.Deps correctly caches dependencies for a Mage run, but tests that execute Mage targets multiple times in the same process currently have no way to clear the global cache. This follows the ResetDeps helper direction discussed in #524.

Fixes #524.

Validation

  • go test ./mg -run TestResetDepsAllowsDependenciesToRunAgain -count=1
  • go test ./mg -count=1
  • GOPATH="$(go env GOPATH)" go test -vet=all -tags CI -race ./... -count=1
  • golangci-lint run ./...
  • git diff --check

Expose mg.ResetDeps for tests that run multiple Mage targets in one process without changing normal once-per-run dependency semantics.

Constraint: Issue magefile#524 needs a way for same-process tests to rerun dependency functions.
Rejected: clearing the cache automatically between Deps calls | that would change normal Mage dependency semantics.
Confidence: high
Scope-risk: narrow
Directive: Do not call ResetDeps while dependencies are running; it only clears the process-global dependency cache.
Tested: go test ./mg -run TestResetDepsAllowsDependenciesToRunAgain -count=1; go test ./mg -count=1; GOPATH="/root/go" go test -vet=all -tags CI -race ./... -count=1; golangci-lint run ./...; git diff --check
Not-tested: full GitHub Actions matrix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Tests reusing onces dependency-cache

1 participant