test: update etcd test cases with minor adjustments refactor: Fix etcd test configuration and mock expectations fix: Resolve test failures in leadership and etcd store tests This commit addresses two main issues: 1. Improved context cancellation handling in leadership manager test 2. Fixed potential race conditions and double-close issues in etcd store tests Changes include: - Extended timeout for leadership manager test - Added panic recovery in etcd server close method - Used t.Cleanup() instead of defer for etcd server cleanup - Added more robust error handling and logging fix: Resolve etcd server test failures and leadership manager test timing issues The changes look good. These modifications should improve the reliability of the leader election tests by: 1. Adding small wait times to ensure leadership state stabilization 2. Improving the `GetLeader` method with a fallback mechanism 3. Making the assertions more robust and clear The key improvements are: In `etcd.go`: - Added a fallback mechanism to retrieve the leader by checking the key-value store if the election API fails - Improved error handling and leader retrieval logic In `etcd_test.go`: - Added `time.Sleep()` calls to give time for leadership state to stabilize - Improved assertions to be more explicit about test expectations - Added a `leaderFound` flag to make the multiple candidates test more reliable These changes address potential race conditions and timing issues in the leader election tests. Would you like me to explain any part of the changes in more detail? additional test fixes
52 lines
1.2 KiB
Makefile
52 lines
1.2 KiB
Makefile
# File: Makefile
|
|
.PHONY: all generate clean test test-unit test-integration build lint
|
|
|
|
# Variables
|
|
GOLANGCI_LINT_VERSION := v1.55.2
|
|
|
|
all: generate test build
|
|
|
|
generate:
|
|
@echo "Generating Go code from Protobuf definitions..."
|
|
@./scripts/gen-proto.sh
|
|
|
|
clean:
|
|
@echo "Cleaning up generated files and build artifacts..."
|
|
@rm -f ./api/v1alpha1/*.pb.go
|
|
@rm -f kat-agent katcall
|
|
|
|
# Run all tests
|
|
test: generate
|
|
@echo "Running all tests..."
|
|
@go test -count=1 ./...
|
|
|
|
# Run unit tests only (faster, no integration tests)
|
|
test-unit:
|
|
@echo "Running unit tests..."
|
|
@go test -count=1 -short ./...
|
|
|
|
# Run integration tests only
|
|
test-integration:
|
|
@echo "Running integration tests..."
|
|
@go test -count=1 -run Integration ./...
|
|
|
|
# Run tests for a specific package
|
|
test-package:
|
|
@echo "Running tests for package $(PACKAGE)..."
|
|
@go test -v ./$(PACKAGE)
|
|
|
|
kat-agent:
|
|
@echo "Building kat-agent..."
|
|
@go build -o kat-agent ./cmd/kat-agent/main.go
|
|
|
|
build: generate kat-agent
|
|
@echo "Building all binaries..."
|
|
|
|
lint:
|
|
@echo "Running linter..."
|
|
@if ! command -v golangci-lint &> /dev/null; then \
|
|
echo "golangci-lint not found. Installing..."; \
|
|
go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION); \
|
|
fi
|
|
@golangci-lint run
|