返回 DeepSeek-Reasonix
transport_stdio_close_windows_test.go
根目录 / internal / plugin / transport_stdio_close_windows_test.go
1 //go:build windows
2
3 package plugin
4
5 import (
6 "context"
7 "errors"
8 "testing"
9 "unsafe"
10
11 "golang.org/x/sys/windows"
12 )
13
14 func TestStdioGracefulExitReleasesWindowsJobBeforeInstanceSlot(t *testing.T) {
15 transport, err := newStdioTransport(context.Background(), Spec{
16 Name: "graceful-exit", Command: "cmd.exe", Args: []string{"/c", "exit", "0"},
17 })
18 if err != nil {
19 t.Fatal(err)
20 }
21 t.Cleanup(transport.close)
22 if transport.job == 0 {
23 t.Fatal("stdio process has no Windows job")
24 }
25 transport.wait()
26 jobInfo := func() error {
27 var info windows.JOBOBJECT_EXTENDED_LIMIT_INFORMATION
28 return windows.QueryInformationJobObject(windows.Handle(transport.job), windows.JobObjectExtendedLimitInformation,
29 uintptr(unsafe.Pointer(&info)), uint32(unsafe.Sizeof(info)), nil)
30 }
31 if err := jobInfo(); err != nil {
32 t.Fatalf("job before close: %v", err)
33 }
34 released := false
35 transport.releaseSlot = func() {
36 released = true
37 if err := jobInfo(); !errors.Is(err, windows.ERROR_INVALID_HANDLE) {
38 t.Errorf("instance slot released before Windows job handle: %v", err)
39 }
40 }
41 transport.close()
42 if !released {
43 t.Fatal("instance slot was not released")
44 }
45 }
46
46 lines GO