Skip to main content
Glama
parallel.go1.79 kB
// Package mcptesting provides parallel execution capabilities for MCP tests. package mcptesting import ( "os" "runtime" "strconv" "sync" "testing" ) var ( // globalMutex protects initialization of global resources globalMutex sync.Mutex // maxParallelTests controls the maximum number of parallel tests maxParallelTests = getMaxParallelTests() // isParallelEnabled indicates if parallel testing is enabled isParallelEnabled = true ) // getMaxParallelTests determines the maximum number of parallel tests // based on environment variables or system capabilities func getMaxParallelTests() int { // Check if explicitly set in environment if envVal := os.Getenv("MCP_TEST_PARALLEL"); envVal != "" { if val, err := strconv.Atoi(envVal); err == nil && val > 0 { return val } } // Get number of CPUs and set a reasonable default numProcs := 4 // Default to 4 if we can't determine if n := runtime.NumCPU(); n > 0 { numProcs = n } // Use CPU count - 1 to avoid saturating the system // but ensure at least 1 if numProcs > 1 { return numProcs - 1 } return 1 } // SetParallelEnabled sets whether parallel testing is enabled func SetParallelEnabled(enabled bool) { globalMutex.Lock() defer globalMutex.Unlock() isParallelEnabled = enabled } // SetMaxParallelTests sets the maximum number of parallel tests func SetMaxParallelTests(max int) { globalMutex.Lock() defer globalMutex.Unlock() if max > 0 { maxParallelTests = max } } // RunParallel marks a test to run in parallel if enabled // and sets appropriate parallelism levels func RunParallel(t *testing.T) { globalMutex.Lock() parallelEnabled := isParallelEnabled parallel := maxParallelTests globalMutex.Unlock() if parallelEnabled { t.Parallel() runtime.GOMAXPROCS(parallel) } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/MrFixit96/go-dev-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server