55 "fmt"
66 "net/http"
77 "os"
8- "syscall"
98 "testing"
109 "time"
1110
@@ -54,12 +53,11 @@ func TestGetToolsets(t *testing.T) {
5453 },
5554 }
5655
57- toolsets := getToolsets (cfg )
58-
59- require .NotNil (t , toolsets )
60- assert .Len (t , toolsets , 2 , "Should have 2 toolsets" )
61- assert .Equal (t , "config_manager" , toolsets [0 ].GetName ())
62- assert .Equal (t , "vulnerability" , toolsets [1 ].GetName ())
56+ allToolsets := getToolsets (cfg )
57+ require .NotNil (t , allToolsets )
58+ assert .Len (t , allToolsets , 2 , "Should have 2 toolsets" )
59+ assert .Equal (t , "config_manager" , allToolsets [0 ].GetName ())
60+ assert .Equal (t , "vulnerability" , allToolsets [1 ].GetName ())
6361}
6462
6563func TestGracefulShutdown (t * testing.T ) {
@@ -74,11 +72,8 @@ func TestGracefulShutdown(t *testing.T) {
7472 // Use a different port to avoid conflicts
7573 cfg .Server .Port = 9999
7674
77- // Create registry and server
7875 registry := toolsets .NewRegistry (cfg , getToolsets (cfg ))
7976 srv := server .NewServer (cfg , registry )
80-
81- // Set up context with cancellation
8277 ctx , cancel := context .WithCancel (context .Background ())
8378
8479 // Start server in goroutine
@@ -102,7 +97,7 @@ func TestGracefulShutdown(t *testing.T) {
10297 // Simulate shutdown signal by canceling context
10398 cancel ()
10499
105- // Wait for server to shut down with timeout
100+ // Wait for server to shut down
106101 select {
107102 case err := <- errChan :
108103 // Server should shut down cleanly (either nil or context.Canceled)
@@ -113,64 +108,3 @@ func TestGracefulShutdown(t *testing.T) {
113108 t .Fatal ("Server did not shut down within timeout period" )
114109 }
115110}
116-
117- func TestGracefulShutdown_WithSignal (t * testing.T ) {
118- // Set up minimal valid config
119- assert .NoError (t , os .Setenv ("STACKROX_MCP__TOOLS__VULNERABILITY__ENABLED" , "true" ))
120- defer func () { assert .NoError (t , os .Unsetenv ("STACKROX_MCP__TOOLS__VULNERABILITY__ENABLED" )) }()
121-
122- cfg , err := config .LoadConfig ("" )
123- require .NoError (t , err )
124- require .NotNil (t , cfg )
125-
126- // Use a different port to avoid conflicts
127- cfg .Server .Port = 10000
128-
129- // Create registry and server
130- registry := toolsets .NewRegistry (cfg , getToolsets (cfg ))
131- srv := server .NewServer (cfg , registry )
132-
133- // Set up context with cancellation and signal handling (like in main)
134- ctx , cancel := context .WithCancel (context .Background ())
135- defer cancel ()
136-
137- sigChan := make (chan os.Signal , 1 )
138- // Note: We use a buffered channel and manually send to avoid OS signal complications in tests
139-
140- go func () {
141- <- sigChan
142- cancel ()
143- }()
144-
145- // Start server in goroutine
146- errChan := make (chan error , 1 )
147- go func () {
148- errChan <- srv .Start (ctx )
149- }()
150-
151- // Wait for server to be ready by polling
152- serverURL := fmt .Sprintf ("http://%s:%d" , cfg .Server .Address , cfg .Server .Port )
153- err = waitForServerReady (serverURL , 3 * time .Second )
154- require .NoError (t , err , "Server should start within timeout" )
155-
156- // Establish actual HTTP connection to verify server is responding
157- resp , err := http .Get (serverURL )
158- if err == nil {
159- _ = resp .Body .Close ()
160- }
161- assert .NoError (t , err , "Should be able to establish HTTP connection to server" )
162-
163- // Simulate signal by sending to channel
164- sigChan <- syscall .SIGTERM
165-
166- // Wait for server to shut down with timeout
167- select {
168- case err := <- errChan :
169- // Server should shut down cleanly
170- if err != nil && err != context .Canceled {
171- t .Errorf ("Server returned unexpected error: %v" , err )
172- }
173- case <- time .After (5 * time .Second ):
174- t .Fatal ("Server did not shut down within timeout period after signal" )
175- }
176- }
0 commit comments