-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
59 lines (49 loc) · 1.32 KB
/
main_test.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
package dispatcher_test
import (
"bytes"
"encoding/json"
"fmt"
"math/rand"
"net/http"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Testing with Ginkgo", func() {
It("checks dispatcher, OK", func() {
totalExpected, urlsSent := 0, 500
for i := 0; i < urlsSent; i++ {
r := rand.Intn(30)
totalExpected += r
go func() {
defer GinkgoRecover()
url := fmt.Sprintf("%s/treat", server.URL)
b, err := json.Marshal(testInput{
URL: fmt.Sprintf("%s%s%d", mServer.URL, pageAddr, r),
What: "Go",
})
Expect(err).NotTo(HaveOccurred())
resp, err := http.Post(url, "application/json", bytes.NewReader(b))
Expect(err).NotTo(HaveOccurred())
Expect(resp.StatusCode).To(Equal(http.StatusOK))
}()
// check that workers count don't exceeds max limit
workers := dispatcher.Workers()
fmt.Println("Workers:", workers)
}
attempts, ticker := 0, time.NewTicker(time.Second)
for {
<-ticker.C
attempts++
if dispatcher.TasksDone() == urlsSent {
ticker.Stop()
break
}
Expect(attempts).To(BeNumerically("<=", 5), "too long!")
}
Expect(dispatcher.ErrorCount()).To(Equal(0))
Expect(totalFound.Get()).To(BeNumerically("==", totalExpected),
"totalFound != totalExpected, %d != %d", totalFound, totalExpected)
dispatcher.Stop()
})
})