-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
96 lines (77 loc) · 4.05 KB
/
Copy pathMakefile
File metadata and controls
96 lines (77 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
PHONY: install-tools install run srv1 srv2 srv3 srv4 srv5 clean client test test-verbose test-coverage test-coverage-html
SERVERS = "localhost:8080,localhost:8081,localhost:8082,localhost:8083,localhost:8084"
PERSISTENT_PATH = ./ignore
DEBUG = DEBUG=true
GO = go run
SRC = cmd/server/main.go
SRC_CLIENT = cmd/client/*.go
TMUX_NEW_WINDOW = tmux new-window -n "Raft"
TMUX_SPLIT_WINDOW = tmux split-window
HEARTBEAT = 1000
TIMEOUT_MIN = 3000
TIMEOUT_MAX = 5000
PROTO_SRC = raft.proto
PROTO_OUT = .
CMD_ARGS = $(filter-out $@,$(MAKECMDGOALS))
HTTP_PORT = 3000
# Define test flags to prevent flag redefinition errors
TEST_FLAGS = -timeout-min=3000 -timeout-max=5000 -heartbeat=1000
install-tools:
@echo "Installing protoc-gen-go..."
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
@echo "protoc-gen-go installed."
install:
make install-tools
go mod tidy
proto-build:
@echo "Compiling protobuf files..."
protoc --go_out=. pkgs/dto/raft.proto
@echo "Protobuf compilation complete."
build:
@echo "Building the project..."
mkdir -p bin
make proto-build
go build -o bin/raft cmd/server/main.go
go build -o bin/client cmd/client/main.go
@echo "Project built."
run:
make proto-build
$(TMUX_NEW_WINDOW) "$(DEBUG) $(GO) $(SRC) -servers=$(SERVERS) -current=localhost:8080 -persistent-path=$(PERSISTENT_PATH) -timeout-min=$(TIMEOUT_MIN) -timeout-max=$(TIMEOUT_MAX) -heartbeat=$(HEARTBEAT) -http-port=$(HTTP_PORT)" && \
$(TMUX_SPLIT_WINDOW) -v "$(DEBUG) $(GO) $(SRC) -servers=$(SERVERS) -current=localhost:8081 -persistent-path=$(PERSISTENT_PATH) -timeout-min=$(TIMEOUT_MIN) -timeout-max=$(TIMEOUT_MAX) -heartbeat=$(HEARTBEAT) -http-port=$(HTTP_PORT)" && \
$(TMUX_SPLIT_WINDOW) -h "$(DEBUG) $(GO) $(SRC) -servers=$(SERVERS) -current=localhost:8082 -persistent-path=$(PERSISTENT_PATH) -timeout-min=$(TIMEOUT_MIN) -timeout-max=$(TIMEOUT_MAX) -heartbeat=$(HEARTBEAT) -http-port=$(HTTP_PORT)" && \
$(TMUX_SPLIT_WINDOW) -v "$(DEBUG) $(GO) $(SRC) -servers=$(SERVERS) -current=localhost:8083 -persistent-path=$(PERSISTENT_PATH) -timeout-min=$(TIMEOUT_MIN) -timeout-max=$(TIMEOUT_MAX) -heartbeat=$(HEARTBEAT) -http-port=$(HTTP_PORT)" && \
$(TMUX_SPLIT_WINDOW) -h "$(DEBUG) $(GO) $(SRC) -servers=$(SERVERS) -current=localhost:8084 -persistent-path=$(PERSISTENT_PATH) -timeout-min=$(TIMEOUT_MIN) -timeout-max=$(TIMEOUT_MAX) -heartbeat=$(HEARTBEAT) -http-port=$(HTTP_PORT)"
srv1:
$(DEBUG) $(GO) $(SRC) -servers=$(SERVERS) -current=localhost:8080 -persistent-path=$(PERSISTENT_PATH) -timeout-min=$(TIMEOUT_MIN) -timeout-max=$(TIMEOUT_MAX) -heartbeat=$(HEARTBEAT) -http-port=$(HTTP_PORT)
srv2:
$(DEBUG) $(GO) $(SRC) -servers=$(SERVERS) -current=localhost:8081 -persistent-path=$(PERSISTENT_PATH) -timeout-min=$(TIMEOUT_MIN) -timeout-max=$(TIMEOUT_MAX) -heartbeat=$(HEARTBEAT) -http-port=$(HTTP_PORT)
srv3:
$(DEBUG) $(GO) $(SRC) -servers=$(SERVERS) -current=localhost:8082 -persistent-path=$(PERSISTENT_PATH) -timeout-min=$(TIMEOUT_MIN) -timeout-max=$(TIMEOUT_MAX) -heartbeat=$(HEARTBEAT) -http-port=$(HTTP_PORT)
srv4:
$(DEBUG) $(GO) $(SRC) -servers=$(SERVERS) -current=localhost:8083 -persistent-path=$(PERSISTENT_PATH) -timeout-min=$(TIMEOUT_MIN) -timeout-max=$(TIMEOUT_MAX) -heartbeat=$(HEARTBEAT) -http-port=$(HTTP_PORT)
srv5:
$(DEBUG) $(GO) $(SRC) -servers=$(SERVERS) -current=localhost:8084 -persistent-path=$(PERSISTENT_PATH) -timeout-min=$(TIMEOUT_MIN) -timeout-max=$(TIMEOUT_MAX) -heartbeat=$(HEARTBEAT) -http-port=$(HTTP_PORT)
client:
$(DEBUG) $(GO) $(SRC_CLIENT) -servers=$(SERVERS) $(CMD_ARGS)
clean:
rm -rf $(PERSISTENT_PATH)/*
kill:
kill -15 $(shell lsof -t -i:8080)
kill -15 $(shell lsof -t -i:8081)
kill -15 $(shell lsof -t -i:8082)
kill -15 $(shell lsof -t -i:8083)
kill -15 $(shell lsof -t -i:8084)
# Run all tests (ignoring errors)
test:
@echo "Running all tests..."
-go test -race ./...
# Run all tests with verbose output (ignoring errors)
test-verbose:
@echo "Running all tests with verbose output..."
-go test -v -race ./...
test-raft:
@echo "Running raft tests..."
-go test -race -v -timeout=10s ./pkgs/raft/...
# This allows passing arguments to the make command without errors
%:
@: