forked from assert200/gorest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgorest.go
62 lines (47 loc) · 1.06 KB
/
gorest.go
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
62
package gorest
import (
"sync"
)
var wg sync.WaitGroup
var firstRestTests []RestTest
// Prime Prime
func Prime(newRestTest RestTest) {
firstRestTests = append(firstRestTests, newRestTest)
}
//Start Start
func Start(workers int) Results {
todoChan := make(chan RestTest, 100000)
doneChan := make(chan RestTest, 100000)
for _, firstRestTest := range firstRestTests {
todoChan <- firstRestTest
wg.Add(1)
}
firstRestTests = nil
for w := 1; w <= workers; w++ {
go worker(&wg, w, todoChan, doneChan)
}
wg.Wait()
close(todoChan)
close(doneChan)
results := Results{}
for testResult := range doneChan {
results.Add(testResult)
}
return results
}
func worker(wg *sync.WaitGroup, id int, todoChan chan RestTest, doneChan chan<- RestTest) {
for todoTest := range todoChan {
doneTest := DoAndVerify(todoTest)
if len(doneTest.Errors) == 0 {
if todoTest.Generator != nil {
newTests := todoTest.Generator(doneTest)
for _, newTest := range newTests {
todoChan <- newTest
wg.Add(1)
}
}
}
doneChan <- doneTest
wg.Done()
}
}