55use PHPFastCGI \FastCGIDaemon \DaemonOptions ;
66use PHPFastCGI \FastCGIDaemon \Driver \Userland \Connection \StreamSocketConnectionPool ;
77use PHPFastCGI \FastCGIDaemon \Driver \Userland \ConnectionHandler \ConnectionHandlerFactory ;
8+ use PHPFastCGI \FastCGIDaemon \Driver \Userland \Exception \UserlandDaemonException ;
89use PHPFastCGI \FastCGIDaemon \Driver \Userland \UserlandDaemon ;
910use PHPFastCGI \FastCGIDaemon \Http \RequestInterface ;
1011use PHPFastCGI \Test \FastCGIDaemon \Helper \Client \ConnectionWrapper ;
@@ -89,6 +90,27 @@ public function testException()
8990 $ this ->assertContains ('boo ' , $ context ['logger ' ]->getMessages ()[0 ]['message ' ]);
9091 }
9192
93+ /**
94+ * Tests that the daemon cleanly handles internal exceptions (such as
95+ * protocol and connection exceptions).
96+ */
97+ public function testDaemonException ()
98+ {
99+ $ context = $ this ->createTestingContext ();
100+
101+ $ socket1 = stream_socket_client ($ context ['address ' ]);
102+ $ connectionWrapper1 = new ConnectionWrapper ($ socket1 );
103+ $ connectionWrapper1 ->writeRequest (1 , ['DAEMON_EXCEPTION ' => 'boo ' ], '' );
104+
105+ $ socket2 = stream_socket_client ($ context ['address ' ]);
106+ $ connectionWrapper2 = new ConnectionWrapper ($ socket2 );
107+ $ connectionWrapper2 ->writeRequest (2 , ['SHUTDOWN ' => true ], '' );
108+
109+ $ context ['daemon ' ]->run ();
110+
111+ $ this ->assertContains ('boo ' , $ context ['logger ' ]->getMessages ()[0 ]['message ' ]);
112+ }
113+
92114 /**
93115 * Tests that the daemon shuts down after receiving a SIGINT.
94116 */
@@ -115,6 +137,8 @@ private function createTestingContext($requestLimit = DaemonOptions::NO_LIMIT, $
115137
116138 if (isset ($ params ['EXCEPTION ' ])) {
117139 throw new \Exception ($ params ['EXCEPTION ' ]);
140+ } elseif (isset ($ params ['DAEMON_EXCEPTION ' ])) {
141+ throw new UserlandDaemonException ($ params ['DAEMON_EXCEPTION ' ]);
118142 } elseif (isset ($ params ['SHUTDOWN ' ])) {
119143 posix_kill (posix_getpid (), SIGINT );
120144 }
0 commit comments