Files
air/Makefile
xiantang d29a90a122 Optimize unit test performance from 60s to 35s (42% improvement) (#843)
Reduce test execution time through smart waiting and selective parallelization.

Changes:
- Replace fixed sleep delays with condition-based waiting (20ms polling)
- Add CI-aware timeout multiplier (2x in CI environments)
- Enable parallel execution for 30+ pure function tests
- Add test and test-ci Make targets
- Update GitHub Actions workflow with CI flag and timeout

Performance:
- Before: ~60 seconds
- After: ~35 seconds
- Improvement: 42% faster (25 seconds saved)

Technical details:
- New helpers: waitForCondition(), waitForEngineState() in test_util.go
- Optimized tests: TestRebuild, TestRun, TestRebuildWhenRunCmdUsingDLV, etc.
- Parallelized: config_test.go (6 tests), flag_test.go (1 test), util_test.go (13 tests)
- Avoided parallelizing tests with global state (os.Setenv, os.Chdir, signal handlers)

Limitations:
- Some tests cannot be parallelized due to Go 1.25 restrictions on t.Parallel() + t.Setenv()
- Pre-existing race conditions in engine tests remain (not addressed in this change)
2026-01-05 21:37:23 +08:00

64 lines
1.7 KiB
Makefile

AIRVER := $(shell git describe --tags)
LDFLAGS += -X "main.BuildTimestamp=$(shell date -u "+%Y-%m-%d %H:%M:%S")"
LDFLAGS += -X "main.airVersion=$(AIRVER)"
LDFLAGS += -X "main.goVersion=$(shell go version | sed -r 's/go version go(.*)\ .*/\1/')"
GO := GO111MODULE=on CGO_ENABLED=0 go
GOLANGCI_LINT_VERSION = v2.6.1
GOLANGCI_LINT_CURRENT := $(shell golangci-lint --version 2>/dev/null | sed -n 's/.*version \([0-9.]*\).*/v\1/p')
.PHONY: init
init: install-golangci-lint
go install golang.org/x/tools/cmd/goimports@latest
@echo "Install pre-commit hook"
@ln -s $(shell pwd)/hooks/pre-commit $(shell pwd)/.git/hooks/pre-commit || true
@chmod +x ./hack/check.sh
.PHONY: install-golangci-lint
install-golangci-lint:
@echo "Installing golangci-lint $(GOLANGCI_LINT_VERSION)"
@GO111MODULE=on go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
.PHONY: setup
setup: init
git init
.PHONY: check
check:
@./hack/check.sh ${scope}
.PHONY: test
test:
@go test ./... -v -race -timeout=3m
.PHONY: test-ci
test-ci:
@CI=true go test ./... -v -timeout=5m
.PHONY: ci
ci: init
@$(GO) mod tidy
.PHONY: build
build: check
$(GO) build -ldflags '$(LDFLAGS)'
.PHONY: install
install: check
@echo "Installing air..."
@$(GO) install -ldflags '$(LDFLAGS)'
.PHONY: release
release: check
GOOS=darwin GOARCH=amd64 $(GO) build -ldflags '$(LDFLAGS)' -o bin/darwin/air
GOOS=linux GOARCH=amd64 $(GO) build -ldflags '$(LDFLAGS)' -o bin/linux/air
GOOS=windows GOARCH=amd64 $(GO) build -ldflags '$(LDFLAGS)' -o bin/windows/air.exe
.PHONY: docker-image
docker-image:
docker build -t cosmtrek/air:$(AIRVER) -f ./Dockerfile .
.PHONY: push-docker-image
push-docker-image:
docker push cosmtrek/air:$(AIRVER)