Skip to content

Commit e8f305f

Browse files
committed
test(commands): keep pkg/commands building on Windows
The test raises SIGTERM at its own process to prove signalContext cancels on it, and syscall.Kill does not exist on Windows. One undefined symbol in a test file fails the whole package's type check, so nothing in pkg/commands built there: both the Windows test job and the Windows lint job went down on it while Linux stayed green. Move it behind a !windows build tag. signalContext itself is unaffected, since syscall.SIGTERM is defined on Windows as well; only delivering a signal this way is not. Signed-off-by: Aleksei Sviridkin <[email protected]> Assisted-by: LLM
1 parent e0ac881 commit e8f305f

2 files changed

Lines changed: 50 additions & 25 deletions

File tree

‎pkg/commands/client_wrappers_test.go‎

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@ package commands
1616

1717
import (
1818
"context"
19-
"os"
2019
"path/filepath"
2120
"slices"
22-
"syscall"
2321
"testing"
24-
"time"
2522

2623
"google.golang.org/grpc/metadata"
2724

@@ -136,25 +133,3 @@ func TestWithClientNoNodes_UsesContextEndpointsWithoutNodes(t *testing.T) {
136133
t.Error("WithClientNoNodes attached node metadata; callers add nodes themselves")
137134
}
138135
}
139-
140-
// TestSignalContext_CancelsOnSignal pins the first half of the interrupt
141-
// contract: a signal cancels the context the client call runs under. The second
142-
// half (a second Ctrl+C killing the process) follows from unregistering the
143-
// handler, which Go's default disposition then handles.
144-
//
145-
// The raise is process-scope, so this test must not run in parallel and the
146-
// package must not gain a second test that installs its own SIGTERM handler.
147-
func TestSignalContext_CancelsOnSignal(t *testing.T) {
148-
ctx, stop := signalContext()
149-
defer stop()
150-
151-
if err := syscall.Kill(os.Getpid(), syscall.SIGTERM); err != nil {
152-
t.Fatalf("raise SIGTERM: %v", err)
153-
}
154-
155-
select {
156-
case <-ctx.Done():
157-
case <-time.After(5 * time.Second):
158-
t.Fatal("context was not cancelled by SIGTERM")
159-
}
160-
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright Cozystack Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
//go:build !windows
16+
17+
// Raising a signal at the running process needs syscall.Kill, which Windows
18+
// does not have. signalContext itself builds everywhere: syscall.SIGTERM is
19+
// defined on Windows too, it just cannot be delivered this way.
20+
21+
package commands
22+
23+
import (
24+
"os"
25+
"syscall"
26+
"testing"
27+
"time"
28+
)
29+
30+
// TestSignalContext_CancelsOnSignal pins the first half of the interrupt
31+
// contract: a signal cancels the context the client call runs under. The second
32+
// half (a second Ctrl+C killing the process) follows from unregistering the
33+
// handler, which Go's default disposition then handles.
34+
//
35+
// The raise is process-scope, so this test must not run in parallel and the
36+
// package must not gain a second test that installs its own SIGTERM handler.
37+
func TestSignalContext_CancelsOnSignal(t *testing.T) {
38+
ctx, stop := signalContext()
39+
defer stop()
40+
41+
if err := syscall.Kill(os.Getpid(), syscall.SIGTERM); err != nil {
42+
t.Fatalf("raise SIGTERM: %v", err)
43+
}
44+
45+
select {
46+
case <-ctx.Done():
47+
case <-time.After(5 * time.Second):
48+
t.Fatal("context was not cancelled by SIGTERM")
49+
}
50+
}

0 commit comments

Comments
 (0)