Skip to content

Commit 507762a

Browse files
committed
Test fixes, add macOS linker warning docs
- Fix timing issues in performance and goroutine leak tests - Add *.out to .gitignore for coverage files - Add make test-clean target to run tests without linker warnings - Document LC_DYSYMTAB warnings on macOS with CGO enabled
1 parent 34a5de7 commit 507762a

File tree

5 files changed

+84
-9
lines changed

5 files changed

+84
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ examples/plugins/vault-backend/vault-backend
2727
examples/plugins/vault-backend/vault:/invalid-token@localhost:8200/logs
2828
examples/plugins/vault-backend/vault:/test-token@localhost:8200/logs
2929
examples/plugins/nats-backend/nats-backend
30+
*.out

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ test-unit:
2020
# Run tests (alias for test-unit)
2121
test: test-unit
2222

23+
# Run tests without linker warnings (CGO disabled)
24+
test-clean:
25+
@echo "Running tests without linker warnings (CGO disabled)..."
26+
@CGO_ENABLED=0 go test ./...
27+
2328
# Run tests with verbose output
2429
test-verbose:
2530
@echo "Running tests with verbose output..."
@@ -28,6 +33,7 @@ test-verbose:
2833
# Run tests with race detector (may show linker warnings on macOS)
2934
test-race:
3035
@echo "Running tests with race detector..."
36+
@echo "Note: LC_DYSYMTAB warnings on macOS are a known Go issue and can be safely ignored"
3137
@go test -v -race -coverprofile=coverage.out $(shell go list ./... | grep -v /examples/)
3238

3339
# Run integration tests
@@ -190,6 +196,7 @@ help:
190196
@echo " build - Build the library"
191197
@echo " test - Run unit tests (alias for test-unit)"
192198
@echo " test-unit - Run unit tests (CGO disabled, no linker warnings)"
199+
@echo " test-clean - Run tests without linker warnings (CGO disabled)"
193200
@echo " test-verbose - Run tests with verbose output"
194201
@echo " test-race - Run tests with race detector (may show warnings)"
195202
@echo " test-integration - Run integration tests"

docs/macos-linker-warnings.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# macOS Linker Warnings
2+
3+
## Issue
4+
5+
When running Go tests on macOS (especially on Apple Silicon/arm64), you may encounter linker warnings like:
6+
7+
```
8+
ld: warning: '/private/var/folders/.../000012.o' has malformed LC_DYSYMTAB,
9+
expected 98 undefined symbols to start at index 1626, found 95 undefined symbols starting at index 1626
10+
```
11+
12+
## Cause
13+
14+
These warnings are caused by a known issue with the Go toolchain on macOS when CGO is enabled. The linker (ld) detects a mismatch in the symbol table of the generated object files.
15+
16+
## Solution
17+
18+
### Option 1: Disable CGO (Recommended for tests)
19+
20+
Run tests with CGO disabled to avoid the warnings:
21+
22+
```bash
23+
CGO_ENABLED=0 go test ./...
24+
```
25+
26+
Or use the Makefile targets:
27+
28+
```bash
29+
make test # Uses CGO_ENABLED=0
30+
make test-clean # Explicitly runs without CGO
31+
```
32+
33+
### Option 2: Ignore the warnings
34+
35+
These warnings are harmless and don't affect the functionality of your tests or binaries. They can be safely ignored.
36+
37+
### Option 3: Use specific linker flags
38+
39+
For production builds where CGO is required, you can suppress debug information:
40+
41+
```bash
42+
go build -ldflags="-w -s" ./...
43+
```
44+
45+
## When CGO is Required
46+
47+
Some tests, particularly those using the race detector, require CGO:
48+
49+
```bash
50+
make test-race # Will show warnings but is necessary for race detection
51+
```
52+
53+
## References
54+
55+
- [Go Issue #61229](https://github.com/golang/go/issues/61229)
56+
- [Apple Developer Forums Discussion](https://developer.apple.com/forums/thread/737577)

examples/performance-optimized/main_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func TestPerformanceOptimizedExample(t *testing.T) {
6969
}
7070

7171
logger.FlushAll()
72+
time.Sleep(50 * time.Millisecond) // Allow time for file to be created
7273

7374
// Verify log file was created
7475
if stat, err := os.Stat("test_performance.log"); err != nil {

pkg/omni/goroutine_leak_test.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,22 +153,32 @@ func TestShutdownTimeout(t *testing.T) {
153153
t.Fatalf("Failed to create logger: %v", err)
154154
}
155155

156-
// Fill the message channel
157-
for i := 0; i < 1000; i++ {
158-
logger.Info("Message %d", i)
159-
}
160-
161-
// Get initial goroutine count
156+
// Get initial goroutine count before filling channel
162157
initialGoroutines := runtime.NumGoroutine()
163158

159+
// Fill the message channel to ensure shutdown takes time
160+
channelSize := 1000
161+
for i := 0; i < channelSize*2; i++ {
162+
select {
163+
case logger.msgChan <- LogMessage{
164+
Level: LevelInfo,
165+
Timestamp: time.Now(),
166+
Format: "Message %d",
167+
Args: []interface{}{i},
168+
}:
169+
default:
170+
// Channel is full, which is what we want
171+
}
172+
}
173+
164174
// Shutdown with very short timeout
165175
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Millisecond)
166176
err = logger.Shutdown(ctx)
167177
cancel()
168178

169-
// Should get timeout error
170-
if err == nil {
171-
t.Error("Expected timeout error, got nil")
179+
// Should get timeout error since channel is full and processing takes time
180+
if err == nil || err != context.DeadlineExceeded {
181+
t.Errorf("Expected context deadline exceeded error, got %v", err)
172182
}
173183

174184
// Wait for background cleanup

0 commit comments

Comments
 (0)