-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathmeasure.go
66 lines (54 loc) · 1.92 KB
/
measure.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
63
64
65
66
package testing
import (
"fmt"
"github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/types"
. "github.com/onsi/gomega"
)
//HTTPMeasure runs the specified specs in an http test
func HTTPMeasure(description string, setup func(map[string]interface{}), f func(string, map[string]interface{}), timeout float64) bool {
return measure(description, setup, f, timeout, types.FlagTypeNone)
}
//FHTTPMeasure runs the specified specs in an http test
func FHTTPMeasure(description string, setup func(map[string]interface{}), f func(string, map[string]interface{}), timeout float64) bool {
return measure(description, setup, f, timeout, types.FlagTypeFocused)
}
//XHTTPMeasure runs the specified specs in an http test
func XHTTPMeasure(description string, setup func(map[string]interface{}), f func(string, map[string]interface{}), timeout float64) bool {
return measure(description, setup, f, timeout, types.FlagTypePending)
}
func measure(description string, setup func(map[string]interface{}), f func(string, map[string]interface{}), timeout float64, flagType types.FlagType) bool {
app := GetDefaultTestApp()
d := func(t string, f func()) { ginkgo.Describe(t, f) }
if flagType == types.FlagTypeFocused {
d = func(t string, f func()) { ginkgo.FDescribe(t, f) }
}
if flagType == types.FlagTypePending {
d = func(t string, f func()) { ginkgo.XDescribe(t, f) }
}
d("Measure", func() {
var loops int
var ctx map[string]interface{}
BeforeOnce(func() {
InitializeTestServer(app)
ctx = map[string]interface{}{"app": app}
setup(ctx)
})
ginkgo.AfterEach(func() {
loops++
if loops == 200 {
transport.CloseIdleConnections()
}
})
ginkgo.Measure(description, func(b ginkgo.Benchmarker) {
runtime := b.Time("runtime", func() {
f(app.HTTPEndpoint, ctx)
})
Expect(runtime.Seconds()).Should(
BeNumerically("<", timeout),
fmt.Sprintf("%s shouldn't take too long.", description),
)
}, 200)
})
return true
}