1-- need to use a global counter to avoid losing it on reload. 2-- not really sure this'll work forever, but even if it doesn't I should allow 3-- some method of persisting data across reloads. 4if reload_count == nil then 5 reload_count = 0 6end 7 8function mcp_config_pools(old) 9 mcp.backend_read_timeout(4) 10 mcp.backend_connect_timeout(5) 11 reload_count = reload_count + 1 12 13 if reload_count == 1 then 14 -- set a low request limit. 15 mcp.active_req_limit(4) 16 local b1 = mcp.backend('b1', '127.0.0.1', 11711) 17 local b2 = mcp.backend('b2', '127.0.0.1', 11712) 18 local b3 = mcp.backend('b3', '127.0.0.1', 11713) 19 20 -- Direct all traffic at a single backend to simplify the test. 21 local pools = { 22 test = mcp.pool({b1}), 23 hold = mcp.pool({b2, b3}) 24 } 25 return pools 26 elseif reload_count == 2 then 27 -- removing the request limit. 28 mcp.active_req_limit(0) 29 local b1 = mcp.backend('b1', '127.0.0.1', 11711) 30 local b2 = mcp.backend('b2', '127.0.0.1', 11712) 31 local b3 = mcp.backend('b3', '127.0.0.1', 11713) 32 33 -- Direct all traffic at a single backend to simplify the test. 34 local pools = { 35 test = mcp.pool({b1}), 36 hold = mcp.pool({b2, b3}) 37 } 38 return pools 39 elseif reload_count == 3 or reload_count == 4 then 40 -- adding the memory buffer limit (abusrdly low) 41 mcp.buffer_memory_limit(20) 42 if reload_count == 4 then 43 -- raise it a bit but still limited. 44 mcp.buffer_memory_limit(200) 45 end 46 local b1 = mcp.backend('b1', '127.0.0.1', 11711) 47 local b2 = mcp.backend('b2', '127.0.0.1', 11712) 48 local b3 = mcp.backend('b3', '127.0.0.1', 11713) 49 50 -- Direct all traffic at a single backend to simplify the test. 51 local pools = { 52 test = mcp.pool({b1}), 53 hold = mcp.pool({b2, b3}) 54 } 55 return pools 56 elseif reload_count == 5 then 57 -- remove the buffer limit entirely. 58 mcp.buffer_memory_limit(0) 59 local b1 = mcp.backend('b1', '127.0.0.1', 11711) 60 local b2 = mcp.backend('b2', '127.0.0.1', 11712) 61 local b3 = mcp.backend('b3', '127.0.0.1', 11713) 62 63 -- Direct all traffic at a single backend to simplify the test. 64 local pools = { 65 test = mcp.pool({b1}), 66 hold = mcp.pool({b2, b3}) 67 } 68 return pools 69 end 70end 71 72-- At least to start we don't need to test every command, but we should do 73-- some tests against the two broad types of commands (gets vs sets with 74-- payloads) 75function mcp_config_routes(zones) 76 local fg = mcp.funcgen_new() 77 local h = fg:new_handle(zones["test"]) 78 fg:ready({ 79 f = function(rctx) 80 return function(r) 81 return rctx:enqueue_and_wait(r, h) 82 end 83 end 84 }) 85 mcp.attach(mcp.CMD_MG, fg) 86 mcp.attach(mcp.CMD_MS, fg) 87 mcp.attach(mcp.CMD_GET, fg) 88 mcp.attach(mcp.CMD_SET, fg) 89end 90