MCPcopy Create free account
hub / github.com/astercloud/aster / RunConcurrentTest

Function RunConcurrentTest

pkg/tools/builtin/testutils.go:420–452  ·  view source on GitHub ↗

RunConcurrentTest 运行并发测试

(concurrency int, testFunc func() error)

Source from the content-addressed store, hash-verified

418
419// RunConcurrentTest 运行并发测试
420func RunConcurrentTest(concurrency int, testFunc func() error) *ConcurrentTestResult {
421 results := make(chan error, concurrency)
422
423 start := time.Now()
424
425 // 启动并发goroutines
426 for range concurrency {
427 go func() {
428 results <- testFunc()
429 }()
430 }
431
432 // 收集结果
433 successCount := 0
434 errorCount := 0
435 var errors []error
436
437 for range concurrency {
438 if err := <-results; err != nil {
439 errorCount++
440 errors = append(errors, err)
441 } else {
442 successCount++
443 }
444 }
445
446 return &ConcurrentTestResult{
447 SuccessCount: successCount,
448 ErrorCount: errorCount,
449 Errors: errors,
450 Duration: time.Since(start),
451 }
452}
453
454// SkipIfShort 如果是短测试模式则跳过
455func SkipIfShort(t *testing.T) {

Calls

no outgoing calls