Skip to content

Commit dfef2c3

Browse files
committed
fix(test): resolve integration test routing, gotestsum PATH, and cross-compilation
- Remove broken test-integration target: TAGS=integration bypassed the t/ runner, skipping Docker Compose orchestration and plugin compilation that integration tests require. Use SUITE= to route through the t/ runner instead. - Fix gotestsum PATH resolution in t/t.go: add gotestsumBin() that resolves to $GOPATH/bin/gotestsum instead of relying on PATH lookup, which fails on machines where $GOPATH/bin is not in PATH. - Add cross-compilation support for Go plugins on macOS: detect non-Linux hosts and set CGO_ENABLED=1, CC to the appropriate cross-compiler, and use the BFD linker (both testutil/plugin.go and dgraphtest/local_cluster.go). - Add check-cross-compiler.sh dependency check script. - Add top-level make deps and make setup targets for dependency management. - Update TESTING.md and CONTRIBUTING.md to document new targets and recommend make setup for first-time onboarding. - Remove test-integration from test-full (redundant: SUITE=all covers it).
1 parent 3d85069 commit dfef2c3

8 files changed

Lines changed: 216 additions & 28 deletions

File tree

CONTRIBUTING.md

Lines changed: 5 additions & 1 deletion
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,6 +145,9 @@ directory, providing control and flexibility beyond the standard Go testing fram
144145
The simplest way to run tests is via Make:
145146

146147
```bash
148+
# First-time setup: install tool dependencies
149+
make setup
150+
147151
# Run default tests (~30 min): unit, systest, core suites + integration2
148152
make test
149153

Makefile

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ dgraph-installed:
7878
$(MAKE) install; \
7979
fi
8080

81+
.PHONY: deps
82+
deps: ## Check test dependencies (pass AUTO_INSTALL=true to auto-install missing ones)
83+
$(MAKE) -C t check
84+
85+
.PHONY: setup
86+
setup: ## Install all test dependencies automatically
87+
$(MAKE) deps AUTO_INSTALL=true
88+
8189
.PHONY: test
8290
test: dgraph-installed local-image ## Run tests (default: unit,systest,core + integration2)
8391
ifdef TAGS
@@ -124,11 +132,6 @@ test-core: ## Core tests (i.e. 'make test SUITE=core')
124132
$(if $(filter command line,$(origin SUITE)),$(error SUITE= cannot be passed to test-core; use 'make test SUITE=...' instead))
125133
@SUITE=core $(MAKE) test
126134

127-
.PHONY: test-integration
128-
test-integration: ## Integration tests (i.e. 'make test TAGS=integration')
129-
$(if $(filter command line,$(origin TAGS)),$(error TAGS= cannot be passed to test-integration; use 'make test TAGS=...' instead))
130-
@TAGS=integration $(MAKE) test
131-
132135
.PHONY: test-integration2
133136
test-integration2: ## Integration2 tests via dgraphtest (i.e. 'make test TAGS=integration2')
134137
$(if $(filter command line,$(origin TAGS)),$(error TAGS= cannot be passed to test-integration2; use 'make test TAGS=...' instead))
@@ -165,9 +168,8 @@ test-load: ## Heavy load tests (i.e. 'make test SUITE=load')
165168
@SUITE=load $(MAKE) test
166169

167170
.PHONY: test-full
168-
test-full: ## Every test: all suites + integration + integration2 + upgrade + fuzz
171+
test-full: ## Every test: all suites + integration2 + upgrade + fuzz
169172
$(MAKE) test-suite
170-
$(MAKE) test-integration
171173
$(MAKE) test-integration2
172174
$(MAKE) test-upgrade
173175
$(MAKE) test-fuzz
@@ -188,6 +190,13 @@ local-image: ## Build local Docker image (dgraph/dgraph:local)
188190
.PHONY: image-local
189191
image-local: local-image ## Alias for local-image
190192

193+
.PHONY: clean
194+
clean: ## Clean build artifacts
195+
$(MAKE) -C dgraph clean
196+
$(MAKE) -C compose clean
197+
@rm -rf linux
198+
@go clean -testcache
199+
191200
.PHONY: docker-image
192201
docker-image: dgraph ## Build Docker image (dgraph/dgraph:$VERSION)
193202
@mkdir -p linux
@@ -243,8 +252,9 @@ help: ## Show available targets and variables
243252
@printf " Available TAGS values: "
244253
@grep -roh "//go:build [a-z0-9]*" --include="*_test.go" . 2>/dev/null | \
245254
awk '{print $$2}' | \
246-
grep -E '^(integration|integration2|upgrade)$$' | \
255+
grep -E '^(integration2|upgrade)$$' | \
247256
sort -u | tr '\n' ' ' && echo ""
257+
@echo " Note: 'integration' tests require the t/ runner (use SUITE=, not TAGS=)"
248258
@echo ""
249259
@echo "Examples:"
250260
@echo " make test TAGS=integration2 PKG=systest/vector # integration2 tests for vector"

TESTING.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,20 +128,24 @@ The codebase is organized into several key packages:
128128

129129
Before running tests, ensure you have the following installed and configured.
130130

131-
> **TL;DR:** On a fresh checkout, just run `make install` followed by `make test`. The build system
132-
> automatically handles OS detection, builds the correct binaries, and validates dependencies.
131+
> **TL;DR:** On a fresh checkout, run `make setup` to auto-install tool dependencies, then
132+
> `make install` followed by `make test`. The build system automatically handles OS detection,
133+
> builds the correct binaries, and validates dependencies.
133134
134135
### Automatic Dependency Checking
135136

136137
The test framework includes scripts that check for required dependencies and can optionally
137138
auto-install them:
138139

139140
```bash
140-
# Check all dependencies (run from t/ directory)
141-
cd t && make check
141+
# Auto-install all missing tool dependencies (recommended for first-time setup)
142+
make setup
142143

143-
# Auto-install missing dependencies
144-
AUTO_INSTALL=true make check
144+
# Check dependencies without installing (reports what's missing)
145+
make deps
146+
147+
# Same as 'make deps' but auto-installs anything missing
148+
make deps AUTO_INSTALL=true
145149
```
146150

147151
The check scripts validate:
@@ -154,9 +158,8 @@ The check scripts validate:
154158

155159
### Required Tools
156160

157-
> **Note:** You don't need to install these manually. Running `AUTO_INSTALL=true make check` from
158-
> the `t/` directory (or `AUTO_INSTALL=true make test` from the repo root) automatically installs
159-
> missing dependencies. The commands below are listed for reference.
161+
> **Note:** You don't need to install these manually. Running `make setup` from the repo root
162+
> automatically installs missing dependencies. The commands below are listed for reference.
160163
161164
#### 1. Go (1.21+)
162165

@@ -222,8 +225,8 @@ dgraph version
222225
The build system now handles most setup automatically. On both Linux and macOS:
223226

224227
```bash
225-
# Install dependencies (optional - auto-installs if missing)
226-
cd t && AUTO_INSTALL=true make check && cd ..
228+
# Auto-install tool dependencies (gotestsum, ack, etc.)
229+
make setup
227230

228231
# Build dgraph binary (automatically handles Linux binary on macOS)
229232
make install
@@ -318,7 +321,6 @@ make test-systest # System integration tests (i.e. 'make test SUITE=systes
318321
make test-vector # Vector search tests (i.e. 'make test SUITE=vector')
319322
make test-ldbc # LDBC benchmark tests (i.e. 'make test SUITE=ldbc')
320323
make test-load # Heavy load tests (i.e. 'make test SUITE=load')
321-
make test-integration # Integration tests (i.e. 'make test TAGS=integration')
322324
make test-integration2 # Integration2 tests via dgraphtest (i.e. 'make test TAGS=integration2')
323325
make test-upgrade # Upgrade tests (i.e. 'make test TAGS=upgrade')
324326
make test-fuzz # Fuzz tests (i.e. 'make test FUZZ=1')
@@ -1301,7 +1303,7 @@ The following items from the original wishlist have been implemented:
13011303
make test SUITE=systest
13021304
make test FUZZ=1 PKG=dql
13031305
make test TAGS=upgrade PKG=acl
1304-
make test TAGS=integration PKG=systest/plugin
1306+
make test-suite SUITE=systest PKG=systest/plugin
13051307
```
13061308

13071309
### Remaining Ideas

dgraphtest/local_cluster.go

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,11 +1322,19 @@ func (c *LocalCluster) GeneratePlugins(raceEnabled bool) error {
13221322
if raceEnabled {
13231323
opts = append(opts, "-race")
13241324
}
1325-
opts = append(opts, "-buildmode=plugin", "-o", so, src)
1326-
os.Setenv("GOOS", "linux")
1327-
os.Setenv("GOARCH", "amd64")
1325+
opts = append(opts, "-buildmode=plugin")
1326+
if runtime.GOOS != "linux" {
1327+
// Use the BFD linker; the default gold linker is not shipped
1328+
// with most cross-compiler toolchains.
1329+
opts = append(opts, "-ldflags", "-extldflags -fuse-ld=bfd")
1330+
}
1331+
opts = append(opts, "-o", so, src)
13281332
cmd := exec.Command("go", opts...)
13291333
cmd.Dir = filepath.Dir(curr)
1334+
cmd.Env = append(os.Environ(), "GOOS=linux", "GOARCH="+runtime.GOARCH)
1335+
if runtime.GOOS != "linux" {
1336+
cmd.Env = append(cmd.Env, "CGO_ENABLED=1", "CC="+linuxCrossCC())
1337+
}
13301338
if out, err := cmd.CombinedOutput(); err != nil {
13311339
log.Printf("Error: %v\n", err)
13321340
log.Printf("Output: %v\n", string(out))
@@ -1347,6 +1355,22 @@ func (c *LocalCluster) GeneratePlugins(raceEnabled bool) error {
13471355
return nil
13481356
}
13491357

1358+
// linuxCrossCC returns the C cross-compiler for targeting Linux from the current host.
1359+
// Respects the LINUX_CC environment variable if set.
1360+
func linuxCrossCC() string {
1361+
if cc := os.Getenv("LINUX_CC"); cc != "" {
1362+
return cc
1363+
}
1364+
switch runtime.GOARCH {
1365+
case "arm64":
1366+
return "aarch64-unknown-linux-gnu-gcc"
1367+
case "amd64":
1368+
return "x86_64-unknown-linux-gnu-gcc"
1369+
default:
1370+
return "gcc"
1371+
}
1372+
}
1373+
13501374
func (c *LocalCluster) GetAlphaGrpcPublicPort(id int) (string, error) {
13511375
return publicPort(c.dcli, c.alphas[id], alphaGrpcPort)
13521376
}

t/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ endif
1919
all: test
2020

2121
.PHONY: check
22-
check: check-go check-docker check-gotestsum check-ack
22+
check: check-go check-docker check-gotestsum check-ack check-cross-compiler
2323
@if [ "$(GOOS)" = "linux" ]; then \
2424
which protoc > /dev/null 2>&1 || (echo "Error: protoc is not installed or not in PATH" && exit 1); \
2525
fi
@@ -44,6 +44,10 @@ check-gotestsum:
4444
check-ack:
4545
@./scripts/check-ack.sh
4646

47+
.PHONY: check-cross-compiler
48+
check-cross-compiler:
49+
@./scripts/check-cross-compiler.sh
50+
4751
.PHONY: check-protoc
4852
check-protoc:
4953
@./scripts/check-protoc.sh

t/scripts/check-cross-compiler.sh

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/usr/bin/env bash
2+
# shellcheck disable=SC2310
3+
set -euo pipefail
4+
5+
# shellcheck source=checkhelper.sh
6+
source "$(dirname "${BASH_SOURCE[0]}")/checkhelper.sh"
7+
8+
BREW_TAP="messense/macos-cross-toolchains"
9+
10+
# Return the expected cross-compiler binary name for the host architecture.
11+
get_cross_compiler() {
12+
if [[ -n ${LINUX_CC-} ]]; then
13+
echo "${LINUX_CC}"
14+
return
15+
fi
16+
local arch
17+
arch="$(uname -m)"
18+
case "${arch}" in
19+
arm64 | aarch64)
20+
echo "aarch64-unknown-linux-gnu-gcc"
21+
;;
22+
x86_64)
23+
echo "x86_64-unknown-linux-gnu-gcc"
24+
;;
25+
*)
26+
err "unsupported architecture: ${arch}"
27+
return 1
28+
;;
29+
esac
30+
}
31+
32+
# Return the Homebrew formula name for the cross-compiler.
33+
get_brew_formula() {
34+
local arch
35+
arch="$(uname -m)"
36+
case "${arch}" in
37+
arm64 | aarch64)
38+
echo "aarch64-unknown-linux-gnu"
39+
;;
40+
x86_64)
41+
echo "x86_64-unknown-linux-gnu"
42+
;;
43+
*)
44+
err "unsupported architecture: ${arch}"
45+
return 1
46+
;;
47+
esac
48+
}
49+
50+
install_cross_compiler_macos() {
51+
ensure_brew || exit 1
52+
local formula
53+
formula="$(get_brew_formula)"
54+
brew tap "${BREW_TAP}"
55+
brew install "${BREW_TAP}/${formula}"
56+
}
57+
58+
main() {
59+
# Cross-compiler is only needed on non-Linux systems
60+
if [[ "$(get_os)" == "Linux" ]]; then
61+
exit 0
62+
fi
63+
64+
local cc
65+
cc="$(get_cross_compiler)"
66+
67+
if command -v "${cc}" &>/dev/null; then
68+
exit 0
69+
fi
70+
71+
if [[ ${AUTO_INSTALL-} == "true" ]]; then
72+
install_cross_compiler_macos
73+
if command -v "${cc}" &>/dev/null; then
74+
exit 0
75+
else
76+
err "cross-compiler check still failing after installation"
77+
exit 1
78+
fi
79+
fi
80+
81+
echo ""
82+
err "Linux cross-compiler is not installed (needed for Go plugin builds)"
83+
echo ""
84+
err "Required binary: ${cc}"
85+
echo ""
86+
err "Please install manually:"
87+
88+
case "$(get_os)" in
89+
Darwin)
90+
local formula
91+
formula="$(get_brew_formula)"
92+
err " brew tap ${BREW_TAP}"
93+
err " brew install ${BREW_TAP}/${formula}"
94+
echo ""
95+
err 'Or set LINUX_CC to a custom cross-compiler (e.g. "zig cc -target ...")'
96+
;;
97+
*)
98+
err " (install a gcc cross-compiler targeting linux for your architecture)"
99+
;;
100+
esac
101+
102+
print_auto_install_hint
103+
exit 1
104+
}
105+
106+
main "$@"

t/t.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,19 @@ func sanitizeFilename(pkg string) string {
422422
return strings.ReplaceAll(pkg, "/", "_")
423423
}
424424

425+
// gotestsumBin returns the absolute path to gotestsum inside $GOPATH/bin.
426+
// This avoids relying on $PATH, which may not include $GOPATH/bin on all machines
427+
// (the check-gotestsum.sh script validates at this same path).
428+
func gotestsumBin() string {
429+
gopath := os.Getenv("GOPATH")
430+
if gopath == "" {
431+
gopath = filepath.Join(os.Getenv("HOME"), "go")
432+
}
433+
return filepath.Join(gopath, "bin", "gotestsum")
434+
}
435+
425436
func runTestsFor(ctx context.Context, pkg, prefix string, xmlFile string) error {
426-
args := []string{"gotestsum", "--junitfile", xmlFile, "--format", "standard-verbose", "--max-fails", "1", "--",
437+
args := []string{gotestsumBin(), "--junitfile", xmlFile, "--format", "standard-verbose", "--max-fails", "1", "--",
427438
"-v", "-failfast", "-tags=integration"}
428439
switch {
429440
case *testTimeout != "":

testutil/plugin.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package testutil
77

88
import (
99
"fmt"
10+
"os"
1011
"os/exec"
1112
"path/filepath"
1213
"runtime"
@@ -33,9 +34,19 @@ func GeneratePlugins(raceEnabled bool) {
3334
if raceEnabled {
3435
opts = append(opts, "-race")
3536
}
36-
opts = append(opts, "-buildmode=plugin", "-o", so, src)
37+
opts = append(opts, "-buildmode=plugin")
38+
if runtime.GOOS != "linux" {
39+
// Use the BFD linker; the default gold linker is not shipped
40+
// with most cross-compiler toolchains.
41+
opts = append(opts, "-ldflags", "-extldflags -fuse-ld=bfd")
42+
}
43+
opts = append(opts, "-o", so, src)
3744
cmd := exec.Command("go", opts...)
3845
cmd.Dir = filepath.Dir(curr)
46+
cmd.Env = append(os.Environ(), "GOOS=linux", "GOARCH="+runtime.GOARCH)
47+
if runtime.GOOS != "linux" {
48+
cmd.Env = append(cmd.Env, "CGO_ENABLED=1", "CC="+linuxCC())
49+
}
3950
if out, err := cmd.CombinedOutput(); err != nil {
4051
fmt.Printf("Error: %v\n", err)
4152
fmt.Printf("Output: %v\n", string(out))
@@ -51,3 +62,19 @@ func GeneratePlugins(raceEnabled bool) {
5162

5263
fmt.Printf("plugin build completed. Files are: %s\n", strings.Join(soFiles, ","))
5364
}
65+
66+
// linuxCC returns the C cross-compiler for targeting Linux from the current host.
67+
// Respects the LINUX_CC environment variable if set.
68+
func linuxCC() string {
69+
if cc := os.Getenv("LINUX_CC"); cc != "" {
70+
return cc
71+
}
72+
switch runtime.GOARCH {
73+
case "arm64":
74+
return "aarch64-unknown-linux-gnu-gcc"
75+
case "amd64":
76+
return "x86_64-unknown-linux-gnu-gcc"
77+
default:
78+
return "gcc"
79+
}
80+
}

0 commit comments

Comments
 (0)