@@ -46,6 +46,17 @@ func createFakeLoaderConfiguration() *config.LoaderConfiguration {
4646 GRPCFunctionTimeoutSeconds : 15 ,
4747 }
4848}
49+ func createFakeVSwarmLoaderConfiguration () * config.LoaderConfiguration {
50+ return & config.LoaderConfiguration {
51+ Platform : "Knative" ,
52+ InvokeProtocol : "grpc" ,
53+ OutputPathPrefix : "test" ,
54+ EnableZipkinTracing : true ,
55+ GRPCConnectionTimeoutSeconds : 5 ,
56+ GRPCFunctionTimeoutSeconds : 15 ,
57+ VSwarm : true ,
58+ }
59+ }
4960
5061var testFunction = common.Function {
5162 Name : "test-function" ,
@@ -68,9 +79,26 @@ func TestGRPCClientWithServerUnreachable(t *testing.T) {
6879 record .StartTime == 0 ||
6980 record .ResponseTime == 0 ||
7081 success != false ||
71- record .ConnectionTimeout != true {
82+ record .FunctionTimeout != true {
83+
84+ t .Error ("Error while testing an unreachable server for trace function." )
85+ }
86+
87+ }
88+ func TestVSwarmClientUnreachable (t * testing.T ) {
89+ cfgSwarm := createFakeVSwarmLoaderConfiguration ()
90+
91+ vSwarmInvoker := CreateInvoker (cfgSwarm , nil , nil )
92+ success , record := vSwarmInvoker .Invoke (& testFunction , & testRuntimeSpecs )
93+
94+ if record .Instance != "" ||
95+ record .RequestedDuration != uint32 (testRuntimeSpecs .Runtime * 1000 ) ||
96+ record .StartTime == 0 ||
97+ record .ResponseTime == 0 ||
98+ success != false ||
99+ record .FunctionTimeout != true {
72100
73- t .Error ("Error while testing an unreachable server." )
101+ t .Error ("Error while testing an unreachable server for vSwarm function ." )
74102 }
75103}
76104
@@ -98,7 +126,32 @@ func TestGRPCClientWithServerReachable(t *testing.T) {
98126 record .ActualDuration == 0 ||
99127 record .ActualMemoryUsage == 0 {
100128
101- t .Error ("Failed gRPC invocations." )
129+ t .Error ("Failed gRPC invocations for trace function." )
130+ }
131+
132+ }
133+ func TestVSwarmClientWithServerReachable (t * testing.T ) {
134+ address , port := "localhost" , 18081
135+ testFunction .Endpoint = fmt .Sprintf ("%s:%d" , address , port )
136+
137+ go standard .StartVSwarmGRPCServer (address , port )
138+ time .Sleep (2 * time .Second )
139+
140+ cfgSwarm := createFakeVSwarmLoaderConfiguration ()
141+ vSwarmInvoker := CreateInvoker (cfgSwarm , nil , nil )
142+
143+ start := time .Now ()
144+ success , record := vSwarmInvoker .Invoke (& testFunction , & testRuntimeSpecs )
145+ logrus .Info ("Elapsed: " , time .Since (start ).Milliseconds (), " ms" )
146+
147+ if ! success ||
148+ record .MemoryAllocationTimeout != false ||
149+ record .ConnectionTimeout != false ||
150+ record .FunctionTimeout != false ||
151+ record .ResponseTime == 0 ||
152+ record .ActualDuration == 0 {
153+
154+ t .Error ("Failed gRPC invocations for vSwarm function." )
102155 }
103156}
104157
@@ -109,7 +162,7 @@ func TestGRPCClientWithServerBatchWorkload(t *testing.T) {
109162 t .Error (err )
110163 }
111164
112- address , port := "localhost" , 18081
165+ address , port := "localhost" , 18082
113166 testFunction .Endpoint = fmt .Sprintf ("%s:%d" , address , port )
114167
115168 go standard .StartGRPCServer (address , port , standard .TraceFunction , "" )
@@ -118,6 +171,7 @@ func TestGRPCClientWithServerBatchWorkload(t *testing.T) {
118171 time .Sleep (2 * time .Second )
119172
120173 cfg := createFakeLoaderConfiguration ()
174+
121175 invoker := CreateInvoker (cfg , nil , nil )
122176
123177 for i := 0 ; i < 50 ; i ++ {
@@ -131,7 +185,7 @@ func TestGRPCClientWithServerBatchWorkload(t *testing.T) {
131185 record .ActualDuration == 0 ||
132186 record .ActualMemoryUsage == 0 {
133187
134- t .Error ("Failed gRPC invocations." )
188+ t .Error ("Failed gRPC invocations for trace function ." )
135189 }
136190 }
137191}
0 commit comments