test: fix test case issue

This commit is contained in:
Marvin Zhang
2024-11-22 13:59:12 +08:00
parent 9f1d7dd385
commit a6e845a9bf
2 changed files with 10 additions and 5 deletions

View File

@@ -809,7 +809,8 @@ func (r *Runner) startIPCReader() {
line := scanner.Text()
var ipcMsg IPCMessage
if err := json.Unmarshal([]byte(line), &ipcMsg); err == nil && ipcMsg.IPC {
err := json.Unmarshal([]byte(line), &ipcMsg)
if err == nil && ipcMsg.IPC {
// Only handle as IPC if it's valid JSON AND has IPC flag set
if r.ipcHandler != nil {
r.ipcHandler(ipcMsg)

View File

@@ -270,8 +270,10 @@ func TestRunner_HandleIPCData(t *testing.T) {
select {
case recordCount := <-processed:
assert.Equal(t, tc.expected, recordCount)
case <-time.After(3 * time.Second):
t.Fatal("timeout waiting for IPC message to be processed")
case <-time.After(1 * time.Second):
if tc.expected > 0 {
t.Fatal("timeout waiting for IPC message to be processed")
}
}
})
}
@@ -330,8 +332,10 @@ func TestRunner_HandleIPCInvalidData(t *testing.T) {
// Mock the gRPC connection
runner.conn = &mockConnectClient{
sendFunc: func(req *grpc.TaskServiceConnectRequest) error {
// This should not be called for invalid data
processed <- struct{}{}
if req.Code == grpc.TaskServiceConnectCode_INSERT_DATA {
// This should not be called for invalid data
processed <- struct{}{}
}
return nil
},
}