Expected Test Failure Report for ext/mysqli/tests/mysqli_poll_kill.phpt ('int mysqli_poll() and kill')
Script
1:
<?php 2: require_once('connect.inc'); 3: 4: function get_connection() { 5: global $host, $user, $passwd, $db, $port, $socket; 6: 7: if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) 8: printf("[001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); 9: return $link; 10: } 11: 12: // Killing connection - 1 13: 14: $link = get_connection(); 15: if (true !== ($tmp = mysqli_query($link, "SELECT 1 AS 'processed before killed'", MYSQLI_ASYNC | MYSQLI_USE_RESULT))) 16: printf("[002] Expecting boolean/true got %s/%s\n", gettype($tmp), var_export($tmp, true)); 17: 18: // Sleep 0.1s - the asynchronous query should have been processed after the wait period 19: usleep(100000); 20: $thread_id = mysqli_thread_id($link); 21: mysqli_kill(get_connection(), $thread_id); 22: 23: $links = array($link); 24: $errors = array($link); 25: $reject = array($link); 26: 27: // Yes, 1 - the asynchronous query should have been processed 28: if (1 !== ($tmp = (mysqli_poll($links, $errors, $reject, 0, 10000)))) 29: printf("[003] Expecting int/1 got %s/%s\n", gettype($tmp), var_export($tmp, true)); 30: 31: if (!is_array($links) || empty($links)) 32: printf("[004] Expecting non-empty array got %s/%s\n", gettype($links), var_export($links, true)); 33: else 34: foreach ($links as $link) { 35: if (is_object($res = mysqli_reap_async_query($link))) { 36: // Yes, you can fetch a result - the query has been processed 37: var_dump(mysqli_fetch_assoc($res)); 38: mysqli_free_result($res); 39: } else if ($link->errno > 0) { 40: printf("[005] Error: %d\n", $link->errno); 41: } 42: } 43: 44: // No error! 45: if (!is_array($errors) || !empty($errors)) 46: printf("[006] Expecting non-empty array got %s/%s\n", gettype($errors), var_export($errors, true)); 47: 48: if (!is_array($reject) || !empty($reject)) 49: printf("[007] Expecting empty array got %s/%s\n", gettype($reject), var_export($reject, true)); 50: 51: // Lets pass a dead connection 52: $links = array($link); 53: $errors = array($link); 54: $reject = array($link); 55: if (0 !== ($tmp = mysqli_poll($links, $errors, $reject, 1))) 56: printf("[008] There should be no connection ready! Returned %s/%s, expecting int/0.\n", 57: gettype($tmp), var_export($tmp, true)); 58: 59: if (!empty($errors)) 60: printf("[009] There should be no errors but one rejected connection\n"); 61: 62: foreach ($reject as $mysqli) 63: if (mysqli_thread_id($mysqli) != $thread_id) { 64: printf("[010] Rejected thread %d should have rejected thread %d\n", 65: mysqli_thread_id($mysqli), $thread_id); 66: } 67: 68: // Killing connection - 2 69: 70: $link = get_connection(); 71: if (true !== ($tmp = mysqli_query($link, "SELECT 1", MYSQLI_ASYNC | MYSQLI_USE_RESULT))) 72: printf("[011] Expecting boolean/true got %s/%s\n", gettype($tmp), var_export($tmp, true)); 73: 74: usleep(100000); 75: $thread_id = mysqli_thread_id($link); 76: mysqli_kill(get_connection(), $thread_id); 77: 78: // Yes, 1 - fetch OK packet of kill! 79: $processed = 0; 80: $begin = microtime(true); 81: do { 82: $links = array($link, $link); 83: $errors = array($link, $link); 84: $reject = array($link, $link); 85: $ready = mysqli_poll($links, $errors, $reject, 1); 86: 87: if (!empty($errors)) { 88: foreach ($errors as $mysqli) { 89: printf("[012] Error on thread %d: %s/%s\n", 90: mysqli_thread_id($mysqli), 91: mysqli_errno($mysqli), 92: mysqli_error($mysqli)); 93: } 94: break; 95: } 96: 97: if (FALSE === $ready) { 98: printf("[013] MySQLi indicates some error\n"); 99: break; 100: } 101: 102: if (!empty($reject)) { 103: foreach ($reject as $mysqli) { 104: printf("[014] Rejecting thread %d: %s/%s\n", 105: mysqli_thread_id($mysqli), 106: mysqli_errno($mysqli), 107: mysqli_error($mysqli)); 108: } 109: $processed += count($reject); 110: } 111: 112: foreach ($links as $mysqli) { 113: if (is_object($res = mysqli_reap_async_query($mysqli))) { 114: printf("Fetching from thread %d...\n", mysqli_thread_id($mysqli)); 115: var_dump(mysqli_fetch_assoc($res)); 116: } else if (mysqli_errno($mysqli) > 0) { 117: printf("[015] %d/%s\n", mysqli_errno($mysqli), mysqli_error($mysqli)); 118: } 119: $processed++; 120: } 121: 122: if ((microtime(true) - $begin) > 5) { 123: printf("[016] Pulling the emergency break after 5s, something is wrong...\n"); 124: break; 125: } 126: 127: } while ($processed < 2); 128: 129: 130: // Killing connection - 3 131: 132: $link = get_connection(); 133: $thread_id = mysqli_thread_id($link); 134: mysqli_kill(get_connection(), $thread_id); 135: // Sleep 0.1s to ensure the KILL gets recognized 136: usleep(100000); 137: if (false !== ($tmp = mysqli_query($link, "SELECT 1 AS 'processed before killed'", MYSQLI_ASYNC | MYSQLI_USE_RESULT))) 138: printf("[017] Expecting boolean/false got %s/%s\n", gettype($tmp), var_export($tmp, true)); 139: 140: $links = array($link); 141: $errors = array($link); 142: $reject = array($link); 143: 144: if (0 !== ($tmp = (mysqli_poll($links, $errors, $reject, 0, 10000)))) 145: printf("[018] Expecting int/0 got %s/%s\n", gettype($tmp), var_export($tmp, true)); 146: 147: if (!is_array($links) || empty($links)) 148: printf("[019] Expecting non-empty array got %s/%s\n", gettype($links), var_export($links, true)); 149: else 150: foreach ($links as $link) { 151: if (is_object($res = mysqli_reap_async_query($link))) { 152: // No, you cannot fetch the result 153: var_dump(mysqli_fetch_assoc($res)); 154: mysqli_free_result($res); 155: } else if ($link->errno > 0) { 156: // But you are supposed to handle the error the way its shown here! 157: printf("[020] Error: %d/%s\n", $link->errno, $link->error); 158: } 159: } 160: 161: // None of these will indicate an error, check errno on the list of returned connections! 162: if (!is_array($errors) || !empty($errors)) 163: printf("[021] Expecting non-empty array got %s/%s\n", gettype($errors), var_export($errors, true)); 164: 165: if (!is_array($reject) || !empty($reject)) 166: printf("[021] Expecting empty array got %s/%s\n", gettype($reject), var_export($reject, true)); 167: 168: 169: mysqli_close($link); 170: print "done!"; 171: ?> 172:
Expected
array(1) {
[%u|b%"processed before killed"]=>
%unicode|string%(1) "1"
}
Fetching from thread %d...
array(1) {
[1]=>
%unicode|string%(1) "1"
}
Warning: mysqli_reap_async_query(): Premature end of data (mysqlnd_wireprotocol.c:%d) in %s on line %d
Warning: mysqli_reap_async_query(): RSET_HEADER %s
Warning: mysqli_reap_async_query(): Error reading result set's header in %s on line %d
Warning: Error while sending QUERY packet. %s
Warning: mysqli_reap_async_query(): %s
Warning: mysqli_reap_async_query(): Error reading result set's header in %s on line %d
[018] Error: %d/%s
done!
Output
array(1) {
["processed before killed"]=>
string(1) "1"
}
Fetching from thread 185135...
array(1) {
[1]=>
string(1) "1"
}
Warning: mysqli_reap_async_query(): Premature end of data (mysqlnd_wireprotocol.c:1079) in /var/php_gcov/PHP_5_6/ext/mysqli/tests/mysqli_poll_kill.php on line 113
Warning: mysqli_reap_async_query(): RSET_HEADER packet 4 bytes shorter than expected in /var/php_gcov/PHP_5_6/ext/mysqli/tests/mysqli_poll_kill.php on line 113
Warning: mysqli_reap_async_query(): Error reading result set's header in /var/php_gcov/PHP_5_6/ext/mysqli/tests/mysqli_poll_kill.php on line 113
[017] Expecting boolean/false got boolean/true
[018] Expecting int/0 got integer/1
Warning: mysqli_reap_async_query(): MySQL server has gone away in /var/php_gcov/PHP_5_6/ext/mysqli/tests/mysqli_poll_kill.php on line 151
Warning: mysqli_reap_async_query(): Error reading result set's header in /var/php_gcov/PHP_5_6/ext/mysqli/tests/mysqli_poll_kill.php on line 151
[020] Error: 2006/MySQL server has gone away
done!
Diff
016+ [017] Expecting boolean/false got boolean/true
017+ [018] Expecting int/0 got integer/1
017- Warning: Error while sending QUERY packet. %s
018-
022+ [020] Error: 2006/MySQL server has gone away
022- [018] Error: %d/%s
Generated at Wed, 25 Apr 2018 20:18:17 +0000 (19 hours ago)
|