From eee10ea08c0a838dd73d1bd8627c06c63d23d6c4 Mon Sep 17 00:00:00 2001 From: Marvin Zhang Date: Fri, 22 Nov 2024 12:48:16 +0800 Subject: [PATCH] test: fix test cases --- core/task/handler/runner_test.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/core/task/handler/runner_test.go b/core/task/handler/runner_test.go index b16df446..1323526d 100644 --- a/core/task/handler/runner_test.go +++ b/core/task/handler/runner_test.go @@ -4,9 +4,8 @@ import ( "encoding/json" "fmt" "github.com/apex/log" + "github.com/crawlab-team/crawlab/core/utils" "io" - "os" - "syscall" "testing" "time" @@ -127,15 +126,14 @@ func TestRunner_Cancel(t *testing.T) { runner.pid = runner.cmd.Process.Pid // Test cancel - err = runner.Cancel(true) - assert.NoError(t, err) + go func() { + err = runner.Cancel(true) + assert.NoError(t, err) + }() // Verify process was killed // Wait a short time for the process to be killed time.Sleep(100 * time.Millisecond) - - process, err := os.FindProcess(runner.pid) - require.NoError(t, err) - err = process.Signal(syscall.Signal(0)) - assert.Error(t, err) // Process should not exist + exists := utils.ProcessIdExists(runner.pid) + assert.False(t, exists) }