-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfra_test.go
114 lines (89 loc) · 2.33 KB
/
infra_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
package reinfra_test
import (
"context"
"fmt"
"github.com/ds0nt/reinfra"
"github.com/ds0nt/reinfra/components"
"github.com/ds0nt/reinfra/readymanager"
"github.com/ds0nt/reinfra/service"
"github.com/ds0nt/reinfra/test"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("readymanager", func() {
It("readymanager should work", func() {
r := readymanager.ReadyManager{}
Expect(r.Ready()).To(BeFalse())
Expect(r.Ready()).To(BeFalse())
go func() {
r.SetReady()
Expect(r.Ready()).To(BeTrue())
}()
<-r.ReadyCh()
Expect(r.Ready()).To(BeTrue())
Expect(r.Ready()).To(BeTrue())
r.SetUnready()
Expect(r.Ready()).To(BeFalse())
Expect(r.Ready()).To(BeFalse())
go func() {
r.SetReady()
Expect(r.Ready()).To(BeTrue())
}()
<-r.ReadyCh()
Expect(r.Ready()).To(BeTrue())
Expect(r.Ready()).To(BeTrue())
})
})
var _ = Describe("Infra", func() {
It("should find and initialize it's service", func(done Done) {
type testService struct {
*service.Service
*components.GRPCServer
}
s := testService{}
Expect(s.Service).To(BeNil())
reinfra.Init(&s)
Expect(s.Service).NotTo(BeNil())
Expect(s.Service.Ready()).To(BeFalse())
ctx, cancel := context.WithCancel(context.Background())
errCh := reinfra.Run(ctx, &s)
s.Service.WaitForReady(ctx)
Expect(s.Service.Ready()).To(BeTrue())
cancel()
for err := range errCh {
fmt.Println("Service Err Ch", err)
}
Expect(s.Service.Ready()).To(BeFalse())
close(done)
}, 0.5)
It("should be able to serve and dial GRPC", func(done Done) {
ctx, cancel := context.WithCancel(context.Background())
type testDialerService struct {
*service.Service
*test.TestDialer
}
s := test.TestService{}
reinfra.Init(&s)
test.RegisterTestServer(s.GRPCServer.Server(), &s)
errCh := reinfra.Run(ctx, &s)
s.Service.WaitForReady(ctx)
s2 := testDialerService{}
reinfra.Init(&s2)
s2.TestDialer.Addr = s.GRPCServer.Addr
errCh2 := reinfra.Run(ctx, &s2)
s2.Service.WaitForReady(ctx)
resp, err := s2.TestClient().Create(context.Background(), &test.TestMessage{
Message: "hello",
})
Expect(err).To(BeNil())
Expect(resp.Message).To(Equal("hello"))
cancel()
for err := range errCh {
fmt.Println("Service Err Ch", err)
}
for err := range errCh2 {
fmt.Println("Service Err Ch", err)
}
close(done)
}, 0.5)
})