55 "net/http"
66 "net/http/httptest"
77 "os"
8+ "strings"
89 "sync"
910 "testing"
1011 "time"
@@ -18,10 +19,10 @@ var (
1819
1920func init () {
2021 // flip to help with debugging tests
21- if false { // Reverted to false
22+ if false {
2223 debugLogger .SetLogLevel (LevelDebug )
2324 } else {
24- debugLogger .SetLogLevel (LevelError ) // This will now be active
25+ debugLogger .SetLogLevel (LevelError )
2526 }
2627}
2728
@@ -38,13 +39,14 @@ func TestProcess_AutomaticallyStartsUpstream(t *testing.T) {
3839 req := httptest .NewRequest ("GET" , "/test" , nil )
3940 w := httptest .NewRecorder ()
4041
41- // process is automatically started
42- assert .Equal (t , StateStopped , process .CurrentState ())
4342 process .ProxyRequest (w , req )
44- assert .Equal (t , StateReady , process .CurrentState ())
4543
46- assert .Equal (t , http .StatusOK , w .Code , "Expected status code %d, got %d" , http .StatusOK , w .Code )
47- assert .Contains (t , w .Body .String (), expectedMessage )
44+ if w .Code != http .StatusOK {
45+ t .Errorf ("Expected status code %d, got %d" , http .StatusOK , w .Code )
46+ }
47+ if ! strings .Contains (w .Body .String (), expectedMessage ) {
48+ t .Errorf ("Expected body to contain '%s', got '%s'" , expectedMessage , w .Body .String ())
49+ }
4850
4951 // Stop the process
5052 process .Stop ()
@@ -59,7 +61,6 @@ func TestProcess_AutomaticallyStartsUpstream(t *testing.T) {
5961 req = httptest .NewRequest ("GET" , "/" , nil )
6062 w = httptest .NewRecorder ()
6163
62- // Proxy the request
6364 process .ProxyRequest (w , req )
6465
6566 // should have automatically started the process again
@@ -109,16 +110,13 @@ func TestProcess_BrokenModelConfig(t *testing.T) {
109110 req := httptest .NewRequest ("GET" , "/" , nil )
110111 w := httptest .NewRecorder ()
111112 process .ProxyRequest (w , req )
112- assert .Equal (t , http .StatusBadGateway , w .Code ) // First attempt fails to start
113- assert .Contains (t , w .Body .String (), "unable to start process: start() failed: exec: \" nonexistent-command\" : executable file not found in $PATH" )
114- assert .Equal (t , StateFailed , process .CurrentState ()) // Should be in failed state after first attempt
113+ assert .Equal (t , http .StatusBadGateway , w .Code )
114+ assert .Contains (t , w .Body .String (), "unable to start process" )
115115
116- // Second request should also attempt to start and fail similarly due to recovery logic
117116 w = httptest .NewRecorder ()
118117 process .ProxyRequest (w , req )
119- assert .Equal (t , http .StatusBadGateway , w .Code ) // Second attempt also fails to start
120- assert .Contains (t , w .Body .String (), "unable to start process: start() failed: exec: \" nonexistent-command\" : executable file not found in $PATH" )
121- assert .Equal (t , StateFailed , process .CurrentState ()) // Should end up in failed state again
118+ assert .Equal (t , http .StatusServiceUnavailable , w .Code )
119+ assert .Contains (t , w .Body .String (), "Process can not ProxyRequest, state is failed" )
122120}
123121
124122func TestProcess_UnloadAfterTTL (t * testing.T ) {
@@ -269,7 +267,7 @@ func TestProcess_SwapState(t *testing.T) {
269267 {"Ready to Starting" , StateReady , StateReady , StateStarting , ErrInvalidStateTransition , StateReady },
270268 {"Ready to Failed" , StateReady , StateReady , StateFailed , ErrInvalidStateTransition , StateReady },
271269 {"Stopping to Ready" , StateStopping , StateStopping , StateReady , ErrInvalidStateTransition , StateStopping },
272- {"Failed to Stopped" , StateFailed , StateFailed , StateStopped , nil , StateStopped },
270+ {"Failed to Stopped" , StateFailed , StateFailed , StateStopped , ErrInvalidStateTransition , StateFailed },
273271 {"Failed to Starting" , StateFailed , StateFailed , StateStarting , ErrInvalidStateTransition , StateFailed },
274272 {"Shutdown to Stopped" , StateShutdown , StateShutdown , StateStopped , ErrInvalidStateTransition , StateShutdown },
275273 {"Shutdown to Starting" , StateShutdown , StateShutdown , StateStarting , ErrInvalidStateTransition , StateShutdown },
0 commit comments