Repository navigation
Expand file tree
/
Copy pathintegration_setup_test.go
More file actions
61 lines (48 loc) · 1.93 KB
/
Copy pathintegration_setup_test.go
File metadata and controls
61 lines (48 loc) · 1.93 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
//go:build integration
package picoloom
// Notes:
// - Integration test setup: shared ServicePool for all integration tests
// - testPool is initialized in TestMain and closed after all tests complete
// - acquireService helper provides automatic cleanup via t.Cleanup()
// - Pool size is capped at 4 for CI environments to avoid resource exhaustion
import (
"os"
"testing"
"time"
)
// ---------------------------------------------------------------------------
// Test Configuration
// ---------------------------------------------------------------------------
// testTimeout is the standard timeout for integration test operations.
const testTimeout = 30 * time.Second
// testPool is the shared ServicePool for all integration tests.
// It is initialized in TestMain and closed after all tests complete.
// Safe for concurrent use: tests only Acquire/Release, never modify the pool.
var testPool *ServicePool
// ---------------------------------------------------------------------------
// TestMain - Integration Test Setup and Teardown
// ---------------------------------------------------------------------------
func TestMain(m *testing.M) {
// Create pool with auto-sized capacity based on CPU cores.
// Use a conservative size for CI environments.
poolSize := ResolvePoolSize(0)
if poolSize > 4 {
poolSize = 4 // Cap at 4 to avoid resource exhaustion in CI
}
testPool = NewServicePool(poolSize)
code := m.Run()
// Cleanup all browser instances
testPool.Close()
os.Exit(code)
}
// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------
// acquireService gets a service from the shared pool with automatic cleanup.
// Uses t.Cleanup() to ensure Release is called even if test panics.
func acquireService(t *testing.T) *Service {
t.Helper()
svc := testPool.Acquire()
t.Cleanup(func() { testPool.Release(svc) })
return svc
}