1-- get some information about the test being run from an external file 2-- so we can modify ourselves. 3local mode = dofile("/tmp/proxyconfigmode.lua") 4 5function mcp_config_pools(old) 6 mcp.backend_use_iothread(true) 7 mcp.backend_read_timeout(4) 8 mcp.backend_connect_timeout(5) 9 10 if mode == "none" then 11 return {} 12 elseif mode == "start" then 13 local b1 = mcp.backend('b1', '127.0.0.1', 11511) 14 local b2 = mcp.backend('b2', '127.0.0.1', 11512) 15 local b3 = mcp.backend('b3', '127.0.0.1', 11513) 16 17 local pools = { 18 test = mcp.pool({b1, b2, b3}) 19 } 20 return pools 21 elseif mode == "betable" then 22 local b1 = mcp.backend({ label = "b1", host = "127.0.0.1", port = 11511, 23 connecttimeout = 2, retrytimeout = 5, readtimeout = 1, 24 failurelimit = 0 }) 25 local b2 = mcp.backend({ label = "b2", host = "127.0.0.1", port = 11512, 26 connecttimeout = 2, retrytimeout = 5, readtimeout = 5 }) 27 local b3 = mcp.backend({ label = "b3", host = "127.0.0.1", port = 11513, 28 connecttimeout = 5, retrytimeout = 5, readtimeout = 5 }) 29 30 local pools = { 31 test = mcp.pool({b1, b2, b3}) 32 } 33 return pools 34 elseif mode == "noiothread" then 35 local b1 = mcp.backend('b1', '127.0.0.1', 11514) 36 local b2 = mcp.backend('b2', '127.0.0.1', 11515) 37 local b3 = mcp.backend('b3', '127.0.0.1', 11516) 38 39 local pools = { 40 test = mcp.pool({b1, b2, b3}, { iothread = false }) 41 } 42 return pools 43 elseif mode == "connections" then 44 local b1 = mcp.backend({ label = "b1c", host = "127.0.0.1", port = 11511, 45 connections = 3}) 46 local pools = { 47 test = mcp.pool({b1}) 48 } 49 return pools 50 elseif mode == "connectionsreload" then 51 local b1 = mcp.backend({ label = "b1c", host = "127.0.0.1", port = 11511, 52 connections = 1}) 53 local pools = { 54 test = mcp.pool({b1}) 55 } 56 return pools 57 elseif mode == "down" then 58 local down = mcp.backend({ label = "down", host = "127.0.0.1", port = 11517, 59 down = true }) 60 local pools = { 61 test = mcp.pool({down}) 62 } 63 return pools 64 elseif mode == "notdown" then 65 local down = mcp.backend({ label = "down", host = "127.0.0.1", port = 11517, 66 down = false }) 67 local pools = { 68 test = mcp.pool({down}) 69 } 70 return pools 71 end 72end 73 74-- At least to start we don't need to test every command, but we should do 75-- some tests against the two broad types of commands (gets vs sets with 76-- payloads) 77function mcp_config_routes(zones) 78 if mode == "none" then 79 mcp.attach(mcp.CMD_MG, function(r) return "SERVER_ERROR no mg route\r\n" end) 80 mcp.attach(mcp.CMD_MS, function(r) return "SERVER_ERROR no ms route\r\n" end) 81 else 82 local fg = mcp.funcgen_new() 83 local h = fg:new_handle(zones["test"]) 84 fg:ready({ 85 f = function(rctx) 86 return function(r) 87 return rctx:enqueue_and_wait(r, h) 88 end 89 end 90 }) 91 92 mcp.attach(mcp.CMD_MG, fg) 93 mcp.attach(mcp.CMD_MS, fg) 94 end 95end 96