|
| 1 | +-- MySQL Proxy script for simulating a slow server |
| 2 | +-- |
| 3 | +-- Written by Patrick Allaert <[email protected]> |
| 4 | +-- Copyright © 2009-2011 Libereco Technologies |
| 5 | +-- |
| 6 | +-- This program is free software: you can redistribute it and/or modify |
| 7 | +-- it under the terms of the GNU General Public License as published by |
| 8 | +-- the Free Software Foundation, either version 3 of the License, or |
| 9 | +-- (at your option) any later version. |
| 10 | +-- |
| 11 | +-- This program is distributed in the hope that it will be useful, |
| 12 | +-- but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +-- GNU General Public License for more details. |
| 15 | +-- |
| 16 | +-- You should have received a copy of the GNU General Public License |
| 17 | +-- along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | +-- Requirements: the sleep command accepting a float value as parameter |
| 20 | +-- See http://lua-users.org/wiki/SleepFunction for alternatives |
| 21 | + |
| 22 | +-- Factor of slowness, how many times slower every requests should be |
| 23 | +factor = 2 |
| 24 | + |
| 25 | +-- In addition to a factor of slowness you can set a fixed amount of additional |
| 26 | +-- time every request should take (in seconds). |
| 27 | +additionalTime = 0.1 |
| 28 | + |
| 29 | +function read_query( packet ) |
| 30 | + if packet:byte() ~= proxy.COM_QUERY then |
| 31 | + return |
| 32 | + end |
| 33 | + proxy.queries:append(1, string.char(proxy.COM_QUERY) .. packet:sub(2)) |
| 34 | + |
| 35 | + return proxy.PROXY_SEND_QUERY |
| 36 | +end |
| 37 | + |
| 38 | +function read_query_result (inj) |
| 39 | + os.execute( "sleep " .. ( ( (factor - 1) * inj.response_time / 1e6 ) + additionalTime ) ) |
| 40 | +end |
0 commit comments