Skip to content

Commit 0e15afb

Browse files
committed
Fix test
1 parent ca3dd5f commit 0e15afb

File tree

3 files changed

+41
-35
lines changed

3 files changed

+41
-35
lines changed

internal/command/command_plugin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (cp *CommandPlugin) Init(ctx context.Context, messagePipe bus.MessagePipeIn
5757

5858
cp.messagePipe = messagePipe
5959
cp.commandService = NewCommandService(ctx, cp.conn.CommandServiceClient(), cp.config, cp.subscribeChannel)
60-
60+
6161
go cp.monitorSubscribeChannel(ctx)
6262

6363
return nil

internal/command/command_service_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ func TestCommandService_receiveCallback_configApplyRequest(t *testing.T) {
115115
)
116116

117117
nginxInstance := protos.GetNginxOssInstance([]string{})
118+
commandService.instancesMutex.Lock()
118119
commandService.instances = append(commandService.instances, nginxInstance)
120+
commandService.instancesMutex.Unlock()
119121

120122
defer commandService.CancelSubscription(ctx)
121123

@@ -412,7 +414,9 @@ func TestCommandService_isValidRequest(t *testing.T) {
412414

413415
nginxInstance := protos.GetNginxOssInstance([]string{})
414416

417+
commandService.instancesMutex.Lock()
415418
commandService.instances = append(commandService.instances, nginxInstance)
419+
commandService.instancesMutex.Unlock()
416420

417421
testCases := []struct {
418422
req *mpi.ManagementPlaneRequest

test/integration/grpc_management_plane_api_test.go

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -200,40 +200,42 @@ func TestGrpc_StartUp(t *testing.T) {
200200
verifyUpdateDataPlaneHealth(t)
201201
}
202202

203-
//func TestGrpc_ConfigUpload(t *testing.T) {
204-
// teardownTest := setupConnectionTest(t, true, false)
205-
// defer teardownTest(t)
206-
//
207-
// nginxInstanceID := verifyConnection(t, 2)
208-
// assert.False(t, t.Failed())
209-
//
210-
// request := fmt.Sprintf(`{
211-
// "message_meta": {
212-
// "message_id": "5d0fa83e-351c-4009-90cd-1f2acce2d184",
213-
// "correlation_id": "79794c1c-8e91-47c1-a92c-b9a0c3f1a263",
214-
// "timestamp": "2023-01-15T01:30:15.01Z"
215-
// },
216-
// "config_upload_request": {
217-
// "instance_id": "%s"
218-
// }
219-
//}`, nginxInstanceID)
220-
//
221-
// client := resty.New()
222-
// client.SetRetryCount(retryCount).SetRetryWaitTime(retryWaitTime).SetRetryMaxWaitTime(retryMaxWaitTime)
223-
//
224-
// url := fmt.Sprintf("http://%s/api/v1/requests", mockManagementPlaneAPIAddress)
225-
// resp, err := client.R().EnableTrace().SetBody(request).Post(url)
226-
//
227-
// require.NoError(t, err)
228-
// assert.Equal(t, http.StatusOK, resp.StatusCode())
229-
//
230-
// responses := getManagementPlaneResponses(t, 2)
231-
//
232-
// assert.Equal(t, mpi.CommandResponse_COMMAND_STATUS_OK, responses[0].GetCommandResponse().GetStatus())
233-
// assert.Equal(t, "Successfully updated all files", responses[0].GetCommandResponse().GetMessage())
234-
// assert.Equal(t, mpi.CommandResponse_COMMAND_STATUS_OK, responses[1].GetCommandResponse().GetStatus())
235-
// assert.Equal(t, "Successfully updated all files", responses[1].GetCommandResponse().GetMessage())
236-
//}
203+
func TestGrpc_ConfigUpload(t *testing.T) {
204+
teardownTest := setupConnectionTest(t, true, false)
205+
defer teardownTest(t)
206+
207+
nginxInstanceID := verifyConnection(t, 2)
208+
assert.False(t, t.Failed())
209+
210+
request := fmt.Sprintf(`{
211+
"message_meta": {
212+
"message_id": "5d0fa83e-351c-4009-90cd-1f2acce2d184",
213+
"correlation_id": "79794c1c-8e91-47c1-a92c-b9a0c3f1a263",
214+
"timestamp": "2023-01-15T01:30:15.01Z"
215+
},
216+
"config_upload_request": {
217+
"instance_id": "%s"
218+
}
219+
}`, nginxInstanceID)
220+
221+
t.Logf("Sending config upload request: %s", request)
222+
223+
client := resty.New()
224+
client.SetRetryCount(retryCount).SetRetryWaitTime(retryWaitTime).SetRetryMaxWaitTime(retryMaxWaitTime)
225+
226+
url := fmt.Sprintf("http://%s/api/v1/requests", mockManagementPlaneAPIAddress)
227+
resp, err := client.R().EnableTrace().SetBody(request).Post(url)
228+
229+
require.NoError(t, err)
230+
assert.Equal(t, http.StatusOK, resp.StatusCode())
231+
232+
responses := getManagementPlaneResponses(t, 2)
233+
234+
assert.Equal(t, mpi.CommandResponse_COMMAND_STATUS_OK, responses[0].GetCommandResponse().GetStatus())
235+
assert.Equal(t, "Successfully updated all files", responses[0].GetCommandResponse().GetMessage())
236+
assert.Equal(t, mpi.CommandResponse_COMMAND_STATUS_OK, responses[1].GetCommandResponse().GetStatus())
237+
assert.Equal(t, "Successfully updated all files", responses[1].GetCommandResponse().GetMessage())
238+
}
237239

238240
func TestGrpc_ConfigApply(t *testing.T) {
239241
ctx := context.Background()

0 commit comments

Comments
 (0)