forked from akash-network/provider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitor_test.go
141 lines (121 loc) · 3.81 KB
/
monitor_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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package cluster
import (
"testing"
manifest "github.com/akash-network/node/manifest/v2beta1"
"github.com/akash-network/node/pubsub"
"github.com/akash-network/node/testutil"
"github.com/boz/go-lifecycle"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/akash-network/provider/cluster/mocks"
ctypes "github.com/akash-network/provider/cluster/types/v1beta2"
"github.com/akash-network/provider/event"
"github.com/akash-network/provider/session"
)
func TestMonitorInstantiate(t *testing.T) {
myLog := testutil.Logger(t)
bus := pubsub.NewBus()
lid := testutil.LeaseID(t)
group := &manifest.Group{}
client := &mocks.Client{}
statusResult := &ctypes.LeaseStatus{}
client.On("LeaseStatus", mock.Anything, lid).Return(statusResult, nil)
mySession := session.New(myLog, nil, nil, -1)
lc := lifecycle.New()
myDeploymentManager := &deploymentManager{
bus: bus,
session: mySession,
client: client,
lease: lid,
mgroup: group,
log: myLog,
lc: lc,
}
monitor := newDeploymentMonitor(myDeploymentManager)
require.NotNil(t, monitor)
monitor.lc.Shutdown(nil)
}
func TestMonitorSendsClusterDeploymentPending(t *testing.T) {
const serviceName = "test"
myLog := testutil.Logger(t)
bus := pubsub.NewBus()
lid := testutil.LeaseID(t)
group := &manifest.Group{}
group.Services = make([]manifest.Service, 1)
group.Services[0].Name = serviceName
group.Services[0].Expose = make([]manifest.ServiceExpose, 1)
group.Services[0].Expose[0].ExternalPort = 2000
group.Services[0].Expose[0].Proto = manifest.TCP
group.Services[0].Expose[0].Port = 40000
client := &mocks.Client{}
statusResult := make(map[string]*ctypes.ServiceStatus)
client.On("LeaseStatus", mock.Anything, lid).Return(statusResult, nil)
mySession := session.New(myLog, nil, nil, -1)
sub, err := bus.Subscribe()
require.NoError(t, err)
lc := lifecycle.New()
myDeploymentManager := &deploymentManager{
bus: bus,
session: mySession,
client: client,
lease: lid,
mgroup: group,
log: myLog,
lc: lc,
}
monitor := newDeploymentMonitor(myDeploymentManager)
require.NotNil(t, monitor)
ev := <-sub.Events()
result := ev.(event.ClusterDeployment)
require.Equal(t, lid, result.LeaseID)
require.Equal(t, event.ClusterDeploymentPending, result.Status)
monitor.lc.Shutdown(nil)
}
func TestMonitorSendsClusterDeploymentDeployed(t *testing.T) {
const serviceName = "test"
myLog := testutil.Logger(t)
bus := pubsub.NewBus()
lid := testutil.LeaseID(t)
group := &manifest.Group{}
group.Services = make([]manifest.Service, 1)
group.Services[0].Name = serviceName
group.Services[0].Expose = make([]manifest.ServiceExpose, 1)
group.Services[0].Expose[0].ExternalPort = 2000
group.Services[0].Expose[0].Proto = manifest.TCP
group.Services[0].Expose[0].Port = 40000
group.Services[0].Count = 3
client := &mocks.Client{}
statusResult := make(map[string]*ctypes.ServiceStatus)
statusResult[serviceName] = &ctypes.ServiceStatus{
Name: serviceName,
Available: 3,
Total: 3,
URIs: nil,
ObservedGeneration: 0,
Replicas: 0,
UpdatedReplicas: 0,
ReadyReplicas: 0,
AvailableReplicas: 0,
}
client.On("LeaseStatus", mock.Anything, lid).Return(statusResult, nil)
mySession := session.New(myLog, nil, nil, -1)
sub, err := bus.Subscribe()
require.NoError(t, err)
lc := lifecycle.New()
myDeploymentManager := &deploymentManager{
bus: bus,
session: mySession,
client: client,
lease: lid,
mgroup: group,
log: myLog,
lc: lc,
}
monitor := newDeploymentMonitor(myDeploymentManager)
require.NotNil(t, monitor)
ev := <-sub.Events()
result := ev.(event.ClusterDeployment)
require.Equal(t, lid, result.LeaseID)
require.Equal(t, event.ClusterDeploymentDeployed, result.Status)
monitor.lc.Shutdown(nil)
}