Skip to content

Commit 793fe9c

Browse files
fix(test): macOS local image, plugin tests, and test suite restructuring (#9610)
## Summary This PR fixes macOS compatibility for local image builds and plugin tests, restructures the test suite system for better ergonomics and resource management, and fixes a flaky integration2 test. ### macOS / Local Build Fixes - Enable CGO cross-compilation for plugin support on macOS (Darwin → Linux) - Fix integration test routing, `gotestsum` PATH resolution, and cross-compilation issues - Add cluster pause/resume and resilient restore waits for stability - Resolve shellcheck SC2312 in `check-cross-compiler.sh` ### Test Suite Restructuring - **New `integration` suite** (new default): runs everything except `ldbc`, `load`, and `systest-heavy` — replaces old `unit,systest,core` default - **New `unit` suite behavior**: true unit tests only — no Docker cluster, no `--tags=integration`, skips custom-cluster packages - **New `systest-baseline` / `systest-heavy` sub-suites**: separates lightweight systests from resource-intensive ones (minio, encryption, tracing, online-restore) that can OOM on Docker - `systest` still runs both sub-suites for backward compatibility - **New Make targets**: `test-integration`, `test-integration-heavy` - **Renamed**: `test-full` → `test-all` - **Removed**: `test-suite`, `test-ldbc`, `test-load` (use `make test SUITE=...` instead) ### Import Client Retry Fix - **Fixed flaky `TestImportApis/SingleGroupShutOneAlpha`** in the `dgraph-integration2-tests` CI job - Root cause: `initiateSnapshotStream` made a single attempt to start the snapshot stream, but the Dgraph server can return "overloaded with pending proposals" during Raft membership changes (e.g., when an alpha is shut down and the cluster is rebalancing) - Fix: Added exponential backoff retry (1s → 10s cap, 60s max total) for transient "overloaded" errors - Only retries on "overloaded" — connectivity errors ("connection refused", "unable to connect to the leader") still fail immediately so negative test cases don't block unnecessarily ### Quick Reference | Command | What it runs | |---------|-------------| | `make test` | `integration` suite + `integration2` (~30 min) | | `make test-unit` | True unit tests — no Docker | | `make test-integration` | Integration tests via t/ runner with Docker | | `make test-integration-heavy` | systest-heavy + ldbc + load | | `make test-all` | Every test: all suites + integration2 + upgrade + fuzz | ## Test plan - [x] `make test-unit` runs without starting Docker cluster and discovers only non-integration tests - [x] `make test` (integration suite) correctly excludes heavy/ldbc/load packages - [x] `make test-integration-heavy` (`systest-heavy`) correctly runs only heavy packages (11 packages) - [x] `make test SUITE=systest` runs both systest-baseline and systest-heavy (30 packages) - [x] `make test SUITE=systest-baseline` runs only lightweight systests (18 packages) - [x] `TestImportApis/SingleGroupShutOneAlpha` passes reliably with retry logic (CI) - [x] Existing CI workflows continue to pass --------- Co-authored-by: Shiva Kharsi (@shivaji-kharse / @shiva-istari) <[email protected]>
1 parent 1a7fff6 commit 793fe9c

12 files changed

Lines changed: 576 additions & 121 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,5 @@ x/log_test/*.enc
4848
*.buf
4949
.osgrep
5050
.worktrees/
51+
AGENTS.md
52+
CLAUDE.md

CONTRIBUTING.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
```bash
4141
git clone https://github.com/dgraph-io/dgraph.git
4242
cd ./dgraph
43-
make install
43+
make setup # auto-install tool dependencies (gotestsum, ack, etc.)
44+
make install # build and install the dgraph binary
4445
```
4546

4647
This will put the source code in a Git repo under `$GOPATH/src/github.com/dgraph-io/dgraph` and
@@ -144,16 +145,25 @@ directory, providing control and flexibility beyond the standard Go testing fram
144145
The simplest way to run tests is via Make:
145146

146147
```bash
147-
# Run all tests
148+
# First-time setup: install tool dependencies
149+
make setup
150+
151+
# Run default tests (~30 min): integration suite + integration2
148152
make test
149153

154+
# Run every test in the repo
155+
make test-all
156+
150157
# Run specific test types
151-
make test-unit # Unit tests only (no Docker)
152-
make test-integration2 # Integration2 tests via dgraphtest
153-
make test-upgrade # Upgrade tests
158+
make test-unit # True unit tests only — no Docker, no build tags
159+
make test-integration # Integration tests via t/ runner with Docker
160+
make test-integration-heavy # All heavy tests: systest-heavy + ldbc + load
161+
make test-integration2 # Integration2 tests via dgraphtest
162+
make test-upgrade # Upgrade tests
154163

155164
# Use variables for more control
156165
make test TAGS=integration2 PKG=systest/vector
166+
make test SUITE=all # All t/ runner suites
157167
make test TIMEOUT=90m # Override per-package timeout (default: 30m)
158168
```
159169

Makefile

Lines changed: 73 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,20 @@ ifeq ($(GOPATH),)
1818
$(error GOPATH is not set. Please set it explicitly, e.g. export GOPATH=$$HOME/go)
1919
endif
2020

21-
# On non-Linux systems, use a separate directory for Linux binaries
21+
# On non-Linux systems, use a separate directory for Linux binaries and
22+
# a cross-compiler so that CGO is available (required for plugin support).
2223
ifeq ($(GOHOSTOS),linux)
2324
export LINUX_GOBIN ?= $(GOPATH)/bin
25+
LINUX_CC ?= gcc
2426
else
2527
export LINUX_GOBIN ?= $(GOPATH)/linux_$(GOHOSTARCH)
28+
ifeq ($(GOHOSTARCH),arm64)
29+
LINUX_CC ?= aarch64-unknown-linux-gnu-gcc
30+
else ifeq ($(GOHOSTARCH),amd64)
31+
LINUX_CC ?= x86_64-unknown-linux-gnu-gcc
32+
else
33+
LINUX_CC ?= gcc
34+
endif
2635
endif
2736

2837
######################
@@ -60,7 +69,7 @@ install: ## Install dgraph binary
6069
ifneq ($(GOHOSTOS),linux)
6170
@mkdir -p $(LINUX_GOBIN)
6271
@echo "Installing dgraph (linux/$(GOHOSTARCH))..."
63-
@GOOS=linux GOARCH=$(GOHOSTARCH) $(MAKE) -C dgraph dgraph
72+
@GOOS=linux GOARCH=$(GOHOSTARCH) CGO_ENABLED=1 CC=$(LINUX_CC) $(MAKE) -C dgraph BUILD_TAGS= EXTLDFLAGS=-fuse-ld=bfd dgraph
6473
@mv dgraph/dgraph $(LINUX_GOBIN)/dgraph
6574
@echo "Installed dgraph (linux/$(GOHOSTARCH)) to $(LINUX_GOBIN)/dgraph"
6675
endif
@@ -73,13 +82,18 @@ uninstall: ## Uninstall dgraph binary
7382

7483
.PHONY: dgraph-installed
7584
dgraph-installed:
76-
@if [ ! -f "$(GOPATH)/bin/dgraph" ] || [ ! -f "$(LINUX_GOBIN)/dgraph" ]; then \
77-
echo "Dgraph binary missing, running make install..."; \
78-
$(MAKE) install; \
79-
fi
85+
$(MAKE) install
86+
87+
.PHONY: deps
88+
deps: ## Check test dependencies (pass AUTO_INSTALL=true to auto-install missing ones)
89+
$(MAKE) -C t deps
90+
91+
.PHONY: setup
92+
setup: ## Install all test dependencies automatically
93+
$(MAKE) deps AUTO_INSTALL=true
8094

8195
.PHONY: test
82-
test: dgraph-installed local-image ## Run tests (see 'make help' for options)
96+
test: dgraph-installed local-image ## Run tests (default: integration + integration2)
8397
ifdef TAGS
8498
@echo "Running tests with tags: $(TAGS)"
8599
go test -v --tags="$(TAGS)" \
@@ -97,53 +111,70 @@ else
97111
done
98112
endif
99113
else
100-
@echo "Running test suite: $(or $(SUITE),all)"
101-
$(MAKE) -C t test args="--suite=$(or $(SUITE),all) $(if $(PKG),--pkg=\"$(PKG)\") $(if $(TEST),--test=\"$(TEST)\") $(if $(TIMEOUT),--timeout=$(TIMEOUT))"
114+
ifdef SUITE
115+
@echo "Running test suite: $(SUITE)"
116+
$(MAKE) -C t test args="--suite=$(SUITE) $(if $(PKG),--pkg=\"$(PKG)\") $(if $(TEST),--test=\"$(TEST)\") $(if $(TIMEOUT),--timeout=$(TIMEOUT))"
117+
else
118+
@echo "Running test suite: integration"
119+
$(MAKE) -C t test args="--suite=integration $(if $(PKG),--pkg=\"$(PKG)\") $(if $(TEST),--test=\"$(TEST)\") $(if $(TIMEOUT),--timeout=$(TIMEOUT))"
120+
@echo "Running integration2 tests..."
121+
go test -v --tags="integration2" \
122+
$(if $(TEST),--run="$(TEST)") \
123+
$(if $(PKG),./$(PKG)/...,./...)
124+
endif
102125
endif
103-
104-
.PHONY: test-all
105-
test-all: ## All test suites via t/ runner (i.e. 'make test SUITE=all')
106-
@SUITE=all $(MAKE) test
107126

108127
.PHONY: test-unit
109-
test-unit: ## Unit tests, no Docker (i.e. 'make test SUITE=unit')
128+
test-unit: ## True unit tests only — no Docker, no integration build tag (i.e. 'make test SUITE=unit')
129+
$(if $(filter command line,$(origin SUITE)),$(error SUITE= cannot be passed to test-unit; use 'make test SUITE=...' instead))
110130
@SUITE=unit $(MAKE) test
111131

132+
.PHONY: test-integration
133+
test-integration: ## Integration tests via t/ runner with Docker (i.e. 'make test SUITE=integration')
134+
$(if $(filter command line,$(origin SUITE)),$(error SUITE= cannot be passed to test-integration; use 'make test SUITE=...' instead))
135+
@SUITE=integration $(MAKE) test
136+
112137
.PHONY: test-core
113138
test-core: ## Core tests (i.e. 'make test SUITE=core')
139+
$(if $(filter command line,$(origin SUITE)),$(error SUITE= cannot be passed to test-core; use 'make test SUITE=...' instead))
114140
@SUITE=core $(MAKE) test
115141

116-
.PHONY: test-integration
117-
test-integration: ## Integration tests (i.e. 'make test TAGS=integration')
118-
@TAGS=integration $(MAKE) test
119-
120142
.PHONY: test-integration2
121143
test-integration2: ## Integration2 tests via dgraphtest (i.e. 'make test TAGS=integration2')
144+
$(if $(filter command line,$(origin TAGS)),$(error TAGS= cannot be passed to test-integration2; use 'make test TAGS=...' instead))
122145
@TAGS=integration2 $(MAKE) test
123146

124147
.PHONY: test-upgrade
125148
test-upgrade: ## Upgrade tests (i.e. 'make test TAGS=upgrade')
149+
$(if $(filter command line,$(origin TAGS)),$(error TAGS= cannot be passed to test-upgrade; use 'make test TAGS=...' instead))
126150
@TAGS=upgrade $(MAKE) test
127151

128152
.PHONY: test-systest
129-
test-systest: ## System integration tests (i.e. 'make test SUITE=systest')
153+
test-systest: ## All systest packages: systest-baseline + systest-heavy (i.e. 'make test SUITE=systest')
154+
$(if $(filter command line,$(origin SUITE)),$(error SUITE= cannot be passed to test-systest; use 'make test SUITE=...' instead))
130155
@SUITE=systest $(MAKE) test
131156

157+
.PHONY: test-integration-heavy
158+
test-integration-heavy: ## All heavy tests: systest-heavy + ldbc + load
159+
$(if $(filter command line,$(origin SUITE)),$(error SUITE= cannot be passed to test-integration-heavy; use 'make test SUITE=...' instead))
160+
@SUITE=systest-heavy,ldbc,load $(MAKE) test
161+
132162
.PHONY: test-vector
133163
test-vector: ## Vector search tests (i.e. 'make test SUITE=vector')
164+
$(if $(filter command line,$(origin SUITE)),$(error SUITE= cannot be passed to test-vector; use 'make test SUITE=...' instead))
134165
@SUITE=vector $(MAKE) test
135166

136167
.PHONY: test-fuzz
137-
test-fuzz: ## Fuzz tests, auto-discovers packages (i.e. 'make test FUZZ=1')
168+
test-fuzz: ## Fuzz tests (i.e. 'make test FUZZ=1')
169+
$(if $(filter command line,$(origin FUZZ)),$(error FUZZ= cannot be passed to test-fuzz; use 'make test FUZZ=...' instead))
138170
@FUZZ=1 $(MAKE) test
139171

140-
.PHONY: test-ldbc
141-
test-ldbc: ## LDBC benchmark tests (i.e. 'make test SUITE=ldbc')
142-
@SUITE=ldbc $(MAKE) test
143-
144-
.PHONY: test-load
145-
test-load: ## Heavy load tests (i.e. 'make test SUITE=load')
146-
@SUITE=load $(MAKE) test
172+
.PHONY: test-all
173+
test-all: ## Every test: all t/ suites + integration2 + upgrade + fuzz
174+
$(MAKE) test SUITE=all
175+
$(MAKE) test-integration2
176+
$(MAKE) test-upgrade
177+
$(MAKE) test-fuzz
147178

148179
.PHONY: test-benchmark
149180
test-benchmark: ## Go benchmarks (i.e. 'go test -bench')
@@ -152,7 +183,11 @@ test-benchmark: ## Go benchmarks (i.e. 'go test -bench')
152183
.PHONY: local-image
153184
local-image: ## Build local Docker image (dgraph/dgraph:local)
154185
@echo building local docker image
155-
@GOOS=linux GOARCH=amd64 $(MAKE) dgraph
186+
ifneq ($(GOHOSTOS),linux)
187+
@GOOS=linux GOARCH=$(GOHOSTARCH) CGO_ENABLED=1 CC=$(LINUX_CC) $(MAKE) BUILD_TAGS= EXTLDFLAGS=-fuse-ld=bfd dgraph
188+
else
189+
@GOOS=linux GOARCH=$(GOHOSTARCH) $(MAKE) dgraph
190+
endif
156191
@mkdir -p linux
157192
@mv ./dgraph/dgraph ./linux/dgraph
158193
@docker build -f contrib/Dockerfile -t dgraph/dgraph:local .
@@ -161,6 +196,13 @@ local-image: ## Build local Docker image (dgraph/dgraph:local)
161196
.PHONY: image-local
162197
image-local: local-image ## Alias for local-image
163198

199+
.PHONY: clean
200+
clean: ## Clean build artifacts
201+
$(MAKE) -C dgraph clean
202+
$(MAKE) -C compose clean
203+
@rm -rf linux
204+
@go clean -testcache
205+
164206
.PHONY: docker-image
165207
docker-image: dgraph ## Build Docker image (dgraph/dgraph:$VERSION)
166208
@mkdir -p linux
@@ -201,7 +243,7 @@ help: ## Show available targets and variables
201243
awk 'BEGIN {FS = ":.*?## "}; {printf " %-20s %s\n", $$1, $$2}'
202244
@echo ""
203245
@echo "Variables that can be passed to 'test':"
204-
@echo " SUITE Select t/ runner suite (e.g., make test SUITE=systest)"
246+
@echo " SUITE Select t/ runner suite (default: integration + integration2)"
205247
@echo " TAGS Go build tags - bypasses t/ runner (e.g., make test TAGS=integration2)"
206248
@echo " PKG Limit to specific package (e.g., make test PKG=systest/export)"
207249
@echo " TEST Run specific test function (e.g., make test TEST=TestGQLSchema)"
@@ -216,8 +258,9 @@ help: ## Show available targets and variables
216258
@printf " Available TAGS values: "
217259
@grep -roh "//go:build [a-z0-9]*" --include="*_test.go" . 2>/dev/null | \
218260
awk '{print $$2}' | \
219-
grep -E '^(integration|integration2|upgrade)$$' | \
261+
grep -E '^(integration2|upgrade)$$' | \
220262
sort -u | tr '\n' ' ' && echo ""
263+
@echo " Note: 'integration' tests require the t/ runner (use SUITE=, not TAGS=)"
221264
@echo ""
222265
@echo "Examples:"
223266
@echo " make test TAGS=integration2 PKG=systest/vector # integration2 tests for vector"

0 commit comments

Comments
 (0)