-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfasthttp_service_test.go
122 lines (104 loc) · 3.02 KB
/
fasthttp_service_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package hermes
import (
"sync"
"time"
"github.com/lab259/go-rscsrv"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Services", func() {
Describe("Fasthttp Service", func() {
It("should not return any error loading the service", func() {
var service FasthttpService
result, err := service.LoadConfiguration()
Expect(err).NotTo(BeNil())
Expect(err.Error()).To(ContainSubstring("not implemented"))
Expect(result).To(BeNil())
})
It("should apply a given pointer configuration", func() {
var service FasthttpService
Expect(service.ApplyConfiguration(&FasthttpServiceConfiguration{
Bind: "12345",
})).To(BeNil())
Expect(service.Configuration.Bind).To(Equal("12345"))
})
It("should apply a given configuration", func() {
var service FasthttpService
Expect(service.ApplyConfiguration(FasthttpServiceConfiguration{
Bind: "12345",
})).To(BeNil())
Expect(service.Configuration.Bind).To(Equal("12345"))
})
It("should fail applying a wrong type configuration", func() {
var service FasthttpService
Expect(service.ApplyConfiguration(map[string]interface{}{
"bind": "12345",
})).To(Equal(rscsrv.ErrWrongConfigurationInformed))
})
It("should start and stop the service", func(done Done) {
var service FasthttpService
service.Configuration.Bind = ":32301" // High port
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer GinkgoRecover()
wg.Done()
Expect(service.Start()).To(BeNil())
wg.Done()
}()
wg.Wait()
time.Sleep(time.Millisecond * 500)
wg.Add(1)
Expect(service.Stop()).To(BeNil())
wg.Wait()
done <- true
}, 1)
It("should restart the service that is not started", func(done Done) {
var service FasthttpService
service.Configuration.Bind = ":32301" // High port
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer GinkgoRecover()
wg.Done()
Expect(service.Restart()).To(BeNil())
wg.Done()
}()
wg.Wait()
time.Sleep(time.Millisecond * 500)
wg.Add(1)
Expect(service.Stop()).To(BeNil())
wg.Wait()
done <- true
}, 1)
It("should stop a stopped service", func() {
var service FasthttpService
Expect(service.Stop()).To(BeNil())
})
It("should restart the service", func(done Done) {
var service FasthttpService
service.Configuration.Bind = ":32301" // High port
ch := make(chan string, 10)
// Just ignore result
go func() {
ch <- "service:step1:begin"
service.Start()
ch <- "service:step1:end"
}()
time.Sleep(time.Millisecond * 500) // Waits for the service a bit
go func() {
ch <- "service:step2:begin"
service.Restart()
time.Sleep(time.Millisecond * 500)
ch <- "service:step2:end"
}()
time.Sleep(time.Millisecond * 500) // Waits for the service a bit
Expect(service.Stop()).To(BeNil())
Expect(<-ch).To(Equal("service:step1:begin"))
Expect(<-ch).To(Equal("service:step2:begin"))
Expect(<-ch).To(Equal("service:step1:end"))
Expect(<-ch).To(Equal("service:step2:end"))
done <- true
}, 2)
})
})