- disallow detaching requests while executing progress callbacks
[m6w6/ext-http] / tests / HttpRequestPool_006.phpt
index 9d788ad2ada97592ac8a323eb2834c969b8ac8b9..1b5cb9f14269c6c0e2017a79b9de0bb720be483a 100644 (file)
@@ -10,23 +10,41 @@ checkurl("de.php.net");
 --FILE--
 <?php
 echo "-TEST\n";
-class r1 extends HttpRequest {
+class r extends HttpRequest {
        function onProgress() {
-               $GLOBALS['p']->detach($this);
+               static $i = array();
+               if (empty($i[$this->getUrl()])) {
+                       $i[$this->getUrl()] = true;
+                       try {
+                               $GLOBALS['p']->detach($this);
+                       } catch (Exception $ex) {
+                               echo $ex, "\n";
+                       }
+               }
        }
-}
-class r2 extends HttpRequest {
        function onFinish() {
                $GLOBALS['p']->detach($this);
        }
 }
-$p = new HttpRequestPool(new r1("at.php.net"), new r2("de.php.net"));
+$p = new HttpRequestPool(new r("http://at.php.net"), new r("http://de.php.net"));
 $p->send();
 var_dump($p->getAttachedRequests());
 echo "Done\n";
 ?>
 --EXPECTF--
 %sTEST
+exception 'HttpRequestPoolException' with message 'HttpRequest object(#%d) cannot be detached from the HttpRequestPool while executing the progress callback' in %sHttpRequestPool_006.php:%d
+Stack trace:
+#0 %sHttpRequestPool_006.php(%d): HttpRequestPool->detach(Object(r))
+#1 [internal function]: r->onProgress(Array)
+#2 %sHttpRequestPool_006.php(%d): HttpRequestPool->send()
+#3 {main}
+exception 'HttpRequestPoolException' with message 'HttpRequest object(#%d) cannot be detached from the HttpRequestPool while executing the progress callback' in %sHttpRequestPool_006.php:%d
+Stack trace:
+#0 %sHttpRequestPool_006.php(%d): HttpRequestPool->detach(Object(r))
+#1 [internal function]: r->onProgress(Array)
+#2 %sHttpRequestPool_006.php(%d): HttpRequestPool->send()
+#3 {main}
 array(0) {
 }
 Done