MCPcopy Index your code
hub / github.com/php/frankenphp / TestSessionHandlerPreLoopPreserved_worker

Function TestSessionHandlerPreLoopPreserved_worker

frankenphp_test.go:1159–1206  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1157}
1158
1159func TestSessionHandlerPreLoopPreserved_worker(t *testing.T) {
1160 runTest(t, func(_ func(http.ResponseWriter, *http.Request), ts *httptest.Server, i int) {
1161 // Request 1: Check that the pre-loop session handler is preserved
1162 resp1, err := http.Get(ts.URL + "/worker-with-session-handler.php?action=check")
1163 assert.NoError(t, err)
1164 body1, _ := io.ReadAll(resp1.Body)
1165 _ = resp1.Body.Close()
1166
1167 body1Str := string(body1)
1168 t.Logf("Request 1 response: %s", body1Str)
1169 assert.Contains(t, body1Str, "HANDLER_PRESERVED",
1170 "Session handler set before loop should be preserved")
1171 assert.Contains(t, body1Str, "save_handler=user",
1172 "session.save_handler should remain 'user'")
1173
1174 // Request 2: Use the session - should work with pre-loop handler
1175 resp2, err := http.Get(ts.URL + "/worker-with-session-handler.php?action=use_session")
1176 assert.NoError(t, err)
1177 body2, _ := io.ReadAll(resp2.Body)
1178 _ = resp2.Body.Close()
1179
1180 body2Str := string(body2)
1181 t.Logf("Request 2 response: %s", body2Str)
1182 assert.Contains(t, body2Str, "SESSION_OK",
1183 "Session should work with pre-loop handler.\nResponse: %s", body2Str)
1184 assert.NotContains(t, body2Str, "ERROR:",
1185 "No errors expected.\nResponse: %s", body2Str)
1186 assert.NotContains(t, body2Str, "EXCEPTION:",
1187 "No exceptions expected.\nResponse: %s", body2Str)
1188
1189 // Request 3: Check handler is still preserved after using session
1190 resp3, err := http.Get(ts.URL + "/worker-with-session-handler.php?action=check")
1191 assert.NoError(t, err)
1192 body3, _ := io.ReadAll(resp3.Body)
1193 _ = resp3.Body.Close()
1194
1195 body3Str := string(body3)
1196 t.Logf("Request 3 response: %s", body3Str)
1197 assert.Contains(t, body3Str, "HANDLER_PRESERVED",
1198 "Session handler should still be preserved after use")
1199
1200 }, &testOptions{
1201 workerScript: "worker-with-session-handler.php",
1202 nbWorkers: 1,
1203 nbParallelRequests: 1,
1204 realServer: true,
1205 })
1206}
1207
1208func TestSessionNoLeakBetweenRequests_worker(t *testing.T) {
1209 runTest(t, func(_ func(http.ResponseWriter, *http.Request), ts *httptest.Server, i int) {

Callers

nothing calls this directly

Calls 3

runTestFunction · 0.85
GetMethod · 0.80
CloseMethod · 0.80

Tested by

no test coverage detected