MCPcopy Create free account
hub / github.com/cloudwan/gohan / RunTests

Function RunTests

extension/framework/framework.go:98–159  ·  view source on GitHub ↗

RunTests runs extension tests for CLI.

(testFiles []string, printAllLogs bool, testFilter string, workers int)

Source from the content-addressed store, hash-verified

96
97// RunTests runs extension tests for CLI.
98func RunTests(testFiles []string, printAllLogs bool, testFilter string, workers int) (returnCode int) {
99 if !printAllLogs {
100 l.SetUpBasicLogging(l.BufWritter{}, l.DefaultFormat)
101 }
102
103 if workers <= 0 {
104 panic("Workers must be greater than 0")
105 }
106
107 if len(testFiles) < workers {
108 workers = len(testFiles)
109 }
110
111 var (
112 maxIdx = int64(len(testFiles) - 1)
113 idx int64 = -1
114 errors = make(map[string]runner.TestRunnerErrors)
115 errorsMu sync.Mutex
116 wg sync.WaitGroup
117 )
118
119 worker := func() {
120 for {
121 i := atomic.AddInt64(&idx, 1)
122 if i > maxIdx {
123 break
124 }
125
126 fileName := testFiles[i]
127 testErr := runner.NewTestRunner(fileName, printAllLogs, testFilter).Run()
128
129 errorsMu.Lock()
130 errors[fileName] = testErr
131 errorsMu.Unlock()
132
133 if err, ok := testErr[runner.GeneralError]; ok {
134 log.Error(fmt.Sprintf("\t ERROR (%s): %v", fileName, err))
135 }
136 }
137 wg.Done()
138 }
139
140 // force goroutine local manager
141 singleton.SetScope(singleton.ScopeGLSSingleton)
142
143 for workers > 0 {
144 wg.Add(1)
145 go worker()
146 workers--
147 }
148 wg.Wait()
149
150 summary := makeSummary(errors)
151 printSummary(summary, printAllLogs)
152
153 for _, err := range summary {
154 if err != nil {
155 return 1

Callers 1

TestExtensionsFunction · 0.70

Calls 8

makeSummaryFunction · 0.85
printSummaryFunction · 0.85
WaitMethod · 0.80
LockMethod · 0.65
UnlockMethod · 0.65
ErrorMethod · 0.65
RunMethod · 0.45
AddMethod · 0.45

Tested by 1

TestExtensionsFunction · 0.56